1
The following changes since commit 9468484fe904ab4691de6d9c34616667f377ceac:
1
The following changes since commit 0e3aff9ec34059512d597eacfcf4d1b5d4570c50:
2
2
3
Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2024-01-09 10:32:23 +0000)
3
Merge tag 'pull-10.0-gdb-plugins-doc-updates-170125-1' of https://gitlab.com/stsquad/qemu into staging (2025-01-17 10:13:07 -0500)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240110
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20250119-1
8
8
9
for you to fetch changes up to 71b76da33a1558bcd59100188f5753737ef6fa21:
9
for you to fetch changes up to f04cac4f8f254931f2af9d059b2175769e576afa:
10
10
11
target/riscv: Ensure mideleg is set correctly on reset (2024-01-10 18:47:47 +1000)
11
hw/char/riscv_htif: Convert HTIF_DEBUG() to trace events (2025-01-19 09:44:35 +1000)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
RISC-V PR for 9.0
14
Second RISC-V PR for 10.0
15
15
16
* Make vector whole-register move (vmv) depend on vtype register
16
* Reduce the overhead for simple RISC-V vector unit-stride loads and stores
17
* Fix th.dcache.cval1 priviledge check
17
* Add V bit to GDB priv reg
18
* Don't allow write mstatus_vs without RVV
18
* Add 'sha' support
19
* Use hwaddr instead of target_ulong for RV32
19
* Add traces for exceptions in user mode
20
* Fix machine IDs QOM getters\
20
* Update Pointer Masking to Zjpm v1.0
21
* Fix KVM reg id sizes
21
* Add Smrnmi support
22
* ACPI: Enable AIA, PLIC and update RHCT
22
* Fix timebase-frequency when using KVM acceleration
23
* Fix the interrupts-extended property format of PLIC
23
* Add RISC-V Counter delegation ISA extension support
24
* Add support for Zacas extension
24
* Add support for Smdbltrp and Ssdbltrp extensions
25
* Add amocas.[w,d,q] instructions
25
* Introduce a translation tag for the IOMMU page table cache
26
* Document acpi parameter of virt machine
26
* Support Supm and Sspm as part of Zjpm v1.0
27
* RVA22 profiles support
27
* Convert htif debug prints to trace event
28
* Remove group setting of KVM AIA if the machine only has 1 socket
29
* Add RVV CSRs to KVM
30
* sifive_u: Update S-mode U-Boot image build instructions
31
* Upgrade OpenSBI from v1.3.1 to v1.4
32
* pmp: Ignore writes when RW=01 and MML=0
33
* Assert that the CSR numbers will be correct
34
* Don't adjust vscause for exceptions
35
* Ensure mideleg is set correctly on reset
36
28
37
----------------------------------------------------------------
29
----------------------------------------------------------------
38
Alistair Francis (3):
30
Alexey Baturo (8):
39
target/riscv: Assert that the CSR numbers will be correct
31
target/riscv: Remove obsolete pointer masking extension code.
40
target/riscv: Don't adjust vscause for exceptions
32
target/riscv: Add new CSR fields for S{sn, mn, m}pm extensions as part of Zjpm v1.0
41
target/riscv: Ensure mideleg is set correctly on reset
33
target/riscv: Add helper functions to calculate current number of masked bits for pointer masking
34
target/riscv: Add pointer masking tb flags
35
target/riscv: Update address modify functions to take into account pointer masking
36
target/riscv: Apply pointer masking for virtualized memory accesses
37
target/riscv: Enable updates for pointer masking variables and thus enable pointer masking extension
38
target/riscv: Support Supm and Sspm as part of Zjpm v1.0
42
39
43
Bin Meng (2):
40
Atish Patra (5):
44
docs/system/riscv: sifive_u: Update S-mode U-Boot image build instructions
41
target/riscv: Enable S*stateen bits for AIA
45
roms/opensbi: Upgrade from v1.3.1 to v1.4
42
target/riscv: Add properties for counter delegation ISA extensions
43
target/riscv: Invoke pmu init after feature enable
44
target/riscv: Add implied rule for counter delegation extensions
45
target/riscv: Add configuration for S[m|s]csrind, Smcdeleg/Ssccfg
46
46
47
Daniel Henrique Barboza (36):
47
Clément Léger (9):
48
target/riscv/cpu.c: fix machine IDs getters
48
target/riscv: Fix henvcfg potentially containing stale bits
49
target/riscv/kvm: change KVM_REG_RISCV_FP_F to u32
49
target/riscv: Add Ssdbltrp CSRs handling
50
target/riscv/kvm: change KVM_REG_RISCV_FP_D to u64
50
target/riscv: Implement Ssdbltrp sret, mret and mnret behavior
51
target/riscv/kvm: change timer regs size to u64
51
target/riscv: Implement Ssdbltrp exception handling
52
target/riscv/kvm: add RISCV_CONFIG_REG()
52
target/riscv: Add Ssdbltrp ISA extension enable switch
53
target/riscv/kvm: rename riscv_reg_id() to riscv_reg_id_ulong()
53
target/riscv: Add Smdbltrp CSRs handling
54
target/riscv: create TYPE_RISCV_VENDOR_CPU
54
target/riscv: Implement Smdbltrp sret, mret and mnret behavior
55
target/riscv/tcg: do not use "!generic" CPU checks
55
target/riscv: Implement Smdbltrp behavior
56
target/riscv/tcg: update priv_ver on user_set extensions
56
target/riscv: Add Smdbltrp ISA extension enable switch
57
target/riscv: add rv64i CPU
58
target/riscv: add zicbop extension flag
59
target/riscv/tcg: add 'zic64b' support
60
riscv-qmp-cmds.c: expose named features in cpu_model_expansion
61
target/riscv: add rva22u64 profile definition
62
target/riscv/kvm: add 'rva22u64' flag as unavailable
63
target/riscv/tcg: add user flag for profile support
64
target/riscv/tcg: add MISA user options hash
65
target/riscv/tcg: add riscv_cpu_write_misa_bit()
66
target/riscv/tcg: handle profile MISA bits
67
target/riscv/tcg: add hash table insert helpers
68
target/riscv/tcg: honor user choice for G MISA bits
69
target/riscv/tcg: validate profiles during finalize
70
riscv-qmp-cmds.c: add profile flags in cpu-model-expansion
71
target/riscv: add 'rva22u64' CPU
72
target/riscv: implement svade
73
target/riscv: add priv ver restriction to profiles
74
target/riscv/cpu.c: finalize satp_mode earlier
75
target/riscv/cpu.c: add riscv_cpu_is_32bit()
76
target/riscv: add satp_mode profile support
77
target/riscv: add 'parent' in profile description
78
target/riscv: add RVA22S64 profile
79
target/riscv: add rva22s64 cpu
80
linux-headers: Update to Linux v6.7-rc5
81
linux-headers: riscv: add ptrace.h
82
target/riscv/kvm: do PR_RISCV_V_SET_CONTROL during realize()
83
target/riscv/kvm: add RVV and Vector CSR regs
84
57
85
Heinrich Schuchardt (1):
58
Craig Blackmore (2):
86
docs/system/riscv: document acpi parameter of virt machine
59
target/riscv: rvv: fix typo in vext continuous ldst function names
60
target/riscv: rvv: speed up small unit-stride loads and stores
87
61
88
Ivan Klokov (2):
62
Daniel Henrique Barboza (9):
89
target/riscv/pmp: Use hwaddr instead of target_ulong for RV32
63
target/riscv: add shcounterenw
90
target/riscv: pmp: Ignore writes when RW=01 and MML=0
64
target/riscv: add shvstvala
65
target/riscv: add shtvala
66
target/riscv: add shvstvecd
67
target/riscv: add shvsatpa
68
target/riscv: add shgatpa
69
target/riscv/tcg: add sha
70
target/riscv: use RISCVException enum in exception helpers
71
target/riscv: add trace in riscv_raise_exception()
91
72
92
LIU Zhiwei (2):
73
Frank Chang (1):
93
target/riscv: Fix th.dcache.cval1 priviledge check
74
target/riscv: Add Zicfilp support for Smrnmi
94
target/riscv: Not allow write mstatus_vs without RVV
95
75
96
Max Chou (2):
76
Jason Chien (1):
97
target/riscv: Add vill check for whole vector register move instructions
77
hw/riscv/riscv-iommu.c: Introduce a translation tag for the page table cache
98
target/riscv: The whole vector register move instructions depend on vsew
99
78
100
Rob Bradford (1):
79
Kaiwen Xue (6):
101
disas/riscv: Add amocas.[w,d,q] instructions
80
target/riscv: Add properties for Indirect CSR Access extension
81
target/riscv: Decouple AIA processing from xiselect and xireg
82
target/riscv: Support generic CSR indirect access
83
target/riscv: Add counter delegation definitions
84
target/riscv: Add select value range check for counter delegation
85
target/riscv: Add counter delegation/configuration support
102
86
103
Sunil V L (13):
87
Philippe Mathieu-Daudé (3):
104
hw/arm/virt-acpi-build.c: Migrate fw_cfg creation to common location
88
target/riscv: Have kvm_riscv_get_timebase_frequency() take RISCVCPU cpu
105
hw/arm/virt-acpi-build.c: Migrate virtio creation to common location
89
hw/riscv/virt: Remove unnecessary use of &first_cpu
106
hw/i386/acpi-microvm.c: Use common function to add virtio in DSDT
90
hw/char/riscv_htif: Convert HTIF_DEBUG() to trace events
107
hw/riscv: virt: Make few IMSIC macros and functions public
108
hw/riscv/virt-acpi-build.c: Add AIA support in RINTC
109
hw/riscv/virt-acpi-build.c: Add IMSIC in the MADT
110
hw/riscv/virt-acpi-build.c: Add APLIC in the MADT
111
hw/riscv/virt-acpi-build.c: Add CMO information in RHCT
112
hw/riscv/virt-acpi-build.c: Add MMU node in RHCT
113
hw/pci-host/gpex: Define properties for MMIO ranges
114
hw/riscv/virt: Update GPEX MMIO related properties
115
hw/riscv/virt-acpi-build.c: Add IO controllers and devices
116
hw/riscv/virt-acpi-build.c: Add PLIC in MADT
117
91
118
Weiwei Li (1):
92
Tommy Wu (5):
119
target/riscv: Add support for Zacas extension
93
target/riscv: Add 'ext_smrnmi' in the RISCVCPUConfig
94
target/riscv: Add Smrnmi CSRs
95
target/riscv: Handle Smrnmi interrupt and exception
96
target/riscv: Add Smrnmi mnret instruction
97
target/riscv: Add Smrnmi cpu extension
120
98
121
Yong-Xuan Wang (2):
99
Yanfeng Liu (1):
122
hw/riscv/virt.c: fix the interrupts-extended property format of PLIC
100
riscv/gdbstub: add V bit to priv reg
123
target/riscv/kvm.c: remove group setting of KVM AIA if the machine only has 1 socket
124
101
125
docs/system/riscv/sifive_u.rst | 33 +-
102
include/hw/riscv/riscv_hart.h | 4 +
126
docs/system/riscv/virt.rst | 5 +
103
target/riscv/cpu.h | 65 +-
127
include/hw/nvram/fw_cfg_acpi.h | 15 +
104
target/riscv/cpu_bits.h | 157 ++-
128
include/hw/pci-host/gpex.h | 28 +-
105
target/riscv/cpu_cfg.h | 13 +
129
include/hw/riscv/virt.h | 26 ++
106
target/riscv/helper.h | 1 +
130
include/hw/virtio/virtio-acpi.h | 16 +
107
target/riscv/internals.h | 54 +
131
include/standard-headers/drm/drm_fourcc.h | 2 +
108
target/riscv/kvm/kvm_riscv.h | 4 +-
132
include/standard-headers/linux/pci_regs.h | 24 +-
109
target/riscv/pmp.h | 1 +
133
include/standard-headers/linux/vhost_types.h | 7 +
110
target/riscv/insn32.decode | 3 +
134
include/standard-headers/linux/virtio_config.h | 5 +
111
hw/char/riscv_htif.c | 15 +-
135
include/standard-headers/linux/virtio_pci.h | 11 +
112
hw/riscv/riscv-iommu.c | 205 +++-
136
linux-headers/asm-arm64/kvm.h | 32 ++
113
hw/riscv/riscv_hart.c | 41 +
137
linux-headers/asm-generic/unistd.h | 14 +-
114
hw/riscv/virt.c | 2 +-
138
linux-headers/asm-loongarch/bitsperlong.h | 1 +
115
target/riscv/cpu.c | 97 +-
139
linux-headers/asm-loongarch/kvm.h | 108 ++++++
116
target/riscv/cpu_helper.c | 311 +++++-
140
linux-headers/asm-loongarch/mman.h | 1 +
117
target/riscv/csr.c | 1257 +++++++++++++++++-------
141
linux-headers/asm-loongarch/unistd.h | 5 +
118
target/riscv/gdbstub.c | 23 +-
142
linux-headers/asm-mips/unistd_n32.h | 4 +
119
target/riscv/kvm/kvm-cpu.c | 4 +-
143
linux-headers/asm-mips/unistd_n64.h | 4 +
120
target/riscv/machine.c | 18 +-
144
linux-headers/asm-mips/unistd_o32.h | 4 +
121
target/riscv/op_helper.c | 126 ++-
145
linux-headers/asm-powerpc/unistd_32.h | 4 +
122
target/riscv/pmp.c | 14 +-
146
linux-headers/asm-powerpc/unistd_64.h | 4 +
123
target/riscv/tcg/tcg-cpu.c | 60 +-
147
linux-headers/asm-riscv/kvm.h | 12 +
124
target/riscv/translate.c | 49 +-
148
linux-headers/asm-riscv/ptrace.h | 132 +++++++
125
target/riscv/vector_helper.c | 31 +-
149
linux-headers/asm-s390/unistd_32.h | 4 +
126
target/riscv/insn_trans/trans_privileged.c.inc | 20 +
150
linux-headers/asm-s390/unistd_64.h | 4 +
127
hw/char/trace-events | 4 +
151
linux-headers/asm-x86/unistd_32.h | 4 +
128
target/riscv/trace-events | 3 +
152
linux-headers/asm-x86/unistd_64.h | 3 +
129
tests/data/acpi/riscv64/virt/RHCT | Bin 332 -> 390 bytes
153
linux-headers/asm-x86/unistd_x32.h | 3 +
130
28 files changed, 1862 insertions(+), 720 deletions(-)
154
linux-headers/linux/iommufd.h | 180 +++++++++-
131
155
linux-headers/linux/kvm.h | 11 +
156
linux-headers/linux/psp-sev.h | 1 +
157
linux-headers/linux/stddef.h | 9 +-
158
linux-headers/linux/userfaultfd.h | 9 +-
159
linux-headers/linux/vfio.h | 47 ++-
160
linux-headers/linux/vhost.h | 8 +
161
target/riscv/cpu-qom.h | 5 +
162
target/riscv/cpu.h | 18 +
163
target/riscv/cpu_cfg.h | 5 +
164
target/riscv/pmp.h | 8 +-
165
target/riscv/insn32.decode | 6 +
166
disas/riscv.c | 9 +
167
hw/arm/virt-acpi-build.c | 51 +--
168
hw/i386/acpi-microvm.c | 15 +-
169
hw/nvram/fw_cfg-acpi.c | 23 ++
170
hw/pci-host/gpex-acpi.c | 13 +
171
hw/pci-host/gpex.c | 12 +
172
hw/riscv/virt-acpi-build.c | 323 ++++++++++++++++--
173
hw/riscv/virt.c | 124 +++----
174
hw/virtio/virtio-acpi.c | 33 ++
175
target/riscv/cpu.c | 223 ++++++++++--
176
target/riscv/cpu_helper.c | 4 +-
177
target/riscv/csr.c | 10 +-
178
target/riscv/kvm/kvm-cpu.c | 250 ++++++++++----
179
target/riscv/pmp.c | 28 +-
180
target/riscv/riscv-qmp-cmds.c | 44 ++-
181
target/riscv/tcg/tcg-cpu.c | 455 ++++++++++++++++++++++---
182
target/riscv/translate.c | 1 +
183
target/riscv/insn_trans/trans_rvv.c.inc | 8 +-
184
target/riscv/insn_trans/trans_rvzacas.c.inc | 150 ++++++++
185
target/riscv/insn_trans/trans_xthead.c.inc | 2 +-
186
hw/nvram/meson.build | 1 +
187
hw/riscv/Kconfig | 1 +
188
hw/virtio/meson.build | 1 +
189
pc-bios/opensbi-riscv32-generic-fw_dynamic.bin | Bin 135376 -> 267416 bytes
190
pc-bios/opensbi-riscv64-generic-fw_dynamic.bin | Bin 138368 -> 270808 bytes
191
roms/opensbi | 2 +-
192
scripts/update-linux-headers.sh | 3 +
193
68 files changed, 2248 insertions(+), 360 deletions(-)
194
create mode 100644 include/hw/nvram/fw_cfg_acpi.h
195
create mode 100644 include/hw/virtio/virtio-acpi.h
196
create mode 100644 linux-headers/asm-loongarch/bitsperlong.h
197
create mode 100644 linux-headers/asm-loongarch/kvm.h
198
create mode 100644 linux-headers/asm-loongarch/mman.h
199
create mode 100644 linux-headers/asm-loongarch/unistd.h
200
create mode 100644 linux-headers/asm-riscv/ptrace.h
201
create mode 100644 hw/nvram/fw_cfg-acpi.c
202
create mode 100644 hw/virtio/virtio-acpi.c
203
create mode 100644 target/riscv/insn_trans/trans_rvzacas.c.inc
diff view generated by jsdifflib
Deleted patch
1
From: Max Chou <max.chou@sifive.com>
2
1
3
The ratified version of RISC-V V spec section 16.6 says that
4
`The instructions operate as if EEW=SEW`.
5
6
So the whole vector register move instructions depend on the vtype
7
register that means the whole vector register move instructions should
8
raise an illegal-instruction exception when vtype.vill=1.
9
10
Signed-off-by: Max Chou <max.chou@sifive.com>
11
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
12
Message-ID: <20231129170400.21251-2-max.chou@sifive.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
15
target/riscv/insn_trans/trans_rvv.c.inc | 5 +++--
16
1 file changed, 3 insertions(+), 2 deletions(-)
17
18
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
19
index XXXXXXX..XXXXXXX 100644
20
--- a/target/riscv/insn_trans/trans_rvv.c.inc
21
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
22
@@ -XXX,XX +XXX,XX @@ static bool trans_vcompress_vm(DisasContext *s, arg_r *a)
23
}
24
25
/*
26
- * Whole Vector Register Move Instructions ignore vtype and vl setting.
27
- * Thus, we don't need to check vill bit. (Section 16.6)
28
+ * Whole Vector Register Move Instructions depend on vtype register(vsew).
29
+ * Thus, we need to check vill bit. (Section 16.6)
30
*/
31
#define GEN_VMV_WHOLE_TRANS(NAME, LEN) \
32
static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \
33
{ \
34
if (require_rvv(s) && \
35
+ vext_check_isa_ill(s) && \
36
QEMU_IS_ALIGNED(a->rd, LEN) && \
37
QEMU_IS_ALIGNED(a->rs2, LEN)) { \
38
uint32_t maxsz = (s->cfg_ptr->vlen >> 3) * LEN; \
39
--
40
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Max Chou <max.chou@sifive.com>
2
1
3
The RISC-V v spec 16.6 section says that the whole vector register move
4
instructions operate as if EEW=SEW. So it should depends on the vsew
5
field of vtype register.
6
7
Signed-off-by: Max Chou <max.chou@sifive.com>
8
Acked-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-ID: <20231129170400.21251-3-max.chou@sifive.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/insn_trans/trans_rvv.c.inc | 3 +--
13
1 file changed, 1 insertion(+), 2 deletions(-)
14
15
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/insn_trans/trans_rvv.c.inc
18
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
19
@@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \
20
QEMU_IS_ALIGNED(a->rs2, LEN)) { \
21
uint32_t maxsz = (s->cfg_ptr->vlen >> 3) * LEN; \
22
if (s->vstart_eq_zero) { \
23
- /* EEW = 8 */ \
24
- tcg_gen_gvec_mov(MO_8, vreg_ofs(s, a->rd), \
25
+ tcg_gen_gvec_mov(s->sew, vreg_ofs(s, a->rd), \
26
vreg_ofs(s, a->rs2), maxsz, maxsz); \
27
mark_vs_dirty(s); \
28
} else { \
29
--
30
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
2
1
3
According to the specification, the th.dcache.cvall1 can be executed
4
under all priviledges.
5
The specification about xtheadcmo located in,
6
https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadcmo/dcache_cval1.adoc
7
8
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Christoph Muellner <christoph.muellner@vrull.eu>
11
Message-ID: <20231208094315.177-1-zhiwei_liu@linux.alibaba.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/insn_trans/trans_xthead.c.inc | 2 +-
15
1 file changed, 1 insertion(+), 1 deletion(-)
16
17
diff --git a/target/riscv/insn_trans/trans_xthead.c.inc b/target/riscv/insn_trans/trans_xthead.c.inc
18
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/insn_trans/trans_xthead.c.inc
20
+++ b/target/riscv/insn_trans/trans_xthead.c.inc
21
@@ -XXX,XX +XXX,XX @@ NOP_PRIVCHECK(th_dcache_csw, REQUIRE_XTHEADCMO, REQUIRE_PRIV_MS)
22
NOP_PRIVCHECK(th_dcache_cisw, REQUIRE_XTHEADCMO, REQUIRE_PRIV_MS)
23
NOP_PRIVCHECK(th_dcache_isw, REQUIRE_XTHEADCMO, REQUIRE_PRIV_MS)
24
NOP_PRIVCHECK(th_dcache_cpal1, REQUIRE_XTHEADCMO, REQUIRE_PRIV_MS)
25
-NOP_PRIVCHECK(th_dcache_cval1, REQUIRE_XTHEADCMO, REQUIRE_PRIV_MS)
26
+NOP_PRIVCHECK(th_dcache_cval1, REQUIRE_XTHEADCMO, REQUIRE_PRIV_MSU)
27
28
NOP_PRIVCHECK(th_icache_iall, REQUIRE_XTHEADCMO, REQUIRE_PRIV_MS)
29
NOP_PRIVCHECK(th_icache_ialls, REQUIRE_XTHEADCMO, REQUIRE_PRIV_MS)
30
--
31
2.43.0
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Craig Blackmore <craig.blackmore@embecosm.com>
2
2
3
Expose all profile flags for all CPUs when executing
3
Replace `continus` with `continuous`.
4
query-cpu-model-expansion. This will allow callers to quickly determine
5
if a certain profile is implemented by a given CPU. This includes vendor
6
CPUs - the fact that they don't have profile user flags doesn't mean
7
that they don't implement the profile.
8
4
9
After this change it's possible to quickly determine if our stock CPUs
5
Signed-off-by: Craig Blackmore <craig.blackmore@embecosm.com>
10
implement the existing rva22u64 profile. Here's a few examples:
6
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
7
Reviewed-by: Max Chou <max.chou@sifive.com>
12
$ ./build/qemu-system-riscv64 -S -M virt -display none
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
-qmp tcp:localhost:1234,server,wait=off
9
Message-ID: <20241218142353.1027938-2-craig.blackmore@embecosm.com>
14
15
$ ./scripts/qmp/qmp-shell localhost:1234
16
Welcome to the QMP low-level shell!
17
Connected to QEMU 8.1.50
18
19
- As expected, the 'max' CPU implements the rva22u64 profile.
20
21
(QEMU) query-cpu-model-expansion type=full model={"name":"max"}
22
{"return": {"model":
23
{"name": "rv64", "props": {... "rva22u64": true, ...}}}}
24
25
- rv64 is missing "zba", "zbb", "zbs", "zkt" and "zfhmin":
26
27
query-cpu-model-expansion type=full model={"name":"rv64"}
28
{"return": {"model":
29
{"name": "rv64", "props": {... "rva22u64": false, ...}}}}
30
31
query-cpu-model-expansion type=full model={"name":"rv64",
32
"props":{"zba":true,"zbb":true,"zbs":true,"zkt":true,"zfhmin":true}}
33
{"return": {"model":
34
{"name": "rv64", "props": {... "rva22u64": true, ...}}}}
35
36
We have no vendor CPUs that supports rva22u64 (veyron-v1 is the closest
37
- it is missing just 'zkt').
38
39
In short, aside from the 'max' CPU, we have no CPUs that supports
40
rva22u64 by default.
41
42
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
43
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
44
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
45
Message-ID: <20231218125334.37184-18-dbarboza@ventanamicro.com>
46
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
47
---
11
---
48
target/riscv/riscv-qmp-cmds.c | 14 ++++++++++++++
12
target/riscv/vector_helper.c | 10 +++++-----
49
1 file changed, 14 insertions(+)
13
1 file changed, 5 insertions(+), 5 deletions(-)
50
14
51
diff --git a/target/riscv/riscv-qmp-cmds.c b/target/riscv/riscv-qmp-cmds.c
15
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
52
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/riscv-qmp-cmds.c
17
--- a/target/riscv/vector_helper.c
54
+++ b/target/riscv/riscv-qmp-cmds.c
18
+++ b/target/riscv/vector_helper.c
55
@@ -XXX,XX +XXX,XX @@ static void riscv_obj_add_named_feats_qdict(Object *obj, QDict *qdict_out)
19
@@ -XXX,XX +XXX,XX @@ GEN_VEXT_ST_ELEM(ste_w, uint32_t, H4, stl)
56
}
20
GEN_VEXT_ST_ELEM(ste_d, uint64_t, H8, stq)
21
22
static inline QEMU_ALWAYS_INLINE void
23
-vext_continus_ldst_tlb(CPURISCVState *env, vext_ldst_elem_fn_tlb *ldst_tlb,
24
+vext_continuous_ldst_tlb(CPURISCVState *env, vext_ldst_elem_fn_tlb *ldst_tlb,
25
void *vd, uint32_t evl, target_ulong addr,
26
uint32_t reg_start, uintptr_t ra, uint32_t esz,
27
bool is_load)
28
@@ -XXX,XX +XXX,XX @@ vext_continus_ldst_tlb(CPURISCVState *env, vext_ldst_elem_fn_tlb *ldst_tlb,
57
}
29
}
58
30
59
+static void riscv_obj_add_profiles_qdict(Object *obj, QDict *qdict_out)
31
static inline QEMU_ALWAYS_INLINE void
60
+{
32
-vext_continus_ldst_host(CPURISCVState *env, vext_ldst_elem_fn_host *ldst_host,
61
+ RISCVCPUProfile *profile;
33
+vext_continuous_ldst_host(CPURISCVState *env, vext_ldst_elem_fn_host *ldst_host,
62
+ QObject *value;
34
void *vd, uint32_t evl, uint32_t reg_start, void *host,
63
+
35
uint32_t esz, bool is_load)
64
+ for (int i = 0; riscv_profiles[i] != NULL; i++) {
36
{
65
+ profile = riscv_profiles[i];
37
@@ -XXX,XX +XXX,XX @@ vext_page_ldst_us(CPURISCVState *env, void *vd, target_ulong addr,
66
+ value = QOBJECT(qbool_from_bool(profile->enabled));
38
67
+
39
if (flags == 0) {
68
+ qdict_put_obj(qdict_out, profile->name, value);
40
if (nf == 1) {
69
+ }
41
- vext_continus_ldst_host(env, ldst_host, vd, evl, env->vstart, host,
70
+}
42
- esz, is_load);
71
+
43
+ vext_continuous_ldst_host(env, ldst_host, vd, evl, env->vstart,
72
static void riscv_cpuobj_validate_qdict_in(Object *obj, QObject *props,
44
+ host, esz, is_load);
73
const QDict *qdict_in,
45
} else {
74
Error **errp)
46
for (i = env->vstart; i < evl; ++i) {
75
@@ -XXX,XX +XXX,XX @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
47
k = 0;
76
riscv_obj_add_multiext_props(obj, qdict_out, riscv_cpu_experimental_exts);
48
@@ -XXX,XX +XXX,XX @@ vext_page_ldst_us(CPURISCVState *env, void *vd, target_ulong addr,
77
riscv_obj_add_multiext_props(obj, qdict_out, riscv_cpu_vendor_exts);
49
env->vstart += elems;
78
riscv_obj_add_named_feats_qdict(obj, qdict_out);
50
} else {
79
+ riscv_obj_add_profiles_qdict(obj, qdict_out);
51
if (nf == 1) {
80
52
- vext_continus_ldst_tlb(env, ldst_tlb, vd, evl, addr, env->vstart,
81
/* Add our CPU boolean options too */
53
+ vext_continuous_ldst_tlb(env, ldst_tlb, vd, evl, addr, env->vstart,
82
riscv_obj_add_qdict_prop(obj, qdict_out, "mmu");
54
ra, esz, is_load);
55
} else {
56
/* load bytes from guest memory */
83
--
57
--
84
2.43.0
58
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Craig Blackmore <craig.blackmore@embecosm.com>
2
2
3
Our current logic in get/setters of MISA and multi-letter extensions
3
Calling `vext_continuous_ldst_tlb` for load/stores up to 6 bytes
4
works because we have only 2 CPU types, generic and vendor, and by using
4
significantly improves performance.
5
"!generic" we're implying that we're talking about vendor CPUs. When adding
6
a third CPU type this logic will break so let's handle it beforehand.
7
5
8
In set_misa_ext_cfg() and set_multi_ext_cfg(), check for "vendor" cpu instead
6
Co-authored-by: Helene CHELIN <helene.chelin@embecosm.com>
9
of "not generic". The "generic CPU" checks remaining are from
7
Co-authored-by: Paolo Savini <paolo.savini@embecosm.com>
10
riscv_cpu_add_misa_properties() and cpu_add_multi_ext_prop() before
8
Co-authored-by: Craig Blackmore <craig.blackmore@embecosm.com>
11
applying default values for the extensions.
12
9
13
This leaves us with:
10
Signed-off-by: Helene CHELIN <helene.chelin@embecosm.com>
14
11
Signed-off-by: Paolo Savini <paolo.savini@embecosm.com>
15
- vendor CPUs will not allow extension enablement, all other CPUs will;
12
Signed-off-by: Craig Blackmore <craig.blackmore@embecosm.com>
16
13
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
17
- generic CPUs will inherit default values for extensions, all others
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
18
won't.
15
Message-ID: <20241218142353.1027938-3-craig.blackmore@embecosm.com>
19
20
And now we can add a new, third CPU type, that will allow extensions to
21
be enabled and will not inherit defaults, without changing the existing
22
logic.
23
24
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
25
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
26
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
27
Message-ID: <20231218125334.37184-3-dbarboza@ventanamicro.com>
28
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
---
17
---
30
target/riscv/tcg/tcg-cpu.c | 13 +++++++++----
18
target/riscv/vector_helper.c | 16 ++++++++++++++++
31
1 file changed, 9 insertions(+), 4 deletions(-)
19
1 file changed, 16 insertions(+)
32
20
33
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
21
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
34
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
35
--- a/target/riscv/tcg/tcg-cpu.c
23
--- a/target/riscv/vector_helper.c
36
+++ b/target/riscv/tcg/tcg-cpu.c
24
+++ b/target/riscv/vector_helper.c
37
@@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_is_generic(Object *cpu_obj)
25
@@ -XXX,XX +XXX,XX @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,
38
return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL;
39
}
40
41
+static bool riscv_cpu_is_vendor(Object *cpu_obj)
42
+{
43
+ return object_dynamic_cast(cpu_obj, TYPE_RISCV_VENDOR_CPU) != NULL;
44
+}
45
+
46
/*
47
* We'll get here via the following path:
48
*
49
@@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
50
target_ulong misa_bit = misa_ext_cfg->misa_bit;
51
RISCVCPU *cpu = RISCV_CPU(obj);
52
CPURISCVState *env = &cpu->env;
53
- bool generic_cpu = riscv_cpu_is_generic(obj);
54
+ bool vendor_cpu = riscv_cpu_is_vendor(obj);
55
bool prev_val, value;
56
57
if (!visit_type_bool(v, name, &value, errp)) {
58
@@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
59
}
60
61
if (value) {
62
- if (!generic_cpu) {
63
+ if (vendor_cpu) {
64
g_autofree char *cpuname = riscv_cpu_get_name(cpu);
65
error_setg(errp, "'%s' CPU does not allow enabling extensions",
66
cpuname);
67
@@ -XXX,XX +XXX,XX @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
68
{
69
const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque;
70
RISCVCPU *cpu = RISCV_CPU(obj);
71
- bool generic_cpu = riscv_cpu_is_generic(obj);
72
+ bool vendor_cpu = riscv_cpu_is_vendor(obj);
73
bool prev_val, value;
74
75
if (!visit_type_bool(v, name, &value, errp)) {
76
@@ -XXX,XX +XXX,XX @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
77
return;
26
return;
78
}
27
}
79
28
80
- if (value && !generic_cpu) {
29
+#if defined(CONFIG_USER_ONLY)
81
+ if (value && vendor_cpu) {
30
+ /*
82
g_autofree char *cpuname = riscv_cpu_get_name(cpu);
31
+ * For data sizes <= 6 bytes we get better performance by simply calling
83
error_setg(errp, "'%s' CPU does not allow enabling extensions",
32
+ * vext_continuous_ldst_tlb
84
cpuname);
33
+ */
34
+ if (nf == 1 && (evl << log2_esz) <= 6) {
35
+ addr = base + (env->vstart << log2_esz);
36
+ vext_continuous_ldst_tlb(env, ldst_tlb, vd, evl, addr, env->vstart, ra,
37
+ esz, is_load);
38
+
39
+ env->vstart = 0;
40
+ vext_set_tail_elems_1s(evl, vd, desc, nf, esz, max_elems);
41
+ return;
42
+ }
43
+#endif
44
+
45
/* Calculate the page range of first page */
46
addr = base + ((env->vstart * nf) << log2_esz);
47
page_split = -(addr | TARGET_PAGE_MASK);
85
--
48
--
86
2.43.0
49
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Yanfeng Liu <yfliu2008@qq.com>
2
2
3
The profile support is handling multi-letter extensions only. Let's add
3
This adds virtualization mode (V bit) as bit(2) of register `priv`
4
support for MISA bits as well.
4
per RiscV debug spec v1.0.0-rc4. Checked with gdb-multiarch v12.1.
5
5
6
We'll go through every known MISA bit. If the profile doesn't declare
6
Note that GDB may display `INVALID` tag for `priv` reg when V bit
7
the bit as mandatory, ignore it. Otherwise, set the bit in env->misa_ext
7
is set, this doesn't affect actual access to the bit though.
8
and env->misa_ext_mask.
9
8
10
Now that we're setting profile MISA bits, one can use the rv64i CPU to boot
9
Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
11
Linux using the following options:
12
13
-cpu rv64i,rva22u64=true,rv39=true,s=true,zifencei=true
14
15
In the near future, when rva22s64 (where, 's', 'zifencei' and sv39 are
16
mandatory), is implemented, rv64i will be able to boot Linux loading
17
rva22s64 and no additional flags.
18
19
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
20
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
22
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
23
Message-ID: <20231218125334.37184-14-dbarboza@ventanamicro.com>
11
Message-ID: <tencent_1993B55C24DE7979BF34B200F78287002907@qq.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
13
---
26
target/riscv/tcg/tcg-cpu.c | 21 +++++++++++++++++++++
14
target/riscv/gdbstub.c | 23 +++++++++++++++++++----
27
1 file changed, 21 insertions(+)
15
1 file changed, 19 insertions(+), 4 deletions(-)
28
16
29
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
17
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
30
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/tcg/tcg-cpu.c
19
--- a/target/riscv/gdbstub.c
32
+++ b/target/riscv/tcg/tcg-cpu.c
20
+++ b/target/riscv/gdbstub.c
33
@@ -XXX,XX +XXX,XX @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
21
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_virtual(CPUState *cs, GByteArray *buf, int n)
34
profile->user_set = true;
22
RISCVCPU *cpu = RISCV_CPU(cs);
35
profile->enabled = value;
23
CPURISCVState *env = &cpu->env;
36
24
37
+ for (i = 0; misa_bits[i] != 0; i++) {
25
- return gdb_get_regl(buf, env->priv);
38
+ uint32_t bit = misa_bits[i];
26
+ /* Per RiscV debug spec v1.0.0 rc4 */
27
+ target_ulong vbit = (env->virt_enabled) ? BIT(2) : 0;
39
+
28
+
40
+ if (!(profile->misa_ext & bit)) {
29
+ return gdb_get_regl(buf, env->priv | vbit);
41
+ continue;
30
#endif
31
}
32
return 0;
33
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_virtual(CPUState *cs, uint8_t *mem_buf, int n)
34
RISCVCPU *cpu = RISCV_CPU(cs);
35
CPURISCVState *env = &cpu->env;
36
37
- env->priv = ldtul_p(mem_buf) & 0x3;
38
- if (env->priv == PRV_RESERVED) {
39
- env->priv = PRV_S;
40
+ target_ulong new_priv = ldtul_p(mem_buf) & 0x3;
41
+ bool new_virt = 0;
42
+
43
+ if (new_priv == PRV_RESERVED) {
44
+ new_priv = PRV_S;
42
+ }
45
+ }
43
+
46
+
44
+ if (bit == RVI && !profile->enabled) {
47
+ if (new_priv != PRV_M) {
45
+ /*
48
+ new_virt = (ldtul_p(mem_buf) & BIT(2)) >> 2;
46
+ * Disabling profiles will not disable the base
49
}
47
+ * ISA RV64I.
50
+
48
+ */
51
+ if (riscv_has_ext(env, RVH) && new_virt != env->virt_enabled) {
49
+ continue;
52
+ riscv_cpu_swap_hypervisor_regs(env);
50
+ }
53
+ }
51
+
54
+
52
+ g_hash_table_insert(misa_ext_user_opts,
55
+ riscv_cpu_set_mode(env, new_priv, new_virt);
53
+ GUINT_TO_POINTER(bit),
56
#endif
54
+ (gpointer)value);
57
return sizeof(target_ulong);
55
+ riscv_cpu_write_misa_bit(cpu, bit, profile->enabled);
58
}
56
+ }
57
+
58
for (i = 0; profile->ext_offsets[i] != RISCV_PROFILE_EXT_LIST_END; i++) {
59
ext_offset = profile->ext_offsets[i];
60
61
--
59
--
62
2.43.0
60
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
We want to add a new CPU type for bare CPUs that will inherit specific
3
shcounterenw is defined in RVA22 as:
4
traits of the 2 existing types:
5
4
6
- it will allow for extensions to be enabled/disabled, like generic
5
"For any hpmcounter that is not read-only zero, the corresponding bit in
7
CPUs;
6
hcounteren must be writable."
8
7
9
- it will NOT inherit defaults, like vendor CPUs.
8
This is always true in TCG so let's claim support for it.
10
11
We can make this conditions met by adding an explicit type for the
12
existing vendor CPUs and change the existing logic to not imply that
13
"not generic" means vendor CPUs.
14
15
Let's add the "vendor" CPU type first.
16
9
17
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
18
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
19
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Message-ID: <20231218125334.37184-2-dbarboza@ventanamicro.com>
12
Message-ID: <20241218114026.1652352-4-dbarboza@ventanamicro.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
---
14
---
23
target/riscv/cpu-qom.h | 1 +
15
target/riscv/cpu.c | 1 +
24
target/riscv/cpu.c | 30 +++++++++++++++++++++---------
16
tests/data/acpi/riscv64/virt/RHCT | Bin 332 -> 346 bytes
25
2 files changed, 22 insertions(+), 9 deletions(-)
17
2 files changed, 1 insertion(+)
26
18
27
diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h
28
index XXXXXXX..XXXXXXX 100644
29
--- a/target/riscv/cpu-qom.h
30
+++ b/target/riscv/cpu-qom.h
31
@@ -XXX,XX +XXX,XX @@
32
33
#define TYPE_RISCV_CPU "riscv-cpu"
34
#define TYPE_RISCV_DYNAMIC_CPU "riscv-dynamic-cpu"
35
+#define TYPE_RISCV_VENDOR_CPU "riscv-vendor-cpu"
36
37
#define RISCV_CPU_TYPE_SUFFIX "-" TYPE_RISCV_CPU
38
#define RISCV_CPU_TYPE_NAME(name) (name RISCV_CPU_TYPE_SUFFIX)
39
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
19
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
40
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/cpu.c
21
--- a/target/riscv/cpu.c
42
+++ b/target/riscv/cpu.c
22
+++ b/target/riscv/cpu.c
43
@@ -XXX,XX +XXX,XX @@ char *riscv_isa_string(RISCVCPU *cpu)
23
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
44
.instance_init = initfn \
24
ISA_EXT_DATA_ENTRY(zvkt, PRIV_VERSION_1_12_0, ext_zvkt),
45
}
25
ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx),
46
26
ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin),
47
+#define DEFINE_VENDOR_CPU(type_name, initfn) \
27
+ ISA_EXT_DATA_ENTRY(shcounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
48
+ { \
28
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
49
+ .name = type_name, \
29
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
50
+ .parent = TYPE_RISCV_VENDOR_CPU, \
30
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
51
+ .instance_init = initfn \
31
diff --git a/tests/data/acpi/riscv64/virt/RHCT b/tests/data/acpi/riscv64/virt/RHCT
52
+ }
32
index XXXXXXX..XXXXXXX 100644
53
+
33
Binary files a/tests/data/acpi/riscv64/virt/RHCT and b/tests/data/acpi/riscv64/virt/RHCT differ
54
static const TypeInfo riscv_cpu_type_infos[] = {
55
{
56
.name = TYPE_RISCV_CPU,
57
@@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = {
58
.parent = TYPE_RISCV_CPU,
59
.abstract = true,
60
},
61
+ {
62
+ .name = TYPE_RISCV_VENDOR_CPU,
63
+ .parent = TYPE_RISCV_CPU,
64
+ .abstract = true,
65
+ },
66
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init),
67
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_MAX, riscv_max_cpu_init),
68
#if defined(TARGET_RISCV32)
69
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE32, rv32_base_cpu_init),
70
- DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init),
71
- DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rv32_sifive_e_cpu_init),
72
- DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34, rv32_imafcu_nommu_cpu_init),
73
- DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32_sifive_u_cpu_init),
74
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init),
75
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rv32_sifive_e_cpu_init),
76
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_SIFIVE_E34, rv32_imafcu_nommu_cpu_init),
77
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32_sifive_u_cpu_init),
78
#elif defined(TARGET_RISCV64)
79
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE64, rv64_base_cpu_init),
80
- DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64_sifive_e_cpu_init),
81
- DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init),
82
- DEFINE_CPU(TYPE_RISCV_CPU_SHAKTI_C, rv64_sifive_u_cpu_init),
83
- DEFINE_CPU(TYPE_RISCV_CPU_THEAD_C906, rv64_thead_c906_cpu_init),
84
- DEFINE_CPU(TYPE_RISCV_CPU_VEYRON_V1, rv64_veyron_v1_cpu_init),
85
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64_sifive_e_cpu_init),
86
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init),
87
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_SHAKTI_C, rv64_sifive_u_cpu_init),
88
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_THEAD_C906, rv64_thead_c906_cpu_init),
89
+ DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_VEYRON_V1, rv64_veyron_v1_cpu_init),
90
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE128, rv128_base_cpu_init),
91
#endif
92
};
93
--
34
--
94
2.43.0
35
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Add a new profile CPU 'rva22s64' to work as an alias of
3
shvstvala is defined in RVA22 as:
4
4
5
-cpu rv64i,rva22s64
5
"vstval must be written in all cases described above for stval."
6
6
7
Like the existing rva22u64 CPU already does with the RVA22U64 profile.
7
By "cases describe above" the doc refer to the description of sstvala:
8
9
"stval must be written with the faulting virtual address for load,
10
store, and instruction page-fault, access-fault, and misaligned
11
exceptions, and for breakpoint exceptions other than those caused by
12
execution of the EBREAK or C.EBREAK instructions. For
13
virtual-instruction and illegal-instruction exceptions, stval must be
14
written with the faulting instruction."
15
16
We already have sstvala, and our vstval follows the same rules as stval,
17
so we can claim to support shvstvala too.
8
18
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
19
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Message-ID: <20231218125334.37184-27-dbarboza@ventanamicro.com>
21
Message-ID: <20241218114026.1652352-5-dbarboza@ventanamicro.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
23
---
15
target/riscv/cpu-qom.h | 1 +
24
target/riscv/cpu.c | 1 +
16
target/riscv/cpu.c | 8 ++++++++
25
tests/data/acpi/riscv64/virt/RHCT | Bin 346 -> 356 bytes
17
2 files changed, 9 insertions(+)
26
2 files changed, 1 insertion(+)
18
27
19
diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu-qom.h
22
+++ b/target/riscv/cpu-qom.h
23
@@ -XXX,XX +XXX,XX @@
24
#define TYPE_RISCV_CPU_BASE128 RISCV_CPU_TYPE_NAME("x-rv128")
25
#define TYPE_RISCV_CPU_RV64I RISCV_CPU_TYPE_NAME("rv64i")
26
#define TYPE_RISCV_CPU_RVA22U64 RISCV_CPU_TYPE_NAME("rva22u64")
27
+#define TYPE_RISCV_CPU_RVA22S64 RISCV_CPU_TYPE_NAME("rva22s64")
28
#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")
29
#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")
30
#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
28
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
30
--- a/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
31
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ static void rva22u64_profile_cpu_init(Object *obj)
32
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
36
33
ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx),
37
RVA22U64.enabled = true;
34
ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin),
38
}
35
ISA_EXT_DATA_ENTRY(shcounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
39
+
36
+ ISA_EXT_DATA_ENTRY(shvstvala, PRIV_VERSION_1_12_0, has_priv_1_12),
40
+static void rva22s64_profile_cpu_init(Object *obj)
37
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
41
+{
38
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
42
+ rv64i_bare_cpu_init(obj);
39
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
43
+
40
diff --git a/tests/data/acpi/riscv64/virt/RHCT b/tests/data/acpi/riscv64/virt/RHCT
44
+ RVA22S64.enabled = true;
41
index XXXXXXX..XXXXXXX 100644
45
+}
42
Binary files a/tests/data/acpi/riscv64/virt/RHCT and b/tests/data/acpi/riscv64/virt/RHCT differ
46
#endif
47
48
static const gchar *riscv_gdb_arch_name(CPUState *cs)
49
@@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = {
50
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE128, rv128_base_cpu_init),
51
DEFINE_BARE_CPU(TYPE_RISCV_CPU_RV64I, rv64i_bare_cpu_init),
52
DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA22U64, rva22u64_profile_cpu_init),
53
+ DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA22S64, rva22s64_profile_cpu_init),
54
#endif
55
};
56
57
--
43
--
58
2.43.0
44
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
We have two instances of the setting/clearing a MISA bit from
3
shtvala is described in RVA22 as:
4
env->misa_ext and env->misa_ext_mask pattern. And the next patch will
5
end up adding one more.
6
4
7
Create a helper to avoid code repetition.
5
"htval must be written with the faulting guest physical address
6
in all circumstances permitted by the ISA."
7
8
This is the case since commit 3067553993, so claim support for shtvala.
8
9
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
12
Message-ID: <20241218114026.1652352-6-dbarboza@ventanamicro.com>
12
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
13
Message-ID: <20231218125334.37184-13-dbarboza@ventanamicro.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
14
---
16
target/riscv/tcg/tcg-cpu.c | 32 ++++++++++++++++++--------------
15
target/riscv/cpu.c | 1 +
17
1 file changed, 18 insertions(+), 14 deletions(-)
16
tests/data/acpi/riscv64/virt/RHCT | Bin 356 -> 364 bytes
17
2 files changed, 1 insertion(+)
18
18
19
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
19
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
20
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/tcg/tcg-cpu.c
21
--- a/target/riscv/cpu.c
22
+++ b/target/riscv/tcg/tcg-cpu.c
22
+++ b/target/riscv/cpu.c
23
@@ -XXX,XX +XXX,XX @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
23
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
24
GUINT_TO_POINTER(ext_offset));
24
ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx),
25
}
25
ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin),
26
26
ISA_EXT_DATA_ENTRY(shcounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
27
+static void riscv_cpu_write_misa_bit(RISCVCPU *cpu, uint32_t bit,
27
+ ISA_EXT_DATA_ENTRY(shtvala, PRIV_VERSION_1_12_0, has_priv_1_12),
28
+ bool enabled)
28
ISA_EXT_DATA_ENTRY(shvstvala, PRIV_VERSION_1_12_0, has_priv_1_12),
29
+{
29
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
30
+ CPURISCVState *env = &cpu->env;
30
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
31
+
31
diff --git a/tests/data/acpi/riscv64/virt/RHCT b/tests/data/acpi/riscv64/virt/RHCT
32
+ if (enabled) {
32
index XXXXXXX..XXXXXXX 100644
33
+ env->misa_ext |= bit;
33
Binary files a/tests/data/acpi/riscv64/virt/RHCT and b/tests/data/acpi/riscv64/virt/RHCT differ
34
+ env->misa_ext_mask |= bit;
35
+ } else {
36
+ env->misa_ext &= ~bit;
37
+ env->misa_ext_mask &= ~bit;
38
+ }
39
+}
40
+
41
static void riscv_cpu_synchronize_from_tb(CPUState *cs,
42
const TranslationBlock *tb)
43
{
44
@@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
45
*/
46
env->priv_ver = PRIV_VERSION_1_12_0;
47
}
48
-
49
- env->misa_ext |= misa_bit;
50
- env->misa_ext_mask |= misa_bit;
51
- } else {
52
- env->misa_ext &= ~misa_bit;
53
- env->misa_ext_mask &= ~misa_bit;
54
}
55
+
56
+ riscv_cpu_write_misa_bit(cpu, misa_bit, value);
57
}
58
59
static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
60
@@ -XXX,XX +XXX,XX @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
61
*/
62
static void riscv_cpu_add_misa_properties(Object *cpu_obj)
63
{
64
- CPURISCVState *env = &RISCV_CPU(cpu_obj)->env;
65
bool use_def_vals = riscv_cpu_is_generic(cpu_obj);
66
int i;
67
68
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
69
NULL, (void *)misa_cfg);
70
object_property_set_description(cpu_obj, name, desc);
71
if (use_def_vals) {
72
- if (misa_cfg->enabled) {
73
- env->misa_ext |= bit;
74
- env->misa_ext_mask |= bit;
75
- } else {
76
- env->misa_ext &= ~bit;
77
- env->misa_ext_mask &= ~bit;
78
- }
79
+ riscv_cpu_write_misa_bit(RISCV_CPU(cpu_obj), bit,
80
+ misa_cfg->enabled);
81
}
82
}
83
}
84
--
34
--
85
2.43.0
35
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Profiles will need to validate satp_mode during their own finalize
3
shvstvecd is defined in RVA22 as:
4
methods. This will occur inside riscv_tcg_cpu_finalize_features() for
4
5
TCG. Given that satp_mode does not have any pre-req from the accelerator
5
"vstvec.MODE must be capable of holding the value 0 (Direct).
6
finalize() method, it's safe to finalize it earlier.
6
When vstvec.MODE=Direct, vstvec.BASE must be capable of holding any
7
valid four-byte-aligned address."
8
9
This is always true for TCG so let's claim support for it.
7
10
8
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-ID: <20231218125334.37184-22-dbarboza@ventanamicro.com>
13
Message-ID: <20241218114026.1652352-7-dbarboza@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
15
---
14
target/riscv/cpu.c | 16 ++++++++--------
16
target/riscv/cpu.c | 1 +
15
1 file changed, 8 insertions(+), 8 deletions(-)
17
tests/data/acpi/riscv64/virt/RHCT | Bin 364 -> 374 bytes
18
2 files changed, 1 insertion(+)
16
19
17
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
20
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
18
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/cpu.c
22
--- a/target/riscv/cpu.c
20
+++ b/target/riscv/cpu.c
23
+++ b/target/riscv/cpu.c
21
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
24
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
22
{
25
ISA_EXT_DATA_ENTRY(shcounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
23
Error *local_err = NULL;
26
ISA_EXT_DATA_ENTRY(shtvala, PRIV_VERSION_1_12_0, has_priv_1_12),
24
27
ISA_EXT_DATA_ENTRY(shvstvala, PRIV_VERSION_1_12_0, has_priv_1_12),
25
+#ifndef CONFIG_USER_ONLY
28
+ ISA_EXT_DATA_ENTRY(shvstvecd, PRIV_VERSION_1_12_0, has_priv_1_12),
26
+ riscv_cpu_satp_mode_finalize(cpu, &local_err);
29
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
27
+ if (local_err != NULL) {
30
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
28
+ error_propagate(errp, local_err);
31
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
29
+ return;
32
diff --git a/tests/data/acpi/riscv64/virt/RHCT b/tests/data/acpi/riscv64/virt/RHCT
30
+ }
33
index XXXXXXX..XXXXXXX 100644
31
+#endif
34
Binary files a/tests/data/acpi/riscv64/virt/RHCT and b/tests/data/acpi/riscv64/virt/RHCT differ
32
+
33
/*
34
* KVM accel does not have a specialized finalize()
35
* callback because its extensions are validated
36
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
37
return;
38
}
39
}
40
-
41
-#ifndef CONFIG_USER_ONLY
42
- riscv_cpu_satp_mode_finalize(cpu, &local_err);
43
- if (local_err != NULL) {
44
- error_propagate(errp, local_err);
45
- return;
46
- }
47
-#endif
48
}
49
50
static void riscv_cpu_realize(DeviceState *dev, Error **errp)
51
--
35
--
52
2.43.0
36
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
We already track user choice for multi-letter extensions because we
3
shvsatpa is defined in RVA22 as:
4
needed to honor user choice when enabling/disabling extensions during
5
realize(). We refrained from adding the same mechanism for MISA
6
extensions since we didn't need it.
7
4
8
Profile support requires tne need to check for user choice for MISA
5
"All translation modes supported in satp must be supported in vsatp."
9
extensions, so let's add the corresponding hash now. It works like the
10
existing multi-letter hash (multi_ext_user_opts) but tracking MISA bits
11
options in the cpu_set_misa_ext_cfg() callback.
12
6
13
Note that we can't re-use the same hash from multi-letter extensions
7
This is always true in TCG so let's claim support for it.
14
because that hash uses cpu->cfg offsets as keys, while for MISA
15
extensions we're using MISA bits as keys.
16
17
After adding the user hash in cpu_set_misa_ext_cfg(), setting default
18
values with object_property_set_bool() in add_misa_properties() will end
19
up marking the user choice hash with them. Set the default value
20
manually to avoid it.
21
8
22
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
23
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
24
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
11
Message-ID: <20241218114026.1652352-8-dbarboza@ventanamicro.com>
25
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
26
Message-ID: <20231218125334.37184-12-dbarboza@ventanamicro.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
---
13
---
29
target/riscv/tcg/tcg-cpu.c | 15 ++++++++++++++-
14
target/riscv/cpu.c | 1 +
30
1 file changed, 14 insertions(+), 1 deletion(-)
15
tests/data/acpi/riscv64/virt/RHCT | Bin 374 -> 382 bytes
16
2 files changed, 1 insertion(+)
31
17
32
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
18
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
33
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/tcg/tcg-cpu.c
20
--- a/target/riscv/cpu.c
35
+++ b/target/riscv/tcg/tcg-cpu.c
21
+++ b/target/riscv/cpu.c
36
@@ -XXX,XX +XXX,XX @@
22
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
37
23
ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin),
38
/* Hash that stores user set extensions */
24
ISA_EXT_DATA_ENTRY(shcounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
39
static GHashTable *multi_ext_user_opts;
25
ISA_EXT_DATA_ENTRY(shtvala, PRIV_VERSION_1_12_0, has_priv_1_12),
40
+static GHashTable *misa_ext_user_opts;
26
+ ISA_EXT_DATA_ENTRY(shvsatpa, PRIV_VERSION_1_12_0, has_priv_1_12),
41
27
ISA_EXT_DATA_ENTRY(shvstvala, PRIV_VERSION_1_12_0, has_priv_1_12),
42
static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
28
ISA_EXT_DATA_ENTRY(shvstvecd, PRIV_VERSION_1_12_0, has_priv_1_12),
43
{
29
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
44
@@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
30
diff --git a/tests/data/acpi/riscv64/virt/RHCT b/tests/data/acpi/riscv64/virt/RHCT
45
return;
31
index XXXXXXX..XXXXXXX 100644
46
}
32
Binary files a/tests/data/acpi/riscv64/virt/RHCT and b/tests/data/acpi/riscv64/virt/RHCT differ
47
48
+ g_hash_table_insert(misa_ext_user_opts,
49
+ GUINT_TO_POINTER(misa_bit),
50
+ (gpointer)value);
51
+
52
prev_val = env->misa_ext & misa_bit;
53
54
if (value == prev_val) {
55
@@ -XXX,XX +XXX,XX @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
56
*/
57
static void riscv_cpu_add_misa_properties(Object *cpu_obj)
58
{
59
+ CPURISCVState *env = &RISCV_CPU(cpu_obj)->env;
60
bool use_def_vals = riscv_cpu_is_generic(cpu_obj);
61
int i;
62
63
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
64
NULL, (void *)misa_cfg);
65
object_property_set_description(cpu_obj, name, desc);
66
if (use_def_vals) {
67
- object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL);
68
+ if (misa_cfg->enabled) {
69
+ env->misa_ext |= bit;
70
+ env->misa_ext_mask |= bit;
71
+ } else {
72
+ env->misa_ext &= ~bit;
73
+ env->misa_ext_mask &= ~bit;
74
+ }
75
}
76
}
77
}
78
@@ -XXX,XX +XXX,XX @@ static void tcg_cpu_instance_init(CPUState *cs)
79
RISCVCPU *cpu = RISCV_CPU(cs);
80
Object *obj = OBJECT(cpu);
81
82
+ misa_ext_user_opts = g_hash_table_new(NULL, g_direct_equal);
83
multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal);
84
riscv_cpu_add_user_properties(obj);
85
86
--
33
--
87
2.43.0
34
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
We don't have any form of a 'bare bones' CPU. rv64, our default CPUs,
3
shgatpa is defined in RVA22 as:
4
comes with a lot of defaults. This is fine for most regular uses but
5
it's not suitable when more control of what is actually loaded in the
6
CPU is required.
7
4
8
A bare-bones CPU would be annoying to deal with if not by profile
5
"For each supported virtual memory scheme SvNN supported in satp, the
9
support, a way to load a multitude of extensions with a single flag.
6
corresponding hgatp SvNNx4 mode must be supported. The hgatp mode Bare
10
Profile support is going to be implemented shortly, so let's add a CPU
7
must also be supported."
11
for it.
12
8
13
The new 'rv64i' CPU will have only RVI loaded. It is inspired in the
9
Claim support for shgatpa since this is always true for TCG.
14
profile specification that dictates, for RVA22U64 [1]:
15
16
"RVA22U64 Mandatory Base
17
RV64I is the mandatory base ISA for RVA22U64"
18
19
And so it seems that RV64I is the mandatory base ISA for all profiles
20
listed in [1], making it an ideal CPU to use with profile support.
21
22
rv64i is a CPU of type TYPE_RISCV_BARE_CPU. It has a mix of features
23
from pre-existent CPUs:
24
25
- it allows extensions to be enabled, like generic CPUs;
26
- it will not inherit extension defaults, like vendor CPUs.
27
28
This is the minimum extension set to boot OpenSBI and buildroot using
29
rv64i:
30
31
./build/qemu-system-riscv64 -nographic -M virt \
32
-cpu rv64i,sv39=true,g=true,c=true,s=true,u=true
33
34
Our minimal riscv,isa in this case will be:
35
36
# cat /proc/device-tree/cpus/cpu@0/riscv,isa
37
rv64imafdc_zicntr_zicsr_zifencei_zihpm_zca_zcd#
38
39
[1] https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc
40
10
41
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
42
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
43
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
44
Message-ID: <20231218125334.37184-5-dbarboza@ventanamicro.com>
13
Message-ID: <20241218114026.1652352-9-dbarboza@ventanamicro.com>
45
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
46
---
15
---
47
target/riscv/cpu-qom.h | 2 ++
16
target/riscv/cpu.c | 1 +
48
target/riscv/cpu.c | 46 ++++++++++++++++++++++++++++++++++++++++++
17
tests/data/acpi/riscv64/virt/RHCT | Bin 382 -> 390 bytes
49
2 files changed, 48 insertions(+)
18
2 files changed, 1 insertion(+)
50
19
51
diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h
52
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/cpu-qom.h
54
+++ b/target/riscv/cpu-qom.h
55
@@ -XXX,XX +XXX,XX @@
56
#define TYPE_RISCV_CPU "riscv-cpu"
57
#define TYPE_RISCV_DYNAMIC_CPU "riscv-dynamic-cpu"
58
#define TYPE_RISCV_VENDOR_CPU "riscv-vendor-cpu"
59
+#define TYPE_RISCV_BARE_CPU "riscv-bare-cpu"
60
61
#define RISCV_CPU_TYPE_SUFFIX "-" TYPE_RISCV_CPU
62
#define RISCV_CPU_TYPE_NAME(name) (name RISCV_CPU_TYPE_SUFFIX)
63
@@ -XXX,XX +XXX,XX @@
64
#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")
65
#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64")
66
#define TYPE_RISCV_CPU_BASE128 RISCV_CPU_TYPE_NAME("x-rv128")
67
+#define TYPE_RISCV_CPU_RV64I RISCV_CPU_TYPE_NAME("rv64i")
68
#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")
69
#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")
70
#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")
71
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
20
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
72
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
73
--- a/target/riscv/cpu.c
22
--- a/target/riscv/cpu.c
74
+++ b/target/riscv/cpu.c
23
+++ b/target/riscv/cpu.c
75
@@ -XXX,XX +XXX,XX @@ static void set_satp_mode_max_supported(RISCVCPU *cpu,
24
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
76
/* Set the satp mode to the max supported */
25
ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx),
77
static void set_satp_mode_default_map(RISCVCPU *cpu)
26
ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin),
78
{
27
ISA_EXT_DATA_ENTRY(shcounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
79
+ /*
28
+ ISA_EXT_DATA_ENTRY(shgatpa, PRIV_VERSION_1_12_0, has_priv_1_12),
80
+ * Bare CPUs do not default to the max available.
29
ISA_EXT_DATA_ENTRY(shtvala, PRIV_VERSION_1_12_0, has_priv_1_12),
81
+ * Users must set a valid satp_mode in the command
30
ISA_EXT_DATA_ENTRY(shvsatpa, PRIV_VERSION_1_12_0, has_priv_1_12),
82
+ * line.
31
ISA_EXT_DATA_ENTRY(shvstvala, PRIV_VERSION_1_12_0, has_priv_1_12),
83
+ */
32
diff --git a/tests/data/acpi/riscv64/virt/RHCT b/tests/data/acpi/riscv64/virt/RHCT
84
+ if (object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_BARE_CPU) != NULL) {
33
index XXXXXXX..XXXXXXX 100644
85
+ warn_report("No satp mode set. Defaulting to 'bare'");
34
Binary files a/tests/data/acpi/riscv64/virt/RHCT and b/tests/data/acpi/riscv64/virt/RHCT differ
86
+ cpu->cfg.satp_mode.map = (1 << VM_1_10_MBARE);
87
+ return;
88
+ }
89
+
90
cpu->cfg.satp_mode.map = cpu->cfg.satp_mode.supported;
91
}
92
#endif
93
@@ -XXX,XX +XXX,XX @@ static void rv128_base_cpu_init(Object *obj)
94
set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57);
95
#endif
96
}
97
+
98
+static void rv64i_bare_cpu_init(Object *obj)
99
+{
100
+ CPURISCVState *env = &RISCV_CPU(obj)->env;
101
+ riscv_cpu_set_misa(env, MXL_RV64, RVI);
102
+
103
+ /* Remove the defaults from the parent class */
104
+ RISCV_CPU(obj)->cfg.ext_zicntr = false;
105
+ RISCV_CPU(obj)->cfg.ext_zihpm = false;
106
+
107
+ /* Set to QEMU's first supported priv version */
108
+ env->priv_ver = PRIV_VERSION_1_10_0;
109
+
110
+ /*
111
+ * Support all available satp_mode settings. The default
112
+ * value will be set to MBARE if the user doesn't set
113
+ * satp_mode manually (see set_satp_mode_default()).
114
+ */
115
+#ifndef CONFIG_USER_ONLY
116
+ set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV64);
117
+#endif
118
+}
119
#else
120
static void rv32_base_cpu_init(Object *obj)
121
{
122
@@ -XXX,XX +XXX,XX @@ char *riscv_isa_string(RISCVCPU *cpu)
123
.instance_init = initfn \
124
}
125
126
+#define DEFINE_BARE_CPU(type_name, initfn) \
127
+ { \
128
+ .name = type_name, \
129
+ .parent = TYPE_RISCV_BARE_CPU, \
130
+ .instance_init = initfn \
131
+ }
132
+
133
static const TypeInfo riscv_cpu_type_infos[] = {
134
{
135
.name = TYPE_RISCV_CPU,
136
@@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = {
137
.parent = TYPE_RISCV_CPU,
138
.abstract = true,
139
},
140
+ {
141
+ .name = TYPE_RISCV_BARE_CPU,
142
+ .parent = TYPE_RISCV_CPU,
143
+ .abstract = true,
144
+ },
145
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init),
146
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_MAX, riscv_max_cpu_init),
147
#if defined(TARGET_RISCV32)
148
@@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = {
149
DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_THEAD_C906, rv64_thead_c906_cpu_init),
150
DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_VEYRON_V1, rv64_veyron_v1_cpu_init),
151
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE128, rv128_base_cpu_init),
152
+ DEFINE_BARE_CPU(TYPE_RISCV_CPU_RV64I, rv64i_bare_cpu_init),
153
#endif
154
};
155
156
--
35
--
157
2.43.0
36
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
'svade' is a RVA22S64 profile requirement, a profile we're going to add
3
'sha' is the augmented hypervisor extension, defined in RVA22 as a set of
4
shortly. It is a named feature (i.e. not a formal extension, not defined
4
the following extensions:
5
in riscv,isa DT at this moment) defined in [1] as:
6
5
7
"Page-fault exceptions are raised when a page is accessed when A bit is
6
- RVH
8
clear, or written when D bit is clear.".
7
- Ssstateen
8
- Shcounterenw (always present)
9
- Shvstvala (always present)
10
- Shtvala (always present)
11
- Shvstvecd (always present)
12
- Shvsatpa (always present)
13
- Shgatpa (always present)
9
14
10
As far as the spec goes, 'svade' is one of the two distinct modes of
15
We can claim support for 'sha' by checking if we have RVH and ssstateen.
11
handling PTE_A and PTE_D. The other way, i.e. update PTE_A/PTE_D when
12
they're cleared, is defined by the 'svadu' extension. Checking
13
cpu_helper.c, get_physical_address(), we can verify that QEMU is
14
compliant with that: we will update PTE_A/PTE_D if 'svadu' is enabled,
15
or throw a page-fault exception if 'svadu' isn't enabled.
16
17
So, as far as we're concerned, 'svade' translates to 'svadu must be
18
disabled'.
19
20
We'll implement it like 'zic64b': an internal flag that profiles can
21
enable. The flag will not be exposed to users.
22
23
[1] https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc
24
16
25
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
17
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
26
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
27
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
28
Message-ID: <20231218125334.37184-20-dbarboza@ventanamicro.com>
19
Message-ID: <20241218114026.1652352-10-dbarboza@ventanamicro.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
30
---
21
---
31
target/riscv/cpu_cfg.h | 1 +
22
target/riscv/cpu_cfg.h | 1 +
32
target/riscv/cpu.c | 1 +
23
target/riscv/cpu.c | 2 ++
33
target/riscv/tcg/tcg-cpu.c | 5 +++++
24
target/riscv/tcg/tcg-cpu.c | 8 ++++++++
34
3 files changed, 7 insertions(+)
25
3 files changed, 11 insertions(+)
35
26
36
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
27
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
37
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/cpu_cfg.h
29
--- a/target/riscv/cpu_cfg.h
39
+++ b/target/riscv/cpu_cfg.h
30
+++ b/target/riscv/cpu_cfg.h
40
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
31
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
41
bool ext_smepmp;
32
bool ext_svade;
42
bool rvv_ta_all_1s;
33
bool ext_zic64b;
43
bool rvv_ma_all_1s;
34
bool ext_ssstateen;
44
+ bool svade;
35
+ bool ext_sha;
45
bool zic64b;
36
46
37
/*
47
uint32_t mvendorid;
38
* Always 'true' booleans for named features
48
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
39
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
49
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
50
--- a/target/riscv/cpu.c
41
--- a/target/riscv/cpu.c
51
+++ b/target/riscv/cpu.c
42
+++ b/target/riscv/cpu.c
43
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
44
ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx),
45
ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin),
46
ISA_EXT_DATA_ENTRY(shcounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
47
+ ISA_EXT_DATA_ENTRY(sha, PRIV_VERSION_1_12_0, ext_sha),
48
ISA_EXT_DATA_ENTRY(shgatpa, PRIV_VERSION_1_12_0, has_priv_1_12),
49
ISA_EXT_DATA_ENTRY(shtvala, PRIV_VERSION_1_12_0, has_priv_1_12),
50
ISA_EXT_DATA_ENTRY(shvsatpa, PRIV_VERSION_1_12_0, has_priv_1_12),
52
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
51
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
52
const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = {
53
MULTI_EXT_CFG_BOOL("zic64b", ext_zic64b, true),
54
MULTI_EXT_CFG_BOOL("ssstateen", ext_ssstateen, true),
55
+ MULTI_EXT_CFG_BOOL("sha", ext_sha, true),
56
57
{ },
53
};
58
};
54
55
const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = {
56
+ MULTI_EXT_CFG_BOOL("svade", svade, true),
57
MULTI_EXT_CFG_BOOL("zic64b", zic64b, true),
58
59
DEFINE_PROP_END_OF_LIST(),
60
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
59
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
61
index XXXXXXX..XXXXXXX 100644
60
index XXXXXXX..XXXXXXX 100644
62
--- a/target/riscv/tcg/tcg-cpu.c
61
--- a/target/riscv/tcg/tcg-cpu.c
63
+++ b/target/riscv/tcg/tcg-cpu.c
62
+++ b/target/riscv/tcg/tcg-cpu.c
64
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_enable_named_feat(RISCVCPU *cpu, uint32_t feat_offset)
63
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_enable_named_feat(RISCVCPU *cpu, uint32_t feat_offset)
65
cpu->cfg.cbop_blocksize = 64;
64
cpu->cfg.cbop_blocksize = 64;
66
cpu->cfg.cboz_blocksize = 64;
65
cpu->cfg.cboz_blocksize = 64;
67
break;
66
break;
68
+ case CPU_CFG_OFFSET(svade):
67
+ case CPU_CFG_OFFSET(ext_sha):
69
+ cpu->cfg.ext_svadu = false;
68
+ if (!cpu_misa_ext_is_user_set(RVH)) {
70
+ break;
69
+ riscv_cpu_write_misa_bit(cpu, RVH, true);
71
default:
70
+ }
72
g_assert_not_reached();
71
+ /* fallthrough */
73
}
72
case CPU_CFG_OFFSET(ext_ssstateen):
73
cpu->cfg.ext_smstateen = true;
74
break;
74
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_update_named_features(RISCVCPU *cpu)
75
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_update_named_features(RISCVCPU *cpu)
75
cpu->cfg.zic64b = cpu->cfg.cbom_blocksize == 64 &&
76
cpu->cfg.cboz_blocksize == 64;
76
cpu->cfg.cbop_blocksize == 64 &&
77
77
cpu->cfg.cboz_blocksize == 64;
78
cpu->cfg.ext_ssstateen = cpu->cfg.ext_smstateen;
78
+
79
+
79
+ cpu->cfg.svade = !cpu->cfg.ext_svadu;
80
+ cpu->cfg.ext_sha = riscv_has_ext(&cpu->env, RVH) &&
81
+ cpu->cfg.ext_ssstateen;
80
}
82
}
81
83
82
static void riscv_cpu_validate_g(RISCVCPU *cpu)
84
static void riscv_cpu_validate_g(RISCVCPU *cpu)
83
--
85
--
84
2.43.0
86
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Next patch will need to retrieve if a given RISCVCPU is 32 or 64 bit.
3
Do a cosmetic change in riscv_raise_exception() to change 'exception'
4
The existing helper riscv_is_32bit() (hw/riscv/boot.c) will always check
4
type from uint32_t to RISCVException, making it a bit clear that the
5
the first CPU of a given hart array, not any given CPU.
5
arg is directly correlated to the RISCVException enum.
6
6
7
Create a helper to retrieve the info for any given CPU, not the first
7
As a side effect, change 'excp' type from int to RISCVException in
8
CPU of the hart array. The helper is using the same 32 bit check that
8
generate_exception() to guarantee that all callers of
9
riscv_cpu_satp_mode_finalize() was doing.
9
riscv_raise_exception() will use the enum.
10
10
11
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
12
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Message-ID: <20250106173734.412353-2-dbarboza@ventanamicro.com>
15
Message-ID: <20231218125334.37184-23-dbarboza@ventanamicro.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
16
---
18
target/riscv/cpu.h | 1 +
17
target/riscv/cpu.h | 3 ++-
19
target/riscv/cpu.c | 7 ++++++-
18
target/riscv/op_helper.c | 3 ++-
20
2 files changed, 7 insertions(+), 1 deletion(-)
19
target/riscv/translate.c | 2 +-
20
3 files changed, 5 insertions(+), 3 deletions(-)
21
21
22
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
22
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
23
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/cpu.h
24
--- a/target/riscv/cpu.h
25
+++ b/target/riscv/cpu.h
25
+++ b/target/riscv/cpu.h
26
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
26
@@ -XXX,XX +XXX,XX @@ void riscv_translate_code(CPUState *cs, TranslationBlock *tb,
27
uint64_t *cs_base, uint32_t *pflags);
27
int *max_insns, vaddr pc, void *host_pc);
28
28
29
void riscv_cpu_update_mask(CPURISCVState *env);
29
G_NORETURN void riscv_raise_exception(CPURISCVState *env,
30
+bool riscv_cpu_is_32bit(RISCVCPU *cpu);
30
- uint32_t exception, uintptr_t pc);
31
31
+ RISCVException exception,
32
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
32
+ uintptr_t pc);
33
target_ulong *ret_value,
33
34
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
34
target_ulong riscv_cpu_get_fflags(CPURISCVState *env);
35
void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong);
36
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
35
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
36
--- a/target/riscv/cpu.c
38
--- a/target/riscv/op_helper.c
37
+++ b/target/riscv/cpu.c
39
+++ b/target/riscv/op_helper.c
38
@@ -XXX,XX +XXX,XX @@ const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV,
40
@@ -XXX,XX +XXX,XX @@
39
#define BYTE(x) (x)
41
40
#endif
42
/* Exceptions processing helpers */
41
43
G_NORETURN void riscv_raise_exception(CPURISCVState *env,
42
+bool riscv_cpu_is_32bit(RISCVCPU *cpu)
44
- uint32_t exception, uintptr_t pc)
43
+{
45
+ RISCVException exception,
44
+ return riscv_cpu_mxl(&cpu->env) == MXL_RV32;
46
+ uintptr_t pc)
45
+}
46
+
47
#define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \
48
{#_name, _min_ver, CPU_CFG_OFFSET(_prop)}
49
50
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)
51
#ifndef CONFIG_USER_ONLY
52
static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp)
53
{
47
{
54
- bool rv32 = riscv_cpu_mxl(&cpu->env) == MXL_RV32;
48
CPUState *cs = env_cpu(env);
55
+ bool rv32 = riscv_cpu_is_32bit(cpu);
49
cs->exception_index = exception;
56
uint8_t satp_mode_map_max, satp_mode_supported_max;
50
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
57
51
index XXXXXXX..XXXXXXX 100644
58
/* The CPU wants the OS to decide which satp mode to use */
52
--- a/target/riscv/translate.c
53
+++ b/target/riscv/translate.c
54
@@ -XXX,XX +XXX,XX @@ static void gen_update_pc(DisasContext *ctx, target_long diff)
55
ctx->pc_save = ctx->base.pc_next + diff;
56
}
57
58
-static void generate_exception(DisasContext *ctx, int excp)
59
+static void generate_exception(DisasContext *ctx, RISCVException excp)
60
{
61
gen_update_pc(ctx, 0);
62
gen_helper_raise_exception(tcg_env, tcg_constant_i32(excp));
59
--
63
--
60
2.43.0
64
2.48.1
61
65
62
66
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
KVM does not have the means to support enabling the rva22u64 profile.
3
When using system mode we can get the CPU traps being taken via the
4
The main reasons are:
4
'riscv_trap' trace or the "-d int" qemu log. User mode does not a way of
5
logging/showing exceptions to users.
5
6
6
- we're missing support for some mandatory rva22u64 extensions in the
7
Add a trace in riscv_raise_exception() to allow qemu-riscv(32/64) users
7
KVM module;
8
to check all exceptions being thrown. This is particularly useful to
9
help identifying insns that are throwing SIGILLs.
8
10
9
- we can't make promises about enabling a profile since it all depends
11
As it is today we need to debug their binaries to identify where the
10
on host support in the end.
12
illegal insns are:
11
13
12
We'll revisit this decision in the future if needed. For now mark the
14
$ ~/work/qemu/build/qemu-riscv64 -cpu rv64 ./foo.out
13
'rva22u64' profile as unavailable when running a KVM CPU:
15
Illegal instruction (core dumped)
14
16
15
$ qemu-system-riscv64 -machine virt,accel=kvm -cpu rv64,rva22u64=true
17
After this change users can capture the trace and use EPC to pinpoint
16
qemu-system-riscv64: can't apply global rv64-riscv-cpu.rva22u64=true:
18
the insn:
17
'rva22u64' is not available with KVM
19
20
$ ~/work/qemu/build/qemu-riscv64 -cpu rv64 -trace riscv_exception ./foo.out
21
riscv_exception 8 (user_ecall) on epc 0x17cd2
22
riscv_exception 8 (user_ecall) on epc 0x17cda
23
riscv_exception 8 (user_ecall) on epc 0x17622
24
(...)
25
riscv_exception 2 (illegal_instruction) on epc 0x1053a
26
Illegal instruction (core dumped)
18
27
19
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
28
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
20
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
29
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
21
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
30
Message-ID: <20250106173734.412353-3-dbarboza@ventanamicro.com>
22
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
23
Message-ID: <20231218125334.37184-10-dbarboza@ventanamicro.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
31
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
32
---
26
target/riscv/kvm/kvm-cpu.c | 7 ++++++-
33
target/riscv/op_helper.c | 6 ++++++
27
1 file changed, 6 insertions(+), 1 deletion(-)
34
target/riscv/trace-events | 3 +++
35
2 files changed, 9 insertions(+)
28
36
29
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
37
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
30
index XXXXXXX..XXXXXXX 100644
38
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/kvm/kvm-cpu.c
39
--- a/target/riscv/op_helper.c
32
+++ b/target/riscv/kvm/kvm-cpu.c
40
+++ b/target/riscv/op_helper.c
33
@@ -XXX,XX +XXX,XX @@ static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
41
@@ -XXX,XX +XXX,XX @@
34
}
42
#include "exec/exec-all.h"
35
43
#include "exec/cpu_ldst.h"
36
if (value) {
44
#include "exec/helper-proto.h"
37
- error_setg(errp, "extension %s is not available with KVM",
45
+#include "trace.h"
38
+ error_setg(errp, "'%s' is not available with KVM",
46
39
propname);
47
/* Exceptions processing helpers */
40
}
48
G_NORETURN void riscv_raise_exception(CPURISCVState *env,
49
@@ -XXX,XX +XXX,XX @@ G_NORETURN void riscv_raise_exception(CPURISCVState *env,
50
uintptr_t pc)
51
{
52
CPUState *cs = env_cpu(env);
53
+
54
+ trace_riscv_exception(exception,
55
+ riscv_cpu_get_trap_name(exception, false),
56
+ env->pc);
57
+
58
cs->exception_index = exception;
59
cpu_loop_exit_restore(cs, pc);
41
}
60
}
42
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
61
diff --git a/target/riscv/trace-events b/target/riscv/trace-events
43
riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_extensions);
62
index XXXXXXX..XXXXXXX 100644
44
riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_vendor_exts);
63
--- a/target/riscv/trace-events
45
riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_experimental_exts);
64
+++ b/target/riscv/trace-events
65
@@ -XXX,XX +XXX,XX @@ pmpaddr_csr_write(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %"
66
67
mseccfg_csr_read(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": read mseccfg, val: 0x%" PRIx64
68
mseccfg_csr_write(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": write mseccfg, val: 0x%" PRIx64
46
+
69
+
47
+ /* We don't have the needed KVM support for profiles */
70
+# op_helper.c
48
+ for (i = 0; riscv_profiles[i] != NULL; i++) {
71
+riscv_exception(uint32_t exception, const char *desc, uint64_t epc) "%u (%s) on epc 0x%"PRIx64""
49
+ riscv_cpu_add_kvm_unavail_prop(cpu_obj, riscv_profiles[i]->name);
50
+ }
51
}
52
53
static int kvm_riscv_get_regs_core(CPUState *cs)
54
--
72
--
55
2.43.0
73
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Alexey Baturo <baturo.alexey@gmail.com>
2
2
3
'satp_mode' is a requirement for supervisor profiles like RVA22S64.
3
Zjpm extension is finally ratified. And it's much simplier compared to the experimental one.
4
User-mode/application profiles like RVA22U64 doesn't care.
4
The newer version doesn't allow to specify custom mask or base for pointer masking.
5
Instead it allows only certain options for masking top bits.
5
6
6
Add 'satp_mode' to the profile description. If a profile requires it,
7
Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
7
set it during cpu_set_profile(). We'll also check it during finalize()
8
to validate if the running config implements the profile.
9
10
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
12
Acked-by: Alistair Francis <alistair.francis@wdc.com>
8
Acked-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-ID: <20231218125334.37184-24-dbarboza@ventanamicro.com>
9
Message-ID: <20250106102346.1100149-2-baturo.alexey@gmail.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
11
---
16
target/riscv/cpu.h | 1 +
12
target/riscv/cpu.h | 33 +---
17
target/riscv/cpu.c | 1 +
13
target/riscv/cpu_bits.h | 87 ----------
18
target/riscv/tcg/tcg-cpu.c | 40 ++++++++++++++++++++++++++++++++++++++
14
target/riscv/cpu.c | 13 +-
19
3 files changed, 42 insertions(+)
15
target/riscv/cpu_helper.c | 52 ------
16
target/riscv/csr.c | 326 -----------------------------------
17
target/riscv/machine.c | 17 +-
18
target/riscv/tcg/tcg-cpu.c | 5 +-
19
target/riscv/translate.c | 28 +--
20
target/riscv/vector_helper.c | 2 +-
21
9 files changed, 19 insertions(+), 544 deletions(-)
20
22
21
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
23
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
22
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/cpu.h
25
--- a/target/riscv/cpu.h
24
+++ b/target/riscv/cpu.h
26
+++ b/target/riscv/cpu.h
25
@@ -XXX,XX +XXX,XX @@ typedef struct riscv_cpu_profile {
27
@@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState CPURISCVState;
26
bool enabled;
28
#define RVS RV('S')
27
bool user_set;
29
#define RVU RV('U')
28
int priv_spec;
30
#define RVH RV('H')
29
+ int satp_mode;
31
-#define RVJ RV('J')
30
const int32_t ext_offsets[];
32
#define RVG RV('G')
31
} RISCVCPUProfile;
33
#define RVB RV('B')
32
34
35
@@ -XXX,XX +XXX,XX @@ struct CPUArchState {
36
/* True if in debugger mode. */
37
bool debugger;
38
39
- /*
40
- * CSRs for PointerMasking extension
41
- */
42
- target_ulong mmte;
43
- target_ulong mpmmask;
44
- target_ulong mpmbase;
45
- target_ulong spmmask;
46
- target_ulong spmbase;
47
- target_ulong upmmask;
48
- target_ulong upmbase;
49
-
50
uint64_t mstateen[SMSTATEEN_MAX_COUNT];
51
uint64_t hstateen[SMSTATEEN_MAX_COUNT];
52
uint64_t sstateen[SMSTATEEN_MAX_COUNT];
53
uint64_t henvcfg;
54
#endif
55
- target_ulong cur_pmmask;
56
- target_ulong cur_pmbase;
57
58
/* Fields from here on are preserved across CPU reset. */
59
QEMUTimer *stimer; /* Internal timer for S-mode interrupt */
60
@@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, XL, 16, 2)
61
/* If PointerMasking should be applied */
62
FIELD(TB_FLAGS, PM_MASK_ENABLED, 18, 1)
63
FIELD(TB_FLAGS, PM_BASE_ENABLED, 19, 1)
64
-FIELD(TB_FLAGS, VTA, 20, 1)
65
-FIELD(TB_FLAGS, VMA, 21, 1)
66
+FIELD(TB_FLAGS, VTA, 18, 1)
67
+FIELD(TB_FLAGS, VMA, 19, 1)
68
/* Native debug itrigger */
69
-FIELD(TB_FLAGS, ITRIGGER, 22, 1)
70
+FIELD(TB_FLAGS, ITRIGGER, 20, 1)
71
/* Virtual mode enabled */
72
-FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1)
73
-FIELD(TB_FLAGS, PRIV, 24, 2)
74
-FIELD(TB_FLAGS, AXL, 26, 2)
75
+FIELD(TB_FLAGS, VIRT_ENABLED, 21, 1)
76
+FIELD(TB_FLAGS, PRIV, 22, 2)
77
+FIELD(TB_FLAGS, AXL, 24, 2)
78
/* zicfilp needs a TB flag to track indirect branches */
79
-FIELD(TB_FLAGS, FCFI_ENABLED, 28, 1)
80
-FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 29, 1)
81
+FIELD(TB_FLAGS, FCFI_ENABLED, 26, 1)
82
+FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 27, 1)
83
/* zicfiss needs a TB flag so that correct TB is located based on tb flags */
84
-FIELD(TB_FLAGS, BCFI_ENABLED, 30, 1)
85
+FIELD(TB_FLAGS, BCFI_ENABLED, 28, 1)
86
87
#ifdef TARGET_RISCV32
88
#define riscv_cpu_mxl(env) ((void)(env), MXL_RV32)
89
@@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_get_vlmax(uint32_t vlenb, uint32_t vsew,
90
void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
91
uint64_t *cs_base, uint32_t *pflags);
92
93
-void riscv_cpu_update_mask(CPURISCVState *env);
94
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
95
96
RISCVException riscv_csrr(CPURISCVState *env, int csrno,
97
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
98
index XXXXXXX..XXXXXXX 100644
99
--- a/target/riscv/cpu_bits.h
100
+++ b/target/riscv/cpu_bits.h
101
@@ -XXX,XX +XXX,XX @@
102
#define CSR_MHPMCOUNTER30H 0xb9e
103
#define CSR_MHPMCOUNTER31H 0xb9f
104
105
-/*
106
- * User PointerMasking registers
107
- * NB: actual CSR numbers might be changed in future
108
- */
109
-#define CSR_UMTE 0x4c0
110
-#define CSR_UPMMASK 0x4c1
111
-#define CSR_UPMBASE 0x4c2
112
-
113
-/*
114
- * Machine PointerMasking registers
115
- * NB: actual CSR numbers might be changed in future
116
- */
117
-#define CSR_MMTE 0x3c0
118
-#define CSR_MPMMASK 0x3c1
119
-#define CSR_MPMBASE 0x3c2
120
-
121
-/*
122
- * Supervisor PointerMaster registers
123
- * NB: actual CSR numbers might be changed in future
124
- */
125
-#define CSR_SMTE 0x1c0
126
-#define CSR_SPMMASK 0x1c1
127
-#define CSR_SPMBASE 0x1c2
128
-
129
-/*
130
- * Hypervisor PointerMaster registers
131
- * NB: actual CSR numbers might be changed in future
132
- */
133
-#define CSR_VSMTE 0x2c0
134
-#define CSR_VSPMMASK 0x2c1
135
-#define CSR_VSPMBASE 0x2c2
136
#define CSR_SCOUNTOVF 0xda0
137
138
/* Crypto Extension */
139
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
140
#define VS_MODE_INTERRUPTS ((uint64_t)(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP))
141
#define HS_MODE_INTERRUPTS ((uint64_t)(MIP_SGEIP | VS_MODE_INTERRUPTS))
142
143
-/* General PointerMasking CSR bits */
144
-#define PM_ENABLE 0x00000001ULL
145
-#define PM_CURRENT 0x00000002ULL
146
-#define PM_INSN 0x00000004ULL
147
-
148
/* Execution environment configuration bits */
149
#define MENVCFG_FIOM BIT(0)
150
#define MENVCFG_LPE BIT(2) /* zicfilp */
151
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
152
#define HENVCFGH_PBMTE MENVCFGH_PBMTE
153
#define HENVCFGH_STCE MENVCFGH_STCE
154
155
-/* Offsets for every pair of control bits per each priv level */
156
-#define XS_OFFSET 0ULL
157
-#define U_OFFSET 2ULL
158
-#define S_OFFSET 5ULL
159
-#define M_OFFSET 8ULL
160
-
161
-#define PM_XS_BITS (EXT_STATUS_MASK << XS_OFFSET)
162
-#define U_PM_ENABLE (PM_ENABLE << U_OFFSET)
163
-#define U_PM_CURRENT (PM_CURRENT << U_OFFSET)
164
-#define U_PM_INSN (PM_INSN << U_OFFSET)
165
-#define S_PM_ENABLE (PM_ENABLE << S_OFFSET)
166
-#define S_PM_CURRENT (PM_CURRENT << S_OFFSET)
167
-#define S_PM_INSN (PM_INSN << S_OFFSET)
168
-#define M_PM_ENABLE (PM_ENABLE << M_OFFSET)
169
-#define M_PM_CURRENT (PM_CURRENT << M_OFFSET)
170
-#define M_PM_INSN (PM_INSN << M_OFFSET)
171
-
172
-/* mmte CSR bits */
173
-#define MMTE_PM_XS_BITS PM_XS_BITS
174
-#define MMTE_U_PM_ENABLE U_PM_ENABLE
175
-#define MMTE_U_PM_CURRENT U_PM_CURRENT
176
-#define MMTE_U_PM_INSN U_PM_INSN
177
-#define MMTE_S_PM_ENABLE S_PM_ENABLE
178
-#define MMTE_S_PM_CURRENT S_PM_CURRENT
179
-#define MMTE_S_PM_INSN S_PM_INSN
180
-#define MMTE_M_PM_ENABLE M_PM_ENABLE
181
-#define MMTE_M_PM_CURRENT M_PM_CURRENT
182
-#define MMTE_M_PM_INSN M_PM_INSN
183
-#define MMTE_MASK (MMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | MMTE_U_PM_INSN | \
184
- MMTE_S_PM_ENABLE | MMTE_S_PM_CURRENT | MMTE_S_PM_INSN | \
185
- MMTE_M_PM_ENABLE | MMTE_M_PM_CURRENT | MMTE_M_PM_INSN | \
186
- MMTE_PM_XS_BITS)
187
-
188
-/* (v)smte CSR bits */
189
-#define SMTE_PM_XS_BITS PM_XS_BITS
190
-#define SMTE_U_PM_ENABLE U_PM_ENABLE
191
-#define SMTE_U_PM_CURRENT U_PM_CURRENT
192
-#define SMTE_U_PM_INSN U_PM_INSN
193
-#define SMTE_S_PM_ENABLE S_PM_ENABLE
194
-#define SMTE_S_PM_CURRENT S_PM_CURRENT
195
-#define SMTE_S_PM_INSN S_PM_INSN
196
-#define SMTE_MASK (SMTE_U_PM_ENABLE | SMTE_U_PM_CURRENT | SMTE_U_PM_INSN | \
197
- SMTE_S_PM_ENABLE | SMTE_S_PM_CURRENT | SMTE_S_PM_INSN | \
198
- SMTE_PM_XS_BITS)
199
-
200
-/* umte CSR bits */
201
-#define UMTE_U_PM_ENABLE U_PM_ENABLE
202
-#define UMTE_U_PM_CURRENT U_PM_CURRENT
203
-#define UMTE_U_PM_INSN U_PM_INSN
204
-#define UMTE_MASK (UMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | UMTE_U_PM_INSN)
205
-
206
/* MISELECT, SISELECT, and VSISELECT bits (AIA) */
207
#define ISELECT_IPRIO0 0x30
208
#define ISELECT_IPRIO15 0x3f
33
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
209
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
34
index XXXXXXX..XXXXXXX 100644
210
index XXXXXXX..XXXXXXX 100644
35
--- a/target/riscv/cpu.c
211
--- a/target/riscv/cpu.c
36
+++ b/target/riscv/cpu.c
212
+++ b/target/riscv/cpu.c
37
@@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA22U64 = {
213
@@ -XXX,XX +XXX,XX @@
38
.name = "rva22u64",
214
/* RISC-V CPU definitions */
39
.misa_ext = RVI | RVM | RVA | RVF | RVD | RVC | RVU,
215
static const char riscv_single_letter_exts[] = "IEMAFDQCBPVH";
40
.priv_spec = RISCV_PROFILE_ATTR_UNUSED,
216
const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV,
41
+ .satp_mode = RISCV_PROFILE_ATTR_UNUSED,
217
- RVC, RVS, RVU, RVH, RVJ, RVG, RVB, 0};
42
.ext_offsets = {
218
+ RVC, RVS, RVU, RVH, RVG, RVB, 0};
43
CPU_CFG_OFFSET(ext_zicsr), CPU_CFG_OFFSET(ext_zihintpause),
219
44
CPU_CFG_OFFSET(ext_zba), CPU_CFG_OFFSET(ext_zbb),
220
/*
221
* From vector_helper.c
222
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
223
CSR_MSCRATCH,
224
CSR_SSCRATCH,
225
CSR_SATP,
226
- CSR_MMTE,
227
- CSR_UPMBASE,
228
- CSR_UPMMASK,
229
- CSR_SPMBASE,
230
- CSR_SPMMASK,
231
- CSR_MPMBASE,
232
- CSR_MPMMASK,
233
};
234
235
for (i = 0; i < ARRAY_SIZE(dump_csrs); ++i) {
236
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type)
237
}
238
i++;
239
}
240
- /* mmte is supposed to have pm.current hardwired to 1 */
241
- env->mmte |= (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT);
242
243
/*
244
* Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor
245
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type)
246
env->ssp = 0;
247
248
env->xl = riscv_cpu_mxl(env);
249
- riscv_cpu_update_mask(env);
250
cs->exception_index = RISCV_EXCP_NONE;
251
env->load_res = -1;
252
set_default_nan_mode(1, &env->fp_status);
253
@@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = {
254
MISA_EXT_INFO(RVS, "s", "Supervisor-level instructions"),
255
MISA_EXT_INFO(RVU, "u", "User-level instructions"),
256
MISA_EXT_INFO(RVH, "h", "Hypervisor"),
257
- MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"),
258
MISA_EXT_INFO(RVV, "v", "Vector operations"),
259
MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"),
260
MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)")
261
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
262
index XXXXXXX..XXXXXXX 100644
263
--- a/target/riscv/cpu_helper.c
264
+++ b/target/riscv/cpu_helper.c
265
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
266
flags = FIELD_DP32(flags, TB_FLAGS, VS, vs);
267
flags = FIELD_DP32(flags, TB_FLAGS, XL, env->xl);
268
flags = FIELD_DP32(flags, TB_FLAGS, AXL, cpu_address_xl(env));
269
- if (env->cur_pmmask != 0) {
270
- flags = FIELD_DP32(flags, TB_FLAGS, PM_MASK_ENABLED, 1);
271
- }
272
- if (env->cur_pmbase != 0) {
273
- flags = FIELD_DP32(flags, TB_FLAGS, PM_BASE_ENABLED, 1);
274
- }
275
276
*pflags = flags;
277
}
278
279
-void riscv_cpu_update_mask(CPURISCVState *env)
280
-{
281
- target_ulong mask = 0, base = 0;
282
- RISCVMXL xl = env->xl;
283
- /*
284
- * TODO: Current RVJ spec does not specify
285
- * how the extension interacts with XLEN.
286
- */
287
-#ifndef CONFIG_USER_ONLY
288
- int mode = cpu_address_mode(env);
289
- xl = cpu_get_xl(env, mode);
290
- if (riscv_has_ext(env, RVJ)) {
291
- switch (mode) {
292
- case PRV_M:
293
- if (env->mmte & M_PM_ENABLE) {
294
- mask = env->mpmmask;
295
- base = env->mpmbase;
296
- }
297
- break;
298
- case PRV_S:
299
- if (env->mmte & S_PM_ENABLE) {
300
- mask = env->spmmask;
301
- base = env->spmbase;
302
- }
303
- break;
304
- case PRV_U:
305
- if (env->mmte & U_PM_ENABLE) {
306
- mask = env->upmmask;
307
- base = env->upmbase;
308
- }
309
- break;
310
- default:
311
- g_assert_not_reached();
312
- }
313
- }
314
-#endif
315
- if (xl == MXL_RV32) {
316
- env->cur_pmmask = mask & UINT32_MAX;
317
- env->cur_pmbase = base & UINT32_MAX;
318
- } else {
319
- env->cur_pmmask = mask;
320
- env->cur_pmbase = base;
321
- }
322
-}
323
-
324
#ifndef CONFIG_USER_ONLY
325
326
/*
327
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv, bool virt_en)
328
/* tlb_flush is unnecessary as mode is contained in mmu_idx */
329
env->priv = newpriv;
330
env->xl = cpu_recompute_xl(env);
331
- riscv_cpu_update_mask(env);
332
333
/*
334
* Clear the load reservation - otherwise a reservation placed in one
335
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
336
index XXXXXXX..XXXXXXX 100644
337
--- a/target/riscv/csr.c
338
+++ b/target/riscv/csr.c
339
@@ -XXX,XX +XXX,XX @@ static RISCVException hgatp(CPURISCVState *env, int csrno)
340
return hmode(env, csrno);
341
}
342
343
-/* Checks if PointerMasking registers could be accessed */
344
-static RISCVException pointer_masking(CPURISCVState *env, int csrno)
345
-{
346
- /* Check if j-ext is present */
347
- if (riscv_has_ext(env, RVJ)) {
348
- return RISCV_EXCP_NONE;
349
- }
350
- return RISCV_EXCP_ILLEGAL_INST;
351
-}
352
-
353
static RISCVException aia_hmode(CPURISCVState *env, int csrno)
354
{
355
if (!riscv_cpu_cfg(env)->ext_ssaia) {
356
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
357
env->xl = cpu_recompute_xl(env);
358
}
359
360
- riscv_cpu_update_mask(env);
361
return RISCV_EXCP_NONE;
362
}
363
364
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mcontext(CPURISCVState *env, int csrno,
365
return RISCV_EXCP_NONE;
366
}
367
368
-/*
369
- * Functions to access Pointer Masking feature registers
370
- * We have to check if current priv lvl could modify
371
- * csr in given mode
372
- */
373
-static bool check_pm_current_disabled(CPURISCVState *env, int csrno)
374
-{
375
- int csr_priv = get_field(csrno, 0x300);
376
- int pm_current;
377
-
378
- if (env->debugger) {
379
- return false;
380
- }
381
- /*
382
- * If priv lvls differ that means we're accessing csr from higher priv lvl,
383
- * so allow the access
384
- */
385
- if (env->priv != csr_priv) {
386
- return false;
387
- }
388
- switch (env->priv) {
389
- case PRV_M:
390
- pm_current = get_field(env->mmte, M_PM_CURRENT);
391
- break;
392
- case PRV_S:
393
- pm_current = get_field(env->mmte, S_PM_CURRENT);
394
- break;
395
- case PRV_U:
396
- pm_current = get_field(env->mmte, U_PM_CURRENT);
397
- break;
398
- default:
399
- g_assert_not_reached();
400
- }
401
- /* It's same priv lvl, so we allow to modify csr only if pm.current==1 */
402
- return !pm_current;
403
-}
404
-
405
-static RISCVException read_mmte(CPURISCVState *env, int csrno,
406
- target_ulong *val)
407
-{
408
- *val = env->mmte & MMTE_MASK;
409
- return RISCV_EXCP_NONE;
410
-}
411
-
412
-static RISCVException write_mmte(CPURISCVState *env, int csrno,
413
- target_ulong val)
414
-{
415
- uint64_t mstatus;
416
- target_ulong wpri_val = val & MMTE_MASK;
417
-
418
- if (val != wpri_val) {
419
- qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s"
420
- TARGET_FMT_lx "\n", "MMTE: WPRI violation written 0x",
421
- val, "vs expected 0x", wpri_val);
422
- }
423
- /* for machine mode pm.current is hardwired to 1 */
424
- wpri_val |= MMTE_M_PM_CURRENT;
425
-
426
- /* hardwiring pm.instruction bit to 0, since it's not supported yet */
427
- wpri_val &= ~(MMTE_M_PM_INSN | MMTE_S_PM_INSN | MMTE_U_PM_INSN);
428
- env->mmte = wpri_val | EXT_STATUS_DIRTY;
429
- riscv_cpu_update_mask(env);
430
-
431
- /* Set XS and SD bits, since PM CSRs are dirty */
432
- mstatus = env->mstatus | MSTATUS_XS;
433
- write_mstatus(env, csrno, mstatus);
434
- return RISCV_EXCP_NONE;
435
-}
436
-
437
-static RISCVException read_smte(CPURISCVState *env, int csrno,
438
- target_ulong *val)
439
-{
440
- *val = env->mmte & SMTE_MASK;
441
- return RISCV_EXCP_NONE;
442
-}
443
-
444
-static RISCVException write_smte(CPURISCVState *env, int csrno,
445
- target_ulong val)
446
-{
447
- target_ulong wpri_val = val & SMTE_MASK;
448
-
449
- if (val != wpri_val) {
450
- qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s"
451
- TARGET_FMT_lx "\n", "SMTE: WPRI violation written 0x",
452
- val, "vs expected 0x", wpri_val);
453
- }
454
-
455
- /* if pm.current==0 we can't modify current PM CSRs */
456
- if (check_pm_current_disabled(env, csrno)) {
457
- return RISCV_EXCP_NONE;
458
- }
459
-
460
- wpri_val |= (env->mmte & ~SMTE_MASK);
461
- write_mmte(env, csrno, wpri_val);
462
- return RISCV_EXCP_NONE;
463
-}
464
-
465
-static RISCVException read_umte(CPURISCVState *env, int csrno,
466
- target_ulong *val)
467
-{
468
- *val = env->mmte & UMTE_MASK;
469
- return RISCV_EXCP_NONE;
470
-}
471
-
472
-static RISCVException write_umte(CPURISCVState *env, int csrno,
473
- target_ulong val)
474
-{
475
- target_ulong wpri_val = val & UMTE_MASK;
476
-
477
- if (val != wpri_val) {
478
- qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s"
479
- TARGET_FMT_lx "\n", "UMTE: WPRI violation written 0x",
480
- val, "vs expected 0x", wpri_val);
481
- }
482
-
483
- if (check_pm_current_disabled(env, csrno)) {
484
- return RISCV_EXCP_NONE;
485
- }
486
-
487
- wpri_val |= (env->mmte & ~UMTE_MASK);
488
- write_mmte(env, csrno, wpri_val);
489
- return RISCV_EXCP_NONE;
490
-}
491
-
492
-static RISCVException read_mpmmask(CPURISCVState *env, int csrno,
493
- target_ulong *val)
494
-{
495
- *val = env->mpmmask;
496
- return RISCV_EXCP_NONE;
497
-}
498
-
499
-static RISCVException write_mpmmask(CPURISCVState *env, int csrno,
500
- target_ulong val)
501
-{
502
- uint64_t mstatus;
503
-
504
- env->mpmmask = val;
505
- if ((cpu_address_mode(env) == PRV_M) && (env->mmte & M_PM_ENABLE)) {
506
- env->cur_pmmask = val;
507
- }
508
- env->mmte |= EXT_STATUS_DIRTY;
509
-
510
- /* Set XS and SD bits, since PM CSRs are dirty */
511
- mstatus = env->mstatus | MSTATUS_XS;
512
- write_mstatus(env, csrno, mstatus);
513
- return RISCV_EXCP_NONE;
514
-}
515
-
516
-static RISCVException read_spmmask(CPURISCVState *env, int csrno,
517
- target_ulong *val)
518
-{
519
- *val = env->spmmask;
520
- return RISCV_EXCP_NONE;
521
-}
522
-
523
-static RISCVException write_spmmask(CPURISCVState *env, int csrno,
524
- target_ulong val)
525
-{
526
- uint64_t mstatus;
527
-
528
- /* if pm.current==0 we can't modify current PM CSRs */
529
- if (check_pm_current_disabled(env, csrno)) {
530
- return RISCV_EXCP_NONE;
531
- }
532
- env->spmmask = val;
533
- if ((cpu_address_mode(env) == PRV_S) && (env->mmte & S_PM_ENABLE)) {
534
- env->cur_pmmask = val;
535
- if (cpu_get_xl(env, PRV_S) == MXL_RV32) {
536
- env->cur_pmmask &= UINT32_MAX;
537
- }
538
- }
539
- env->mmte |= EXT_STATUS_DIRTY;
540
-
541
- /* Set XS and SD bits, since PM CSRs are dirty */
542
- mstatus = env->mstatus | MSTATUS_XS;
543
- write_mstatus(env, csrno, mstatus);
544
- return RISCV_EXCP_NONE;
545
-}
546
-
547
-static RISCVException read_upmmask(CPURISCVState *env, int csrno,
548
- target_ulong *val)
549
-{
550
- *val = env->upmmask;
551
- return RISCV_EXCP_NONE;
552
-}
553
-
554
-static RISCVException write_upmmask(CPURISCVState *env, int csrno,
555
- target_ulong val)
556
-{
557
- uint64_t mstatus;
558
-
559
- /* if pm.current==0 we can't modify current PM CSRs */
560
- if (check_pm_current_disabled(env, csrno)) {
561
- return RISCV_EXCP_NONE;
562
- }
563
- env->upmmask = val;
564
- if ((cpu_address_mode(env) == PRV_U) && (env->mmte & U_PM_ENABLE)) {
565
- env->cur_pmmask = val;
566
- if (cpu_get_xl(env, PRV_U) == MXL_RV32) {
567
- env->cur_pmmask &= UINT32_MAX;
568
- }
569
- }
570
- env->mmte |= EXT_STATUS_DIRTY;
571
-
572
- /* Set XS and SD bits, since PM CSRs are dirty */
573
- mstatus = env->mstatus | MSTATUS_XS;
574
- write_mstatus(env, csrno, mstatus);
575
- return RISCV_EXCP_NONE;
576
-}
577
-
578
-static RISCVException read_mpmbase(CPURISCVState *env, int csrno,
579
- target_ulong *val)
580
-{
581
- *val = env->mpmbase;
582
- return RISCV_EXCP_NONE;
583
-}
584
-
585
-static RISCVException write_mpmbase(CPURISCVState *env, int csrno,
586
- target_ulong val)
587
-{
588
- uint64_t mstatus;
589
-
590
- env->mpmbase = val;
591
- if ((cpu_address_mode(env) == PRV_M) && (env->mmte & M_PM_ENABLE)) {
592
- env->cur_pmbase = val;
593
- }
594
- env->mmte |= EXT_STATUS_DIRTY;
595
-
596
- /* Set XS and SD bits, since PM CSRs are dirty */
597
- mstatus = env->mstatus | MSTATUS_XS;
598
- write_mstatus(env, csrno, mstatus);
599
- return RISCV_EXCP_NONE;
600
-}
601
-
602
-static RISCVException read_spmbase(CPURISCVState *env, int csrno,
603
- target_ulong *val)
604
-{
605
- *val = env->spmbase;
606
- return RISCV_EXCP_NONE;
607
-}
608
-
609
-static RISCVException write_spmbase(CPURISCVState *env, int csrno,
610
- target_ulong val)
611
-{
612
- uint64_t mstatus;
613
-
614
- /* if pm.current==0 we can't modify current PM CSRs */
615
- if (check_pm_current_disabled(env, csrno)) {
616
- return RISCV_EXCP_NONE;
617
- }
618
- env->spmbase = val;
619
- if ((cpu_address_mode(env) == PRV_S) && (env->mmte & S_PM_ENABLE)) {
620
- env->cur_pmbase = val;
621
- if (cpu_get_xl(env, PRV_S) == MXL_RV32) {
622
- env->cur_pmbase &= UINT32_MAX;
623
- }
624
- }
625
- env->mmte |= EXT_STATUS_DIRTY;
626
-
627
- /* Set XS and SD bits, since PM CSRs are dirty */
628
- mstatus = env->mstatus | MSTATUS_XS;
629
- write_mstatus(env, csrno, mstatus);
630
- return RISCV_EXCP_NONE;
631
-}
632
-
633
-static RISCVException read_upmbase(CPURISCVState *env, int csrno,
634
- target_ulong *val)
635
-{
636
- *val = env->upmbase;
637
- return RISCV_EXCP_NONE;
638
-}
639
-
640
-static RISCVException write_upmbase(CPURISCVState *env, int csrno,
641
- target_ulong val)
642
-{
643
- uint64_t mstatus;
644
-
645
- /* if pm.current==0 we can't modify current PM CSRs */
646
- if (check_pm_current_disabled(env, csrno)) {
647
- return RISCV_EXCP_NONE;
648
- }
649
- env->upmbase = val;
650
- if ((cpu_address_mode(env) == PRV_U) && (env->mmte & U_PM_ENABLE)) {
651
- env->cur_pmbase = val;
652
- if (cpu_get_xl(env, PRV_U) == MXL_RV32) {
653
- env->cur_pmbase &= UINT32_MAX;
654
- }
655
- }
656
- env->mmte |= EXT_STATUS_DIRTY;
657
-
658
- /* Set XS and SD bits, since PM CSRs are dirty */
659
- mstatus = env->mstatus | MSTATUS_XS;
660
- write_mstatus(env, csrno, mstatus);
661
- return RISCV_EXCP_NONE;
662
-}
663
-
664
#endif
665
666
/* Crypto Extension */
667
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
668
[CSR_TINFO] = { "tinfo", debug, read_tinfo, write_ignore },
669
[CSR_MCONTEXT] = { "mcontext", debug, read_mcontext, write_mcontext },
670
671
- /* User Pointer Masking */
672
- [CSR_UMTE] = { "umte", pointer_masking, read_umte, write_umte },
673
- [CSR_UPMMASK] = { "upmmask", pointer_masking, read_upmmask,
674
- write_upmmask },
675
- [CSR_UPMBASE] = { "upmbase", pointer_masking, read_upmbase,
676
- write_upmbase },
677
- /* Machine Pointer Masking */
678
- [CSR_MMTE] = { "mmte", pointer_masking, read_mmte, write_mmte },
679
- [CSR_MPMMASK] = { "mpmmask", pointer_masking, read_mpmmask,
680
- write_mpmmask },
681
- [CSR_MPMBASE] = { "mpmbase", pointer_masking, read_mpmbase,
682
- write_mpmbase },
683
- /* Supervisor Pointer Masking */
684
- [CSR_SMTE] = { "smte", pointer_masking, read_smte, write_smte },
685
- [CSR_SPMMASK] = { "spmmask", pointer_masking, read_spmmask,
686
- write_spmmask },
687
- [CSR_SPMBASE] = { "spmbase", pointer_masking, read_spmbase,
688
- write_spmbase },
689
-
690
/* Performance Counters */
691
[CSR_HPMCOUNTER3] = { "hpmcounter3", ctr, read_hpmcounter },
692
[CSR_HPMCOUNTER4] = { "hpmcounter4", ctr, read_hpmcounter },
693
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
694
index XXXXXXX..XXXXXXX 100644
695
--- a/target/riscv/machine.c
696
+++ b/target/riscv/machine.c
697
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_vector = {
698
699
static bool pointermasking_needed(void *opaque)
700
{
701
- RISCVCPU *cpu = opaque;
702
- CPURISCVState *env = &cpu->env;
703
-
704
- return riscv_has_ext(env, RVJ);
705
+ return false;
706
}
707
708
static const VMStateDescription vmstate_pointermasking = {
709
.name = "cpu/pointer_masking",
710
- .version_id = 1,
711
- .minimum_version_id = 1,
712
+ .version_id = 2,
713
+ .minimum_version_id = 2,
714
.needed = pointermasking_needed,
715
.fields = (const VMStateField[]) {
716
- VMSTATE_UINTTL(env.mmte, RISCVCPU),
717
- VMSTATE_UINTTL(env.mpmmask, RISCVCPU),
718
- VMSTATE_UINTTL(env.mpmbase, RISCVCPU),
719
- VMSTATE_UINTTL(env.spmmask, RISCVCPU),
720
- VMSTATE_UINTTL(env.spmbase, RISCVCPU),
721
- VMSTATE_UINTTL(env.upmmask, RISCVCPU),
722
- VMSTATE_UINTTL(env.upmbase, RISCVCPU),
723
724
VMSTATE_END_OF_LIST()
725
}
726
@@ -XXX,XX +XXX,XX @@ static int riscv_cpu_post_load(void *opaque, int version_id)
727
CPURISCVState *env = &cpu->env;
728
729
env->xl = cpu_recompute_xl(env);
730
- riscv_cpu_update_mask(env);
731
return 0;
732
}
733
45
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
734
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
46
index XXXXXXX..XXXXXXX 100644
735
index XXXXXXX..XXXXXXX 100644
47
--- a/target/riscv/tcg/tcg-cpu.c
736
--- a/target/riscv/tcg/tcg-cpu.c
48
+++ b/target/riscv/tcg/tcg-cpu.c
737
+++ b/target/riscv/tcg/tcg-cpu.c
49
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
738
@@ -XXX,XX +XXX,XX @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
50
riscv_cpu_disable_priv_spec_isa_exts(cpu);
739
MISA_CFG(RVS, true),
51
}
740
MISA_CFG(RVU, true),
52
741
MISA_CFG(RVH, true),
53
+#ifndef CONFIG_USER_ONLY
742
- MISA_CFG(RVJ, false),
54
+static bool riscv_cpu_validate_profile_satp(RISCVCPU *cpu,
743
MISA_CFG(RVV, false),
55
+ RISCVCPUProfile *profile,
744
MISA_CFG(RVG, false),
56
+ bool send_warn)
745
MISA_CFG(RVB, false),
57
+{
746
@@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj)
58
+ int satp_max = satp_mode_max_from_map(cpu->cfg.satp_mode.supported);
747
CPURISCVState *env = &cpu->env;
748
const RISCVCPUMultiExtConfig *prop;
749
750
- /* Enable RVG, RVJ and RVV that are disabled by default */
751
- riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV);
752
+ /* Enable RVG and RVV that are disabled by default */
753
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVV);
754
755
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
756
isa_ext_update_enabled(cpu, prop->offset, true);
757
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
758
index XXXXXXX..XXXXXXX 100644
759
--- a/target/riscv/translate.c
760
+++ b/target/riscv/translate.c
761
@@ -XXX,XX +XXX,XX @@ static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart;
762
static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */
763
static TCGv load_res;
764
static TCGv load_val;
765
-/* globals for PM CSRs */
766
-static TCGv pm_mask;
767
-static TCGv pm_base;
768
769
/*
770
* If an operation is being performed on less than TARGET_LONG_BITS,
771
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
772
bool vl_eq_vlmax;
773
CPUState *cs;
774
TCGv zero;
775
- /* PointerMasking extension */
776
- bool pm_mask_enabled;
777
- bool pm_base_enabled;
778
/* Ztso */
779
bool ztso;
780
/* Use icount trigger for native debug */
781
@@ -XXX,XX +XXX,XX @@ static TCGv get_address(DisasContext *ctx, int rs1, int imm)
782
TCGv src1 = get_gpr(ctx, rs1, EXT_NONE);
783
784
tcg_gen_addi_tl(addr, src1, imm);
785
- if (ctx->pm_mask_enabled) {
786
- tcg_gen_andc_tl(addr, addr, pm_mask);
787
- } else if (get_address_xl(ctx) == MXL_RV32) {
788
+ if (get_address_xl(ctx) == MXL_RV32) {
789
tcg_gen_ext32u_tl(addr, addr);
790
}
791
- if (ctx->pm_base_enabled) {
792
- tcg_gen_or_tl(addr, addr, pm_base);
793
- }
794
795
return addr;
796
}
797
@@ -XXX,XX +XXX,XX @@ static TCGv get_address_indexed(DisasContext *ctx, int rs1, TCGv offs)
798
TCGv src1 = get_gpr(ctx, rs1, EXT_NONE);
799
800
tcg_gen_add_tl(addr, src1, offs);
801
- if (ctx->pm_mask_enabled) {
802
- tcg_gen_andc_tl(addr, addr, pm_mask);
803
- } else if (get_xl(ctx) == MXL_RV32) {
804
+ if (get_xl(ctx) == MXL_RV32) {
805
tcg_gen_ext32u_tl(addr, addr);
806
}
807
- if (ctx->pm_base_enabled) {
808
- tcg_gen_or_tl(addr, addr, pm_base);
809
- }
59
+
810
+
60
+ if (profile->satp_mode > satp_max) {
811
return addr;
61
+ if (send_warn) {
812
}
62
+ bool is_32bit = riscv_cpu_is_32bit(cpu);
813
63
+ const char *req_satp = satp_mode_str(profile->satp_mode, is_32bit);
814
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
64
+ const char *cur_satp = satp_mode_str(satp_max, is_32bit);
815
ctx->xl = FIELD_EX32(tb_flags, TB_FLAGS, XL);
65
+
816
ctx->address_xl = FIELD_EX32(tb_flags, TB_FLAGS, AXL);
66
+ warn_report("Profile %s requires satp mode %s, "
817
ctx->cs = cs;
67
+ "but satp mode %s was set", profile->name,
818
- ctx->pm_mask_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_MASK_ENABLED);
68
+ req_satp, cur_satp);
819
- ctx->pm_base_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLED);
69
+ }
820
ctx->ztso = cpu->cfg.ext_ztso;
70
+
821
ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER);
71
+ return false;
822
ctx->bcfi_enabled = FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED);
72
+ }
823
@@ -XXX,XX +XXX,XX @@ void riscv_translate_init(void)
73
+
824
"load_res");
74
+ return true;
825
load_val = tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, load_val),
75
+}
826
"load_val");
76
+#endif
827
- /* Assign PM CSRs to tcg globals */
77
+
828
- pm_mask = tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, cur_pmmask),
78
static void riscv_cpu_validate_profile(RISCVCPU *cpu,
829
- "pmmask");
79
RISCVCPUProfile *profile)
830
- pm_base = tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, cur_pmbase),
831
- "pmbase");
832
}
833
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
834
index XXXXXXX..XXXXXXX 100644
835
--- a/target/riscv/vector_helper.c
836
+++ b/target/riscv/vector_helper.c
837
@@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_max_elems(uint32_t desc, uint32_t log2_esz)
838
839
static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong addr)
80
{
840
{
81
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_profile(RISCVCPU *cpu,
841
- return (addr & ~env->cur_pmmask) | env->cur_pmbase;
82
bool profile_impl = true;
842
+ return addr;
83
int i;
843
}
84
844
85
+#ifndef CONFIG_USER_ONLY
845
/*
86
+ if (profile->satp_mode != RISCV_PROFILE_ATTR_UNUSED) {
87
+ profile_impl = riscv_cpu_validate_profile_satp(cpu, profile,
88
+ send_warn);
89
+ }
90
+#endif
91
+
92
if (profile->priv_spec != RISCV_PROFILE_ATTR_UNUSED &&
93
profile->priv_spec != env->priv_ver) {
94
profile_impl = false;
95
@@ -XXX,XX +XXX,XX @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
96
cpu->env.priv_ver = profile->priv_spec;
97
}
98
99
+#ifndef CONFIG_USER_ONLY
100
+ if (profile->satp_mode != RISCV_PROFILE_ATTR_UNUSED) {
101
+ const char *satp_prop = satp_mode_str(profile->satp_mode,
102
+ riscv_cpu_is_32bit(cpu));
103
+ object_property_set_bool(obj, satp_prop, profile->enabled, NULL);
104
+ }
105
+#endif
106
+
107
for (i = 0; misa_bits[i] != 0; i++) {
108
uint32_t bit = misa_bits[i];
109
110
--
846
--
111
2.43.0
847
2.48.1
diff view generated by jsdifflib
1
From: Ivan Klokov <ivan.klokov@syntacore.com>
1
From: Alexey Baturo <baturo.alexey@gmail.com>
2
2
3
The Sv32 page-based virtual-memory scheme described in RISCV privileged
3
Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
4
spec Section 5.3 supports 34-bit physical addresses for RV32, so the
4
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
5
PMP scheme must support addresses wider than XLEN for RV32. However,
6
PMP address register format is still 32 bit wide.
7
8
Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-ID: <20231123091214.20312-1-ivan.klokov@syntacore.com>
6
Message-ID: <20250106102346.1100149-3-baturo.alexey@gmail.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
8
---
13
target/riscv/pmp.h | 8 ++++----
9
target/riscv/cpu.h | 8 ++++++++
14
target/riscv/pmp.c | 26 ++++++++++++--------------
10
target/riscv/cpu_bits.h | 4 ++++
15
2 files changed, 16 insertions(+), 18 deletions(-)
11
target/riscv/cpu_cfg.h | 3 +++
12
target/riscv/pmp.h | 1 +
13
target/riscv/csr.c | 33 +++++++++++++++++++++++++++++++--
14
target/riscv/pmp.c | 14 +++++++++++---
15
6 files changed, 58 insertions(+), 5 deletions(-)
16
16
17
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/cpu.h
20
+++ b/target/riscv/cpu.h
21
@@ -XXX,XX +XXX,XX @@ typedef enum {
22
EXT_STATUS_DIRTY,
23
} RISCVExtStatus;
24
25
+/* Enum holds PMM field values for Zjpm v1.0 extension */
26
+typedef enum {
27
+ PMM_FIELD_DISABLED = 0,
28
+ PMM_FIELD_RESERVED = 1,
29
+ PMM_FIELD_PMLEN7 = 2,
30
+ PMM_FIELD_PMLEN16 = 3,
31
+} RISCVPmPmm;
32
+
33
typedef struct riscv_cpu_implied_exts_rule {
34
#ifndef CONFIG_USER_ONLY
35
/*
36
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/cpu_bits.h
39
+++ b/target/riscv/cpu_bits.h
40
@@ -XXX,XX +XXX,XX @@ typedef enum {
41
#define HSTATUS_VTSR 0x00400000
42
#define HSTATUS_HUKTE 0x01000000
43
#define HSTATUS_VSXL 0x300000000
44
+#define HSTATUS_HUPMM 0x3000000000000
45
46
#define HSTATUS32_WPRI 0xFF8FF87E
47
#define HSTATUS64_WPRI 0xFFFFFFFFFF8FF87EULL
48
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
49
#define MENVCFG_CBIE (3UL << 4)
50
#define MENVCFG_CBCFE BIT(6)
51
#define MENVCFG_CBZE BIT(7)
52
+#define MENVCFG_PMM (3ULL << 32)
53
#define MENVCFG_ADUE (1ULL << 61)
54
#define MENVCFG_PBMTE (1ULL << 62)
55
#define MENVCFG_STCE (1ULL << 63)
56
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
57
#define SENVCFG_CBCFE MENVCFG_CBCFE
58
#define SENVCFG_CBZE MENVCFG_CBZE
59
#define SENVCFG_UKTE BIT(8)
60
+#define SENVCFG_PMM MENVCFG_PMM
61
62
#define HENVCFG_FIOM MENVCFG_FIOM
63
#define HENVCFG_LPE MENVCFG_LPE
64
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
65
#define HENVCFG_CBIE MENVCFG_CBIE
66
#define HENVCFG_CBCFE MENVCFG_CBCFE
67
#define HENVCFG_CBZE MENVCFG_CBZE
68
+#define HENVCFG_PMM MENVCFG_PMM
69
#define HENVCFG_ADUE MENVCFG_ADUE
70
#define HENVCFG_PBMTE MENVCFG_PBMTE
71
#define HENVCFG_STCE MENVCFG_STCE
72
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
73
index XXXXXXX..XXXXXXX 100644
74
--- a/target/riscv/cpu_cfg.h
75
+++ b/target/riscv/cpu_cfg.h
76
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
77
bool ext_ssaia;
78
bool ext_sscofpmf;
79
bool ext_smepmp;
80
+ bool ext_ssnpm;
81
+ bool ext_smnpm;
82
+ bool ext_smmpm;
83
bool rvv_ta_all_1s;
84
bool rvv_ma_all_1s;
85
bool rvv_vl_half_avl;
17
diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
86
diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
18
index XXXXXXX..XXXXXXX 100644
87
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/pmp.h
88
--- a/target/riscv/pmp.h
20
+++ b/target/riscv/pmp.h
89
+++ b/target/riscv/pmp.h
21
@@ -XXX,XX +XXX,XX @@ typedef struct {
90
@@ -XXX,XX +XXX,XX @@ typedef enum {
22
} pmp_entry_t;
91
MSECCFG_USEED = 1 << 8,
92
MSECCFG_SSEED = 1 << 9,
93
MSECCFG_MLPE = 1 << 10,
94
+ MSECCFG_PMM = 3ULL << 32,
95
} mseccfg_field_t;
23
96
24
typedef struct {
97
typedef struct {
25
- target_ulong sa;
98
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
26
- target_ulong ea;
99
index XXXXXXX..XXXXXXX 100644
27
+ hwaddr sa;
100
--- a/target/riscv/csr.c
28
+ hwaddr ea;
101
+++ b/target/riscv/csr.c
29
} pmp_addr_t;
102
@@ -XXX,XX +XXX,XX @@ static RISCVException have_mseccfg(CPURISCVState *env, int csrno)
30
103
if (riscv_cpu_cfg(env)->ext_zkr) {
31
typedef struct {
104
return RISCV_EXCP_NONE;
32
@@ -XXX,XX +XXX,XX @@ target_ulong mseccfg_csr_read(CPURISCVState *env);
105
}
33
void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
106
+ if (riscv_cpu_cfg(env)->ext_smmpm) {
34
target_ulong val);
107
+ return RISCV_EXCP_NONE;
35
target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index);
108
+ }
36
-bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
109
37
+bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr,
110
return RISCV_EXCP_ILLEGAL_INST;
38
target_ulong size, pmp_priv_t privs,
111
}
39
pmp_priv_t *allowed_privs,
112
@@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
40
target_ulong mode);
113
if (env_archcpu(env)->cfg.ext_zicfiss) {
41
-target_ulong pmp_get_tlb_size(CPURISCVState *env, target_ulong addr);
114
mask |= MENVCFG_SSE;
42
+target_ulong pmp_get_tlb_size(CPURISCVState *env, hwaddr addr);
115
}
43
void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index);
116
+
44
void pmp_update_rule_nums(CPURISCVState *env);
117
+ /* Update PMM field only if the value is valid according to Zjpm v1.0 */
45
uint32_t pmp_get_num_rules(CPURISCVState *env);
118
+ if (env_archcpu(env)->cfg.ext_smnpm &&
119
+ get_field(val, MENVCFG_PMM) != PMM_FIELD_RESERVED) {
120
+ mask |= MENVCFG_PMM;
121
+ }
122
}
123
env->menvcfg = (env->menvcfg & ~mask) | (val & mask);
124
125
@@ -XXX,XX +XXX,XX @@ static RISCVException write_senvcfg(CPURISCVState *env, int csrno,
126
{
127
uint64_t mask = SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCFG_CBZE;
128
RISCVException ret;
129
+ /* Update PMM field only if the value is valid according to Zjpm v1.0 */
130
+ if (env_archcpu(env)->cfg.ext_ssnpm &&
131
+ riscv_cpu_mxl(env) == MXL_RV64 &&
132
+ get_field(val, SENVCFG_PMM) != PMM_FIELD_RESERVED) {
133
+ mask |= SENVCFG_PMM;
134
+ }
135
136
ret = smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG);
137
if (ret != RISCV_EXCP_NONE) {
138
@@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno,
139
get_field(env->menvcfg, MENVCFG_SSE)) {
140
mask |= HENVCFG_SSE;
141
}
142
+
143
+ /* Update PMM field only if the value is valid according to Zjpm v1.0 */
144
+ if (env_archcpu(env)->cfg.ext_ssnpm &&
145
+ get_field(val, HENVCFG_PMM) != PMM_FIELD_RESERVED) {
146
+ mask |= HENVCFG_PMM;
147
+ }
148
}
149
150
env->henvcfg = (env->henvcfg & ~mask) | (val & mask);
151
@@ -XXX,XX +XXX,XX @@ static RISCVException read_hstatus(CPURISCVState *env, int csrno,
152
static RISCVException write_hstatus(CPURISCVState *env, int csrno,
153
target_ulong val)
154
{
155
+ uint64_t mask = (target_ulong)-1;
156
if (!env_archcpu(env)->cfg.ext_svukte) {
157
- val = val & (~HSTATUS_HUKTE);
158
+ mask &= ~HSTATUS_HUKTE;
159
}
160
- env->hstatus = val;
161
+ /* Update PMM field only if the value is valid according to Zjpm v1.0 */
162
+ if (!env_archcpu(env)->cfg.ext_ssnpm ||
163
+ riscv_cpu_mxl(env) != MXL_RV64 ||
164
+ get_field(val, HSTATUS_HUPMM) == PMM_FIELD_RESERVED) {
165
+ mask &= ~HSTATUS_HUPMM;
166
+ }
167
+ env->hstatus = (env->hstatus & ~mask) | (val & mask);
168
+
169
if (riscv_cpu_mxl(env) != MXL_RV32 && get_field(val, HSTATUS_VSXL) != 2) {
170
qemu_log_mask(LOG_UNIMP,
171
"QEMU does not support mixed HSXLEN options.");
46
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
172
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
47
index XXXXXXX..XXXXXXX 100644
173
index XXXXXXX..XXXXXXX 100644
48
--- a/target/riscv/pmp.c
174
--- a/target/riscv/pmp.c
49
+++ b/target/riscv/pmp.c
175
+++ b/target/riscv/pmp.c
50
@@ -XXX,XX +XXX,XX @@ void pmp_unlock_entries(CPURISCVState *env)
176
@@ -XXX,XX +XXX,XX @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index)
51
}
177
void mseccfg_csr_write(CPURISCVState *env, target_ulong val)
52
}
53
54
-static void pmp_decode_napot(target_ulong a, target_ulong *sa,
55
- target_ulong *ea)
56
+static void pmp_decode_napot(hwaddr a, hwaddr *sa, hwaddr *ea)
57
{
178
{
58
/*
59
* aaaa...aaa0 8-byte NAPOT range
60
@@ -XXX,XX +XXX,XX @@ void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index)
61
uint8_t this_cfg = env->pmp_state.pmp[pmp_index].cfg_reg;
62
target_ulong this_addr = env->pmp_state.pmp[pmp_index].addr_reg;
63
target_ulong prev_addr = 0u;
64
- target_ulong sa = 0u;
65
- target_ulong ea = 0u;
66
+ hwaddr sa = 0u;
67
+ hwaddr ea = 0u;
68
69
if (pmp_index >= 1u) {
70
prev_addr = env->pmp_state.pmp[pmp_index - 1].addr_reg;
71
@@ -XXX,XX +XXX,XX @@ void pmp_update_rule_nums(CPURISCVState *env)
72
}
73
}
74
75
-static int pmp_is_in_range(CPURISCVState *env, int pmp_index,
76
- target_ulong addr)
77
+static int pmp_is_in_range(CPURISCVState *env, int pmp_index, hwaddr addr)
78
{
79
int result = 0;
80
81
@@ -XXX,XX +XXX,XX @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, pmp_priv_t privs,
82
* Return true if a pmp rule match or default match
83
* Return false if no match
84
*/
85
-bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
86
+bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr,
87
target_ulong size, pmp_priv_t privs,
88
pmp_priv_t *allowed_privs, target_ulong mode)
89
{
90
int i = 0;
91
int pmp_size = 0;
92
- target_ulong s = 0;
93
- target_ulong e = 0;
94
+ hwaddr s = 0;
95
+ hwaddr e = 0;
96
97
/* Short cut if no rules */
98
if (0 == pmp_get_num_rules(env)) {
99
@@ -XXX,XX +XXX,XX @@ target_ulong mseccfg_csr_read(CPURISCVState *env)
100
* To avoid this we return a size of 1 (which means no caching) if the PMP
101
* region only covers partial of the TLB page.
102
*/
103
-target_ulong pmp_get_tlb_size(CPURISCVState *env, target_ulong addr)
104
+target_ulong pmp_get_tlb_size(CPURISCVState *env, hwaddr addr)
105
{
106
- target_ulong pmp_sa;
107
- target_ulong pmp_ea;
108
- target_ulong tlb_sa = addr & ~(TARGET_PAGE_SIZE - 1);
109
- target_ulong tlb_ea = tlb_sa + TARGET_PAGE_SIZE - 1;
110
+ hwaddr pmp_sa;
111
+ hwaddr pmp_ea;
112
+ hwaddr tlb_sa = addr & ~(TARGET_PAGE_SIZE - 1);
113
+ hwaddr tlb_ea = tlb_sa + TARGET_PAGE_SIZE - 1;
114
int i;
179
int i;
115
180
+ uint64_t mask = MSECCFG_MMWP | MSECCFG_MML;
116
/*
181
+ /* Update PMM field only if the value is valid according to Zjpm v1.0 */
182
+ if (riscv_cpu_cfg(env)->ext_smmpm &&
183
+ riscv_cpu_mxl(env) == MXL_RV64 &&
184
+ get_field(val, MSECCFG_PMM) != PMM_FIELD_RESERVED) {
185
+ mask |= MSECCFG_PMM;
186
+ }
187
188
trace_mseccfg_csr_write(env->mhartid, val);
189
190
@@ -XXX,XX +XXX,XX @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val)
191
192
if (riscv_cpu_cfg(env)->ext_smepmp) {
193
/* Sticky bits */
194
- val |= (env->mseccfg & (MSECCFG_MMWP | MSECCFG_MML));
195
- if ((val ^ env->mseccfg) & (MSECCFG_MMWP | MSECCFG_MML)) {
196
+ val |= (env->mseccfg & mask);
197
+ if ((val ^ env->mseccfg) & mask) {
198
tlb_flush(env_cpu(env));
199
}
200
} else {
201
- val &= ~(MSECCFG_MMWP | MSECCFG_MML | MSECCFG_RLB);
202
+ mask |= MSECCFG_RLB;
203
+ val &= ~(mask);
204
}
205
206
/* M-mode forward cfi to be enabled if cfi extension is implemented */
117
--
207
--
118
2.43.0
208
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Alexey Baturo <baturo.alexey@gmail.com>
2
2
3
Enabling a profile and then disabling some of its mandatory extensions
3
Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
4
is a valid use. It can be useful for debugging and testing. But the
4
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
5
common expected use of enabling a profile is to enable all its mandatory
6
extensions.
7
8
Add an user warning when mandatory extensions from an enabled profile
9
are disabled in the command line. We're also going to disable the
10
profile flag in this case since the profile must include all the
11
mandatory extensions. This flag can be exposed by QMP to indicate the
12
actual profile state after the CPU is realized.
13
14
After this patch, this will throw warnings:
15
16
-cpu rv64,rva22u64=true,zihintpause=false,zicbom=false,zicboz=false
17
18
qemu-system-riscv64: warning: Profile rva22u64 mandates disabled extension zihintpause
19
qemu-system-riscv64: warning: Profile rva22u64 mandates disabled extension zicbom
20
qemu-system-riscv64: warning: Profile rva22u64 mandates disabled extension zicboz
21
22
Note that the following will NOT throw warnings because the profile is
23
being enabled last, hence all its mandatory extensions will be enabled:
24
25
-cpu rv64,zihintpause=false,zicbom=false,zicboz=false,rva22u64=true
26
27
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
28
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
29
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
30
Message-ID: <20231218125334.37184-17-dbarboza@ventanamicro.com>
6
Message-ID: <20250106102346.1100149-4-baturo.alexey@gmail.com>
31
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
32
---
8
---
33
target/riscv/tcg/tcg-cpu.c | 69 ++++++++++++++++++++++++++++++++++++++
9
target/riscv/cpu.h | 5 +++
34
1 file changed, 69 insertions(+)
10
target/riscv/cpu_helper.c | 78 +++++++++++++++++++++++++++++++++++++++
11
2 files changed, 83 insertions(+)
35
12
36
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
13
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
37
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/tcg/tcg-cpu.c
15
--- a/target/riscv/cpu.h
39
+++ b/target/riscv/tcg/tcg-cpu.c
16
+++ b/target/riscv/cpu.h
40
@@ -XXX,XX +XXX,XX @@ static int cpu_cfg_ext_get_min_version(uint32_t ext_offset)
17
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
41
g_assert_not_reached();
18
19
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
20
21
+bool riscv_cpu_virt_mem_enabled(CPURISCVState *env);
22
+RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env);
23
+uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm);
24
+
25
RISCVException riscv_csrr(CPURISCVState *env, int csrno,
26
target_ulong *ret_value);
27
+
28
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
29
target_ulong *ret_value,
30
target_ulong new_value, target_ulong write_mask);
31
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu_helper.c
34
+++ b/target/riscv/cpu_helper.c
35
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
36
*pflags = flags;
42
}
37
}
43
38
44
+static const char *cpu_cfg_ext_get_name(uint32_t ext_offset)
39
+RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env)
45
+{
40
+{
46
+ const RISCVCPUMultiExtConfig *feat;
41
+#ifndef CONFIG_USER_ONLY
47
+ const RISCVIsaExtData *edata;
42
+ int priv_mode = cpu_address_mode(env);
48
+
43
+
49
+ for (edata = isa_edata_arr; edata->name != NULL; edata++) {
44
+ if (get_field(env->mstatus, MSTATUS_MPRV) &&
50
+ if (edata->ext_enable_offset == ext_offset) {
45
+ get_field(env->mstatus, MSTATUS_MXR)) {
51
+ return edata->name;
46
+ return PMM_FIELD_DISABLED;
52
+ }
53
+ }
47
+ }
54
+
48
+
55
+ for (feat = riscv_cpu_named_features; feat->name != NULL; feat++) {
49
+ /* Get current PMM field */
56
+ if (feat->offset == ext_offset) {
50
+ switch (priv_mode) {
57
+ return feat->name;
51
+ case PRV_M:
52
+ if (riscv_cpu_cfg(env)->ext_smmpm) {
53
+ return get_field(env->mseccfg, MSECCFG_PMM);
58
+ }
54
+ }
55
+ break;
56
+ case PRV_S:
57
+ if (riscv_cpu_cfg(env)->ext_smnpm) {
58
+ if (get_field(env->mstatus, MSTATUS_MPV)) {
59
+ return get_field(env->henvcfg, HENVCFG_PMM);
60
+ } else {
61
+ return get_field(env->menvcfg, MENVCFG_PMM);
62
+ }
63
+ }
64
+ break;
65
+ case PRV_U:
66
+ if (riscv_has_ext(env, RVS)) {
67
+ if (riscv_cpu_cfg(env)->ext_ssnpm) {
68
+ return get_field(env->senvcfg, SENVCFG_PMM);
69
+ }
70
+ } else {
71
+ if (riscv_cpu_cfg(env)->ext_smnpm) {
72
+ return get_field(env->menvcfg, MENVCFG_PMM);
73
+ }
74
+ }
75
+ break;
76
+ default:
77
+ g_assert_not_reached();
78
+ }
79
+ return PMM_FIELD_DISABLED;
80
+#else
81
+ return PMM_FIELD_DISABLED;
82
+#endif
83
+}
84
+
85
+bool riscv_cpu_virt_mem_enabled(CPURISCVState *env)
86
+{
87
+#ifndef CONFIG_USER_ONLY
88
+ int satp_mode = 0;
89
+ int priv_mode = cpu_address_mode(env);
90
+
91
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
92
+ satp_mode = get_field(env->satp, SATP32_MODE);
93
+ } else {
94
+ satp_mode = get_field(env->satp, SATP64_MODE);
59
+ }
95
+ }
60
+
96
+
61
+ g_assert_not_reached();
97
+ return ((satp_mode != VM_1_10_MBARE) && (priv_mode != PRV_M));
98
+#else
99
+ return false;
100
+#endif
62
+}
101
+}
63
+
102
+
64
static bool cpu_cfg_offset_is_named_feat(uint32_t ext_offset)
103
+uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm)
65
{
66
const RISCVCPUMultiExtConfig *feat;
67
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
68
riscv_cpu_disable_priv_spec_isa_exts(cpu);
69
}
70
71
+static void riscv_cpu_validate_profile(RISCVCPU *cpu,
72
+ RISCVCPUProfile *profile)
73
+{
104
+{
74
+ const char *warn_msg = "Profile %s mandates disabled extension %s";
105
+ switch (pmm) {
75
+ bool send_warn = profile->user_set && profile->enabled;
106
+ case PMM_FIELD_DISABLED:
76
+ bool profile_impl = true;
107
+ return 0;
77
+ int i;
108
+ case PMM_FIELD_PMLEN7:
78
+
109
+ return 7;
79
+ for (i = 0; misa_bits[i] != 0; i++) {
110
+ case PMM_FIELD_PMLEN16:
80
+ uint32_t bit = misa_bits[i];
111
+ return 16;
81
+
112
+ default:
82
+ if (!(profile->misa_ext & bit)) {
113
+ g_assert_not_reached();
83
+ continue;
84
+ }
85
+
86
+ if (!riscv_has_ext(&cpu->env, bit)) {
87
+ profile_impl = false;
88
+
89
+ if (send_warn) {
90
+ warn_report(warn_msg, profile->name,
91
+ riscv_get_misa_ext_name(bit));
92
+ }
93
+ }
94
+ }
95
+
96
+ for (i = 0; profile->ext_offsets[i] != RISCV_PROFILE_EXT_LIST_END; i++) {
97
+ int ext_offset = profile->ext_offsets[i];
98
+
99
+ if (!isa_ext_is_enabled(cpu, ext_offset)) {
100
+ profile_impl = false;
101
+
102
+ if (send_warn) {
103
+ warn_report(warn_msg, profile->name,
104
+ cpu_cfg_ext_get_name(ext_offset));
105
+ }
106
+ }
107
+ }
108
+
109
+ profile->enabled = profile_impl;
110
+}
111
+
112
+static void riscv_cpu_validate_profiles(RISCVCPU *cpu)
113
+{
114
+ for (int i = 0; riscv_profiles[i] != NULL; i++) {
115
+ riscv_cpu_validate_profile(cpu, riscv_profiles[i]);
116
+ }
114
+ }
117
+}
115
+}
118
+
116
+
119
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
117
#ifndef CONFIG_USER_ONLY
120
{
118
121
CPURISCVState *env = &cpu->env;
119
/*
122
@@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
123
}
124
125
riscv_cpu_update_named_features(cpu);
126
+ riscv_cpu_validate_profiles(cpu);
127
128
if (cpu->cfg.ext_smepmp && !cpu->cfg.pmp) {
129
/*
130
--
120
--
131
2.43.0
121
2.48.1
diff view generated by jsdifflib
1
From: Alistair Francis <alistair23@gmail.com>
1
From: Alexey Baturo <baturo.alexey@gmail.com>
2
2
3
We have been incorrectly adjusting both the interrupt and exception
3
Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
4
cause when using the hypervisor extension and trapping to VS-mode. This
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
patch changes the conditional to ensure we only adjust the cause for
5
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
6
interrupts and not exceptions.
6
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
7
7
Message-ID: <20250106102346.1100149-5-baturo.alexey@gmail.com>
8
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1708
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Message-ID: <20240108001328.280222-3-alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
9
---
14
target/riscv/cpu_helper.c | 4 ++--
10
target/riscv/cpu.h | 3 +++
15
1 file changed, 2 insertions(+), 2 deletions(-)
11
target/riscv/cpu_helper.c | 3 +++
12
target/riscv/translate.c | 5 +++++
13
3 files changed, 11 insertions(+)
16
14
15
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu.h
18
+++ b/target/riscv/cpu.h
19
@@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, FCFI_ENABLED, 26, 1)
20
FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 27, 1)
21
/* zicfiss needs a TB flag so that correct TB is located based on tb flags */
22
FIELD(TB_FLAGS, BCFI_ENABLED, 28, 1)
23
+/* If pointer masking should be applied and address sign extended */
24
+FIELD(TB_FLAGS, PM_PMM, 29, 2)
25
+FIELD(TB_FLAGS, PM_SIGNEXTEND, 31, 1)
26
27
#ifdef TARGET_RISCV32
28
#define riscv_cpu_mxl(env) ((void)(env), MXL_RV32)
17
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
29
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
18
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/cpu_helper.c
31
--- a/target/riscv/cpu_helper.c
20
+++ b/target/riscv/cpu_helper.c
32
+++ b/target/riscv/cpu_helper.c
21
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
33
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
22
* See if we need to adjust cause. Yes if its VS mode interrupt
34
RISCVCPU *cpu = env_archcpu(env);
23
* no if hypervisor has delegated one of hs mode's interrupt
35
RISCVExtStatus fs, vs;
24
*/
36
uint32_t flags = 0;
25
- if (cause == IRQ_VS_TIMER || cause == IRQ_VS_SOFT ||
37
+ bool pm_signext = riscv_cpu_virt_mem_enabled(env);
26
- cause == IRQ_VS_EXT) {
38
27
+ if (async && (cause == IRQ_VS_TIMER || cause == IRQ_VS_SOFT ||
39
*pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc;
28
+ cause == IRQ_VS_EXT)) {
40
*cs_base = 0;
29
cause = cause - 1;
41
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
30
}
42
flags = FIELD_DP32(flags, TB_FLAGS, VS, vs);
31
write_gva = false;
43
flags = FIELD_DP32(flags, TB_FLAGS, XL, env->xl);
44
flags = FIELD_DP32(flags, TB_FLAGS, AXL, cpu_address_xl(env));
45
+ flags = FIELD_DP32(flags, TB_FLAGS, PM_PMM, riscv_pm_get_pmm(env));
46
+ flags = FIELD_DP32(flags, TB_FLAGS, PM_SIGNEXTEND, pm_signext);
47
48
*pflags = flags;
49
}
50
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
51
index XXXXXXX..XXXXXXX 100644
52
--- a/target/riscv/translate.c
53
+++ b/target/riscv/translate.c
54
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
55
bool vl_eq_vlmax;
56
CPUState *cs;
57
TCGv zero;
58
+ /* actual address width */
59
+ uint8_t addr_xl;
60
+ bool addr_signed;
61
/* Ztso */
62
bool ztso;
63
/* Use icount trigger for native debug */
64
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
65
ctx->xl = FIELD_EX32(tb_flags, TB_FLAGS, XL);
66
ctx->address_xl = FIELD_EX32(tb_flags, TB_FLAGS, AXL);
67
ctx->cs = cs;
68
+ ctx->addr_xl = 0;
69
+ ctx->addr_signed = false;
70
ctx->ztso = cpu->cfg.ext_ztso;
71
ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER);
72
ctx->bcfi_enabled = FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED);
32
--
73
--
33
2.43.0
74
2.48.1
diff view generated by jsdifflib
1
From: Sunil V L <sunilvl@ventanamicro.com>
1
From: Alexey Baturo <baturo.alexey@gmail.com>
2
2
3
Add APLIC structures for each socket in the MADT when system is configured
3
Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
4
with APLIC as the external wired interrupt controller.
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
5
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
6
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
6
Message-ID: <20250106102346.1100149-6-baturo.alexey@gmail.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
10
Acked-by: Michael S. Tsirkin <mst@redhat.com>
11
Message-ID: <20231218150247.466427-8-sunilvl@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
8
---
14
hw/riscv/virt-acpi-build.c | 34 ++++++++++++++++++++++++++++++++++
9
target/riscv/translate.c | 22 ++++++++++++++++------
15
1 file changed, 34 insertions(+)
10
target/riscv/vector_helper.c | 16 ++++++++++++++++
11
2 files changed, 32 insertions(+), 6 deletions(-)
16
12
17
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
13
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
18
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/riscv/virt-acpi-build.c
15
--- a/target/riscv/translate.c
20
+++ b/hw/riscv/virt-acpi-build.c
16
+++ b/target/riscv/translate.c
21
@@ -XXX,XX +XXX,XX @@ static void build_madt(GArray *table_data,
17
@@ -XXX,XX +XXX,XX @@ static TCGv get_address(DisasContext *ctx, int rs1, int imm)
22
uint8_t guest_index_bits = imsic_num_bits(s->aia_guests + 1);
18
TCGv src1 = get_gpr(ctx, rs1, EXT_NONE);
23
uint16_t imsic_max_hart_per_socket = 0;
19
24
uint8_t hart_index_bits;
20
tcg_gen_addi_tl(addr, src1, imm);
25
+ uint64_t aplic_addr;
21
- if (get_address_xl(ctx) == MXL_RV32) {
26
+ uint32_t gsi_base;
22
- tcg_gen_ext32u_tl(addr, addr);
27
uint8_t socket;
23
+ if (ctx->addr_signed) {
28
24
+ tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl);
29
for (socket = 0; socket < riscv_socket_count(ms); socket++) {
25
+ } else {
30
@@ -XXX,XX +XXX,XX @@ static void build_madt(GArray *table_data,
26
+ tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl);
31
build_append_int_noprefix(table_data, IMSIC_MMIO_GROUP_MIN_SHIFT, 1);
32
}
27
}
33
28
34
+ if (s->aia_type != VIRT_AIA_TYPE_NONE) {
29
return addr;
35
+ /* APLICs */
30
@@ -XXX,XX +XXX,XX @@ static TCGv get_address_indexed(DisasContext *ctx, int rs1, TCGv offs)
36
+ for (socket = 0; socket < riscv_socket_count(ms); socket++) {
31
TCGv src1 = get_gpr(ctx, rs1, EXT_NONE);
37
+ aplic_addr = s->memmap[VIRT_APLIC_S].base +
32
38
+ s->memmap[VIRT_APLIC_S].size * socket;
33
tcg_gen_add_tl(addr, src1, offs);
39
+ gsi_base = VIRT_IRQCHIP_NUM_SOURCES * socket;
34
- if (get_xl(ctx) == MXL_RV32) {
40
+ build_append_int_noprefix(table_data, 0x1A, 1); /* Type */
35
- tcg_gen_ext32u_tl(addr, addr);
41
+ build_append_int_noprefix(table_data, 36, 1); /* Length */
36
+ if (ctx->addr_signed) {
42
+ build_append_int_noprefix(table_data, 1, 1); /* Version */
37
+ tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl);
43
+ build_append_int_noprefix(table_data, socket, 1); /* APLIC ID */
38
+ } else {
44
+ build_append_int_noprefix(table_data, 0, 4); /* Flags */
39
+ tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl);
45
+ build_append_int_noprefix(table_data, 0, 8); /* Hardware ID */
40
}
46
+ /* Number of IDCs */
41
47
+ if (s->aia_type == VIRT_AIA_TYPE_APLIC) {
42
return addr;
48
+ build_append_int_noprefix(table_data,
43
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
49
+ s->soc[socket].num_harts,
44
ctx->xl = FIELD_EX32(tb_flags, TB_FLAGS, XL);
50
+ 2);
45
ctx->address_xl = FIELD_EX32(tb_flags, TB_FLAGS, AXL);
51
+ } else {
46
ctx->cs = cs;
52
+ build_append_int_noprefix(table_data, 0, 2);
47
- ctx->addr_xl = 0;
53
+ }
48
- ctx->addr_signed = false;
54
+ /* Total External Interrupt Sources Supported */
49
+ if (get_xl(ctx) == MXL_RV32) {
55
+ build_append_int_noprefix(table_data, VIRT_IRQCHIP_NUM_SOURCES, 2);
50
+ ctx->addr_xl = 32;
56
+ /* Global System Interrupt Base */
51
+ ctx->addr_signed = false;
57
+ build_append_int_noprefix(table_data, gsi_base, 4);
52
+ } else {
58
+ /* APLIC Address */
53
+ int pm_pmm = FIELD_EX32(tb_flags, TB_FLAGS, PM_PMM);
59
+ build_append_int_noprefix(table_data, aplic_addr, 8);
54
+ ctx->addr_xl = 64 - riscv_pm_get_pmlen(pm_pmm);
60
+ /* APLIC size */
55
+ ctx->addr_signed = FIELD_EX32(tb_flags, TB_FLAGS, PM_SIGNEXTEND);
61
+ build_append_int_noprefix(table_data,
62
+ s->memmap[VIRT_APLIC_S].size, 4);
63
+ }
64
+ }
56
+ }
65
+
57
ctx->ztso = cpu->cfg.ext_ztso;
66
acpi_table_end(linker, &table);
58
ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER);
59
ctx->bcfi_enabled = FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED);
60
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
61
index XXXXXXX..XXXXXXX 100644
62
--- a/target/riscv/vector_helper.c
63
+++ b/target/riscv/vector_helper.c
64
@@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_max_elems(uint32_t desc, uint32_t log2_esz)
65
66
static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong addr)
67
{
68
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
69
+ return addr;
70
+ }
71
+ RISCVPmPmm pmm = riscv_pm_get_pmm(env);
72
+ if (pmm == PMM_FIELD_DISABLED) {
73
+ return addr;
74
+ }
75
+ int pmlen = riscv_pm_get_pmlen(pmm);
76
+ bool signext = riscv_cpu_virt_mem_enabled(env);
77
+ addr = addr << pmlen;
78
+ /* sign/zero extend masked address by N-1 bit */
79
+ if (signext) {
80
+ addr = (target_long)addr >> pmlen;
81
+ } else {
82
+ addr = addr >> pmlen;
83
+ }
84
return addr;
67
}
85
}
68
86
69
--
87
--
70
2.43.0
88
2.48.1
diff view generated by jsdifflib
1
From: Sunil V L <sunilvl@ventanamicro.com>
1
From: Alexey Baturo <baturo.alexey@gmail.com>
2
2
3
RISC-V also needs to use the same code to create fw_cfg in DSDT. So,
3
Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
4
avoid code duplication by moving the code in arm and riscv to a device
5
specific file.
6
7
Suggested-by: Igor Mammedov <imammedo@redhat.com>
8
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
9
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
4
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
6
Message-ID: <20250106102346.1100149-7-baturo.alexey@gmail.com>
12
Acked-by: Michael S. Tsirkin <mst@redhat.com>
13
Message-ID: <20231218150247.466427-2-sunilvl@ventanamicro.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
8
---
16
include/hw/nvram/fw_cfg_acpi.h | 15 +++++++++++++++
9
target/riscv/cpu.h | 1 +
17
hw/arm/virt-acpi-build.c | 19 ++-----------------
10
target/riscv/internals.h | 54 ++++++++++++++++++++++++++++++++++++
18
hw/nvram/fw_cfg-acpi.c | 23 +++++++++++++++++++++++
11
target/riscv/cpu_helper.c | 19 +++++++++++++
19
hw/riscv/virt-acpi-build.c | 19 ++-----------------
12
target/riscv/op_helper.c | 16 +++++------
20
hw/nvram/meson.build | 1 +
13
target/riscv/vector_helper.c | 21 --------------
21
5 files changed, 43 insertions(+), 34 deletions(-)
14
5 files changed, 82 insertions(+), 29 deletions(-)
22
create mode 100644 include/hw/nvram/fw_cfg_acpi.h
23
create mode 100644 hw/nvram/fw_cfg-acpi.c
24
15
25
diff --git a/include/hw/nvram/fw_cfg_acpi.h b/include/hw/nvram/fw_cfg_acpi.h
16
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
26
new file mode 100644
17
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX
18
--- a/target/riscv/cpu.h
28
--- /dev/null
19
+++ b/target/riscv/cpu.h
29
+++ b/include/hw/nvram/fw_cfg_acpi.h
20
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_is_32bit(RISCVCPU *cpu);
30
@@ -XXX,XX +XXX,XX @@
21
31
+/* SPDX-License-Identifier: GPL-2.0+ */
22
bool riscv_cpu_virt_mem_enabled(CPURISCVState *env);
32
+/*
23
RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env);
33
+ * ACPI support for fw_cfg
24
+RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env);
34
+ *
25
uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm);
35
+ */
26
36
+
27
RISCVException riscv_csrr(CPURISCVState *env, int csrno,
37
+#ifndef FW_CFG_ACPI_H
28
diff --git a/target/riscv/internals.h b/target/riscv/internals.h
38
+#define FW_CFG_ACPI_H
29
index XXXXXXX..XXXXXXX 100644
39
+
30
--- a/target/riscv/internals.h
40
+#include "qemu/osdep.h"
31
+++ b/target/riscv/internals.h
41
+#include "exec/hwaddr.h"
32
@@ -XXX,XX +XXX,XX @@ static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f)
42
+
33
/* Our implementation of CPUClass::has_work */
43
+void fw_cfg_acpi_dsdt_add(Aml *scope, const MemMapEntry *fw_cfg_memmap);
34
bool riscv_cpu_has_work(CPUState *cs);
44
+
35
36
+/* Zjpm addr masking routine */
37
+static inline target_ulong adjust_addr_body(CPURISCVState *env,
38
+ target_ulong addr,
39
+ bool is_virt_addr)
40
+{
41
+ RISCVPmPmm pmm = PMM_FIELD_DISABLED;
42
+ uint32_t pmlen = 0;
43
+ bool signext = false;
44
+
45
+ /* do nothing for rv32 mode */
46
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
47
+ return addr;
48
+ }
49
+
50
+ /* get pmm field depending on whether addr is */
51
+ if (is_virt_addr) {
52
+ pmm = riscv_pm_get_virt_pmm(env);
53
+ } else {
54
+ pmm = riscv_pm_get_pmm(env);
55
+ }
56
+
57
+ /* if pointer masking is disabled, return original addr */
58
+ if (pmm == PMM_FIELD_DISABLED) {
59
+ return addr;
60
+ }
61
+
62
+ if (!is_virt_addr) {
63
+ signext = riscv_cpu_virt_mem_enabled(env);
64
+ }
65
+ addr = addr << pmlen;
66
+ pmlen = riscv_pm_get_pmlen(pmm);
67
+
68
+ /* sign/zero extend masked address by N-1 bit */
69
+ if (signext) {
70
+ addr = (target_long)addr >> pmlen;
71
+ } else {
72
+ addr = addr >> pmlen;
73
+ }
74
+
75
+ return addr;
76
+}
77
+
78
+static inline target_ulong adjust_addr(CPURISCVState *env,
79
+ target_ulong addr)
80
+{
81
+ return adjust_addr_body(env, addr, false);
82
+}
83
+
84
+static inline target_ulong adjust_addr_virt(CPURISCVState *env,
85
+ target_ulong addr)
86
+{
87
+ return adjust_addr_body(env, addr, true);
88
+}
89
+
90
#endif
91
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
92
index XXXXXXX..XXXXXXX 100644
93
--- a/target/riscv/cpu_helper.c
94
+++ b/target/riscv/cpu_helper.c
95
@@ -XXX,XX +XXX,XX @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env)
96
#endif
97
}
98
99
+RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env)
100
+{
101
+#ifndef CONFIG_USER_ONLY
102
+ int priv_mode = cpu_address_mode(env);
103
+
104
+ if (priv_mode == PRV_U) {
105
+ return get_field(env->hstatus, HSTATUS_HUPMM);
106
+ } else {
107
+ if (get_field(env->hstatus, HSTATUS_SPVP)) {
108
+ return get_field(env->henvcfg, HENVCFG_PMM);
109
+ } else {
110
+ return get_field(env->senvcfg, SENVCFG_PMM);
111
+ }
112
+ }
113
+#else
114
+ return PMM_FIELD_DISABLED;
45
+#endif
115
+#endif
46
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
116
+}
47
index XXXXXXX..XXXXXXX 100644
117
+
48
--- a/hw/arm/virt-acpi-build.c
118
bool riscv_cpu_virt_mem_enabled(CPURISCVState *env)
49
+++ b/hw/arm/virt-acpi-build.c
119
{
50
@@ -XXX,XX +XXX,XX @@
120
#ifndef CONFIG_USER_ONLY
51
#include "target/arm/cpu.h"
121
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
52
#include "hw/acpi/acpi-defs.h"
122
index XXXXXXX..XXXXXXX 100644
53
#include "hw/acpi/acpi.h"
123
--- a/target/riscv/op_helper.c
54
-#include "hw/nvram/fw_cfg.h"
124
+++ b/target/riscv/op_helper.c
55
+#include "hw/nvram/fw_cfg_acpi.h"
125
@@ -XXX,XX +XXX,XX @@ target_ulong helper_hyp_hlv_bu(CPURISCVState *env, target_ulong addr)
56
#include "hw/acpi/bios-linker-loader.h"
126
int mmu_idx = check_access_hlsv(env, false, ra);
57
#include "hw/acpi/aml-build.h"
127
MemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);
58
#include "hw/acpi/utils.h"
128
59
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap,
129
- return cpu_ldb_mmu(env, addr, oi, ra);
60
aml_append(scope, dev);
130
+ return cpu_ldb_mmu(env, adjust_addr_virt(env, addr), oi, ra);
61
}
131
}
62
132
63
-static void acpi_dsdt_add_fw_cfg(Aml *scope, const MemMapEntry *fw_cfg_memmap)
133
target_ulong helper_hyp_hlv_hu(CPURISCVState *env, target_ulong addr)
134
@@ -XXX,XX +XXX,XX @@ target_ulong helper_hyp_hlv_hu(CPURISCVState *env, target_ulong addr)
135
int mmu_idx = check_access_hlsv(env, false, ra);
136
MemOpIdx oi = make_memop_idx(MO_TEUW, mmu_idx);
137
138
- return cpu_ldw_mmu(env, addr, oi, ra);
139
+ return cpu_ldw_mmu(env, adjust_addr_virt(env, addr), oi, ra);
140
}
141
142
target_ulong helper_hyp_hlv_wu(CPURISCVState *env, target_ulong addr)
143
@@ -XXX,XX +XXX,XX @@ target_ulong helper_hyp_hlv_wu(CPURISCVState *env, target_ulong addr)
144
int mmu_idx = check_access_hlsv(env, false, ra);
145
MemOpIdx oi = make_memop_idx(MO_TEUL, mmu_idx);
146
147
- return cpu_ldl_mmu(env, addr, oi, ra);
148
+ return cpu_ldl_mmu(env, adjust_addr_virt(env, addr), oi, ra);
149
}
150
151
target_ulong helper_hyp_hlv_d(CPURISCVState *env, target_ulong addr)
152
@@ -XXX,XX +XXX,XX @@ target_ulong helper_hyp_hlv_d(CPURISCVState *env, target_ulong addr)
153
int mmu_idx = check_access_hlsv(env, false, ra);
154
MemOpIdx oi = make_memop_idx(MO_TEUQ, mmu_idx);
155
156
- return cpu_ldq_mmu(env, addr, oi, ra);
157
+ return cpu_ldq_mmu(env, adjust_addr_virt(env, addr), oi, ra);
158
}
159
160
void helper_hyp_hsv_b(CPURISCVState *env, target_ulong addr, target_ulong val)
161
@@ -XXX,XX +XXX,XX @@ void helper_hyp_hsv_b(CPURISCVState *env, target_ulong addr, target_ulong val)
162
int mmu_idx = check_access_hlsv(env, false, ra);
163
MemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);
164
165
- cpu_stb_mmu(env, addr, val, oi, ra);
166
+ cpu_stb_mmu(env, adjust_addr_virt(env, addr), val, oi, ra);
167
}
168
169
void helper_hyp_hsv_h(CPURISCVState *env, target_ulong addr, target_ulong val)
170
@@ -XXX,XX +XXX,XX @@ void helper_hyp_hsv_h(CPURISCVState *env, target_ulong addr, target_ulong val)
171
int mmu_idx = check_access_hlsv(env, false, ra);
172
MemOpIdx oi = make_memop_idx(MO_TEUW, mmu_idx);
173
174
- cpu_stw_mmu(env, addr, val, oi, ra);
175
+ cpu_stw_mmu(env, adjust_addr_virt(env, addr), val, oi, ra);
176
}
177
178
void helper_hyp_hsv_w(CPURISCVState *env, target_ulong addr, target_ulong val)
179
@@ -XXX,XX +XXX,XX @@ void helper_hyp_hsv_w(CPURISCVState *env, target_ulong addr, target_ulong val)
180
int mmu_idx = check_access_hlsv(env, false, ra);
181
MemOpIdx oi = make_memop_idx(MO_TEUL, mmu_idx);
182
183
- cpu_stl_mmu(env, addr, val, oi, ra);
184
+ cpu_stl_mmu(env, adjust_addr_virt(env, addr), val, oi, ra);
185
}
186
187
void helper_hyp_hsv_d(CPURISCVState *env, target_ulong addr, target_ulong val)
188
@@ -XXX,XX +XXX,XX @@ void helper_hyp_hsv_d(CPURISCVState *env, target_ulong addr, target_ulong val)
189
int mmu_idx = check_access_hlsv(env, false, ra);
190
MemOpIdx oi = make_memop_idx(MO_TEUQ, mmu_idx);
191
192
- cpu_stq_mmu(env, addr, val, oi, ra);
193
+ cpu_stq_mmu(env, adjust_addr_virt(env, addr), val, oi, ra);
194
}
195
196
/*
197
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
198
index XXXXXXX..XXXXXXX 100644
199
--- a/target/riscv/vector_helper.c
200
+++ b/target/riscv/vector_helper.c
201
@@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_max_elems(uint32_t desc, uint32_t log2_esz)
202
return scale < 0 ? vlenb >> -scale : vlenb << scale;
203
}
204
205
-static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong addr)
64
-{
206
-{
65
- Aml *dev = aml_device("FWCF");
207
- if (riscv_cpu_mxl(env) == MXL_RV32) {
66
- aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
208
- return addr;
67
- /* device present, functioning, decoding, not shown in UI */
209
- }
68
- aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
210
- RISCVPmPmm pmm = riscv_pm_get_pmm(env);
69
- aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
211
- if (pmm == PMM_FIELD_DISABLED) {
70
-
212
- return addr;
71
- Aml *crs = aml_resource_template();
213
- }
72
- aml_append(crs, aml_memory32_fixed(fw_cfg_memmap->base,
214
- int pmlen = riscv_pm_get_pmlen(pmm);
73
- fw_cfg_memmap->size, AML_READ_WRITE));
215
- bool signext = riscv_cpu_virt_mem_enabled(env);
74
- aml_append(dev, aml_name_decl("_CRS", crs));
216
- addr = addr << pmlen;
75
- aml_append(scope, dev);
217
- /* sign/zero extend masked address by N-1 bit */
218
- if (signext) {
219
- addr = (target_long)addr >> pmlen;
220
- } else {
221
- addr = addr >> pmlen;
222
- }
223
- return addr;
76
-}
224
-}
77
-
225
-
78
static void acpi_dsdt_add_flash(Aml *scope, const MemMapEntry *flash_memmap)
226
/*
79
{
227
* This function checks watchpoint before real load operation.
80
Aml *dev, *crs;
228
*
81
@@ -XXX,XX +XXX,XX @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
82
if (vmc->acpi_expose_flash) {
83
acpi_dsdt_add_flash(scope, &memmap[VIRT_FLASH]);
84
}
85
- acpi_dsdt_add_fw_cfg(scope, &memmap[VIRT_FW_CFG]);
86
+ fw_cfg_acpi_dsdt_add(scope, &memmap[VIRT_FW_CFG]);
87
acpi_dsdt_add_virtio(scope, &memmap[VIRT_MMIO],
88
(irqmap[VIRT_MMIO] + ARM_SPI_BASE), NUM_VIRTIO_TRANSPORTS);
89
acpi_dsdt_add_pci(scope, memmap, irqmap[VIRT_PCIE] + ARM_SPI_BASE, vms);
90
diff --git a/hw/nvram/fw_cfg-acpi.c b/hw/nvram/fw_cfg-acpi.c
91
new file mode 100644
92
index XXXXXXX..XXXXXXX
93
--- /dev/null
94
+++ b/hw/nvram/fw_cfg-acpi.c
95
@@ -XXX,XX +XXX,XX @@
96
+// SPDX-License-Identifier: GPL-2.0+
97
+/*
98
+ * Add fw_cfg device in DSDT
99
+ *
100
+ */
101
+
102
+#include "hw/nvram/fw_cfg_acpi.h"
103
+#include "hw/acpi/aml-build.h"
104
+
105
+void fw_cfg_acpi_dsdt_add(Aml *scope, const MemMapEntry *fw_cfg_memmap)
106
+{
107
+ Aml *dev = aml_device("FWCF");
108
+ aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
109
+ /* device present, functioning, decoding, not shown in UI */
110
+ aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
111
+ aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
112
+
113
+ Aml *crs = aml_resource_template();
114
+ aml_append(crs, aml_memory32_fixed(fw_cfg_memmap->base,
115
+ fw_cfg_memmap->size, AML_READ_WRITE));
116
+ aml_append(dev, aml_name_decl("_CRS", crs));
117
+ aml_append(scope, dev);
118
+}
119
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
120
index XXXXXXX..XXXXXXX 100644
121
--- a/hw/riscv/virt-acpi-build.c
122
+++ b/hw/riscv/virt-acpi-build.c
123
@@ -XXX,XX +XXX,XX @@
124
#include "hw/acpi/acpi.h"
125
#include "hw/acpi/aml-build.h"
126
#include "hw/acpi/utils.h"
127
+#include "hw/nvram/fw_cfg_acpi.h"
128
#include "qapi/error.h"
129
#include "qemu/error-report.h"
130
#include "sysemu/reset.h"
131
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s)
132
}
133
}
134
135
-static void acpi_dsdt_add_fw_cfg(Aml *scope, const MemMapEntry *fw_cfg_memmap)
136
-{
137
- Aml *dev = aml_device("FWCF");
138
- aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
139
-
140
- /* device present, functioning, decoding, not shown in UI */
141
- aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
142
- aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
143
-
144
- Aml *crs = aml_resource_template();
145
- aml_append(crs, aml_memory32_fixed(fw_cfg_memmap->base,
146
- fw_cfg_memmap->size, AML_READ_WRITE));
147
- aml_append(dev, aml_name_decl("_CRS", crs));
148
- aml_append(scope, dev);
149
-}
150
-
151
/* RHCT Node[N] starts at offset 56 */
152
#define RHCT_NODE_ARRAY_OFFSET 56
153
154
@@ -XXX,XX +XXX,XX @@ static void build_dsdt(GArray *table_data,
155
scope = aml_scope("\\_SB");
156
acpi_dsdt_add_cpus(scope, s);
157
158
- acpi_dsdt_add_fw_cfg(scope, &memmap[VIRT_FW_CFG]);
159
+ fw_cfg_acpi_dsdt_add(scope, &memmap[VIRT_FW_CFG]);
160
161
aml_append(dsdt, scope);
162
163
diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build
164
index XXXXXXX..XXXXXXX 100644
165
--- a/hw/nvram/meson.build
166
+++ b/hw/nvram/meson.build
167
@@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_XLNX_EFUSE_ZYNQMP', if_true: files(
168
system_ss.add(when: 'CONFIG_XLNX_BBRAM', if_true: files('xlnx-bbram.c'))
169
170
specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
171
+specific_ss.add(when: 'CONFIG_ACPI', if_true: files('fw_cfg-acpi.c'))
172
--
229
--
173
2.43.0
230
2.48.1
diff view generated by jsdifflib
1
From: Ivan Klokov <ivan.klokov@syntacore.com>
1
From: Alexey Baturo <baturo.alexey@gmail.com>
2
2
3
This patch changes behavior on writing RW=01 to pmpcfg with MML=0.
3
Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
4
RWX filed is form of collective WARL with the combination of
5
pmpcfg.RW=01 remains reserved for future standard use.
6
7
According to definition of WARL writing the CSR has no other side
8
effect. But current implementation change architectural state and
9
change system behavior. After writing we will get unreadable-unwriteble
10
region regardless on the previous state.
11
12
On the other side WARL said that we should read legal value and nothing
13
says about what we should write. Current behavior change system state
14
regardless of whether we read this register or not.
15
16
Fixes: ac66f2f0 ("target/riscv: pmp: Ignore writes when RW=01")
17
18
Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com>
19
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
20
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
21
Message-ID: <20231220153205.11072-1-ivan.klokov@syntacore.com>
5
Message-ID: <20250106102346.1100149-8-baturo.alexey@gmail.com>
22
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
23
---
7
---
24
target/riscv/pmp.c | 2 +-
8
target/riscv/cpu.c | 6 ++++++
25
1 file changed, 1 insertion(+), 1 deletion(-)
9
1 file changed, 6 insertions(+)
26
10
27
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
11
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
28
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
29
--- a/target/riscv/pmp.c
13
--- a/target/riscv/cpu.c
30
+++ b/target/riscv/pmp.c
14
+++ b/target/riscv/cpu.c
31
@@ -XXX,XX +XXX,XX @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
15
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
32
/* If !mseccfg.MML then ignore writes with encoding RW=01 */
16
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
33
if ((val & PMP_WRITE) && !(val & PMP_READ) &&
17
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
34
!MSECCFG_MML_ISSET(env)) {
18
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
35
- val &= ~(PMP_WRITE | PMP_READ);
19
+ ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm),
36
+ return false;
20
+ ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm),
37
}
21
ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen),
38
env->pmp_state.pmp[pmp_index].cfg_reg = val;
22
ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia),
39
pmp_update_rule_addr(env, pmp_index);
23
ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11),
24
ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf),
25
ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
26
+ ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm),
27
ISA_EXT_DATA_ENTRY(ssstateen, PRIV_VERSION_1_12_0, ext_ssstateen),
28
ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc),
29
ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12),
30
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
31
MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false),
32
MULTI_EXT_CFG_BOOL("zvfhmin", ext_zvfhmin, false),
33
MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true),
34
+ MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false),
35
36
MULTI_EXT_CFG_BOOL("smaia", ext_smaia, false),
37
MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false),
38
+ MULTI_EXT_CFG_BOOL("smmpm", ext_smmpm, false),
39
+ MULTI_EXT_CFG_BOOL("smnpm", ext_smnpm, false),
40
MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false),
41
MULTI_EXT_CFG_BOOL("ssaia", ext_ssaia, false),
42
MULTI_EXT_CFG_BOOL("svade", ext_svade, false),
40
--
43
--
41
2.43.0
44
2.48.1
diff view generated by jsdifflib
1
From: Bin Meng <bmeng@tinylab.org>
1
From: Tommy Wu <tommy.wu@sifive.com>
2
2
3
Upgrade OpenSBI from v1.3.1 to v1.4 and the pre-built bios images.
3
The boolean variable 'ext_smrnmi' is used to determine whether the
4
Smrnmi extension exists.
4
5
5
The v1.4 release includes the following commits:
6
Signed-off-by: Frank Chang <frank.chang@sifive.com>
6
7
Signed-off-by: Tommy Wu <tommy.wu@sifive.com>
7
1a398d9 lib: sbi: Add Zicntr as a HART ISA extension
8
669089c lib: sbi: Add Zihpm as a HART ISA extension
9
72b9c8f lib: sbi: Alphabetically sort HART ISA extensions
10
5359fc6 lib: sbi: Rename hart_pmu_get_allowed_bits() function
11
976895c lib: sbi: Fix Priv spec version for [m|s]counteren and mcountinhibit CSRs
12
6053917 lib: sbi: Fix how print gets flags
13
35ef182 lib: sbi: print not fill '0' when left-aligned
14
40dac06 lib: sbi: Add '+' flags for print
15
458fa74 lib: sbi: Add ' ' '\'' flags for print
16
05cbb6e lib: sbi: implifying the parameters of printi
17
fe08281 lib: sbi: print add 'o' type
18
c6ee5ae lib: sbi: Fix printi
19
3b6fcdd lib: sbi: Simplify prints
20
cc89fa7 lib: sbi: Fix printc
21
ff43168 lib: sbi: Fix timing of clearing tbuf
22
a73982d lib: sbi: Fix missing '\0' when buffer szie equal 1
23
ea6533a lib: utils/gpio: Fix RV32 compile error for designware GPIO driver
24
c3b98c6 include: sbi: Add macro definitions for mseccfg CSR
25
1c099c4 lib: sbi: Add functions to manipulate PMP entries
26
6c202c5 include: sbi: Add Smepmp specific access flags for PMP entries
27
cbcfc7b lib: sbi: Add smepmp in hart extensions
28
d72f5f1 lib: utils: Add detection of Smepmp from ISA string in FDT
29
4a42a23 lib: sbi: Grant SU R/W/X permissions to whole memory
30
f3fdd04 lib: sbi: Change the order of PMP initialization
31
5dd8db5 lib: sbi: Add support for Smepmp
32
6e44ef6 lib: sbi: Add functions to map/unmap shared memory
33
0ad8660 lib: sbi: Map/Unmap debug console shared memory buffers
34
057eb10 lib: utils/gpio: Fix RV32 compile error for designware GPIO driver
35
0e2111e libfdt: fix SPDX license identifiers
36
e05a9cf lib: sbi: Update system suspend to spec
37
5e20d25 include: sbi: fix CSR define of mseccfg
38
44c5151 include: sbi_utils: Remove driver pointer from struct i2c_adapter
39
14a35b0 lib: utils/regmap: Add generic regmap access library
40
8e97275 lib: utils/regmap: Add simple FDT based regmap framework
41
f21d8f7 lib: utils/regmap: Add simple FDT based syscon regmap driver
42
4a344a9 lib: utils/reset: Add syscon based reboot and poweroff
43
c2e6027 lib: utils/reset: Remove SiFive Test reset driver
44
f536e0b gitignore: allow gitignore to ignore most dot file
45
c744ed7 lib: sbi_pmu: Enable noncontigous hpm event and counters
46
6259b2e lib: utils/fdt: Fix fdt_parse_isa_extensions() implementation
47
f46a564 lib: sbi: Fix typo for finding fixed event counter
48
94197a8 fw_base.S: Fix assembler error with clang 16+
49
c104c60 lib: sbi: Add support for smcntrpmf
50
7aabeee Makefile: Fix grep warning
51
e7e73aa platform: generic: allwinner: correct mhpmevent count
52
ee1f83c lib: sbi_pmu: remove mhpm_count field in hart feature
53
a9cffd6 firmware: payload: test: Change to SBI v2.0 DBCN ecalls
54
b20bd47 lib: sbi: improve the definition of SBI_IPI_EVENT_MAX
55
664692f lib: sbi_pmu: ensure update hpm counter before starting counting
56
c9a296d platform: generic: allwinner: fix OF process for T-HEAD c9xx pmu
57
901d3d7 lib: sbi_pmu: keep overflow interrupt of stopped hpm counter disabled
58
cacfba3 platform: Allow platforms to specify the size of tlb fifo
59
5bd9694 lib: sbi: alloc tlb fifo by sbi_malloc
60
130e65d lib: sbi: Implement SET_FS_DIRTY() to make sure the mstatus FS dirty is set
61
d1e4dff lib: sbi: Introduce HART index in sbi_scratch
62
e6125c3 lib: sbi: Remove sbi_platform_hart_index/invalid() functions
63
296e70d lib: sbi: Extend sbi_hartmask to support both hartid and hartindex
64
e632cd7 lib: sbi: Use sbi_scratch_last_hartindex() in remote TLB managment
65
78c667b lib: sbi: Prefer hartindex over hartid in IPI framework
66
22d6ff8 lib: sbi: Remove sbi_scratch_last_hartid() macro
67
112daa2 lib: sbi: Maximize the use of HART index in sbi_domain
68
9560fb3 include: sbi: Remove sbi_hartmask_for_each_hart() macro
69
b8fb96e include: sbi_domain: Fix permission test macros
70
bff27c1 lib: sbi: Factor-out Smepmp configuration as separate function
71
5240d31 lib: sbi: Don't clear mseccfg.MML bit in sbi_hart_smepmp_configure()
72
2b51a9d lib: sbi: Fix pmp_flags for Smepmp read-only shared region
73
73aea28 lib: sbi: Populate M-only Smepmp entries before setting mseccfg.MML
74
e8bc162 lib: utils/serial: Add shared regions for serial drivers
75
b7e9d34 lib: utils/regmap: Mark syscon region as shared read-write
76
3669153 platform: generic: thead: fix stale TLB entries for th1520/sg2042
77
de525ac firmware: Remove ALIGN in .rela.dyn in linker script
78
2a6d725 firmware: Remove handling of R_RISCV_{32,64}
79
6ed125a Makefile: Add --exclude-libs ALL to avoid .dynsym
80
e21901d doc: Fix fw_payload.md
81
a125423 lib: utils/serial: Ensure proper allocation of PMP entries for uart8250
82
d36709f lib: utils: timer/ipi: Update memregion flags for PLMT and PLICSW
83
8197c2f lib: sbi: fix sbi_domain_get_assigned_hartmask()
84
9da30f6 lib: utils/fdt: simplify dt_parse_isa_extensions
85
942aca2 lib: utils: Simplify SET_ISA_EXT_MAP()
86
f831b93 lib: sbi_pmu: check for index overflows
87
d891cae gpio/starfive: redundant readl() call
88
e8114c6 docs: platform: update platform_requirements.md
89
3632f2b lib: sbi: Add support for mconfigptr
90
ec0559e lib: sbi_misaligned_ldst: Fix handling of C.SWSP and C.SDSP
91
cbdd869 include: sbi: Change spec version to 2.0
92
5d0ed1b lib: sbi: simplify sanitize_domain()
93
c1a6987 platform: generic: thead: move to thead c9xx header to vendor specific postion
94
8e941e7 platform: generic: thead: separate implement of T-HEAD c9xx pmu
95
492d9b1 platform: generic: thead: separate implement of T-HEAD c9xx errata
96
3e21b96 platform: generic: thead: initialize PMU by default in thead generic platform
97
a140a4e lib: sbi: Correctly limit flushes to a single ASID/VMID
98
88ae718 platform: generic: thead: improve tlb flush errata
99
52fd64b platform: Uses hart count as the default size of tlb info
100
07f2ccd lib: utils/serial: Optimize semihosting_putc implementation
101
fccdf41 firmware: fw_base.S: Fix boot hart status synchronization
102
d1e0f7f utils/reset: Remove fdt_reset_thead
103
896d2c9 lib: utils/timer: Allow ACLINT MTIMER driver to setup quirks
104
accafb1 lib: utils/timer: mtimer: add separate T-Head C9xx CLINT mtimer compatible
105
98bc25f lib: utils/ipi: mswi: add separate T-Head C9xx CLINT mswi compatible
106
5b2f55d lib: sbi: separate the swap operation of domain region
107
3b03cdd lib: sbi: Add regions merging when sanitizing domain region
108
2bfdb9e platform: generic: Add Sophgo sg2042 platform support
109
280f7ae include: sbi: macros for mseccfg.sseed and .useed
110
efcac33 lib: sbi: Add Zkr in hart extensions
111
6e5b0cf lib: sbi: enable seed access in S-mode
112
6602e11 lib: sbi: change sbi_hart_features.extensions as an array
113
3aaed4f lib: sbi: Make console_puts/console_putc interchangeable
114
dc0bb19 lib: utils/serial: remove semihosting_putc
115
16bb930 lib: sbi: Fix PMP granularity handling in sbi_hart_map_saddr()
116
574b9c8 lib: sbi_pmu: avoid buffer overflow
117
791704c lib: utils/irqchip: Avoid redundant writes to APLIC CLRIE register
118
f520256 lib: sbi: Allow relaxed MMIO writes in device ipi_send() callback
119
b70d628 lib: sbi: Allow relaxed MMIO writes in device ipi_clear() callback
120
bd74931 lib: ipi: Adjust Andes PLICSW to single-bit-per-hart scheme
121
291403f sbi: sbi_pmu: Improve sbi_pmu_init() error handling
122
090fa99 lib: sbi: Add XAndesPMU in hart extensions
123
a48f2cf sbi: sbi_pmu: Add hw_counter_filter_mode() to pmu device
124
51ec60c platform: include: andes45: Add PMU related CSR defines
125
effd89a platform: generic: Introduce pmu_init() platform override
126
1b9e743 platform: andes: Add Andes custom PMU support
127
2e50c24 platform: andes: Enable Andes PMU for AE350
128
535c661 platform: rzfive: Enable Andes PMU for RZ/Five
129
0b3262e lib: utils: fdt_fixup: Allow preserving PMU properties
130
009ae4e platform: andes: Factor out is_andes() helper
131
0308f93 lib: utils: fdt_pmu: Make the fdt_pmu_evt_select table global variable
132
e19d419 lib: utils: fdt_pmu: Do not iterate over the fdt_pmu_evt_select table
133
d162009 docs: pmu: Add Andes PMU node example
134
6b9a849 lib: sbi: Remove xchg/cmpxchg implemented via lr/sc
135
11bf49b lib: sbi: Fix __atomic_op_bit_ord and comments
136
8839869 lib: sbi: Replace __atomic_op_bit_ord with __atomic intrinsics
137
07419ec lib: sbi: Prevent redundant sbi_ipi_process
138
93da66b lib: sbi_hart: Store PMP granularity as log base 2
139
ee72517 lib: sbi_pmu: Add PMU snapshot definitions
140
11a0ba5 lib: sbi_pmu: Fix the counter info function
141
0696810 firmware: fix section types
142
a25fc74 lib: sbi_hsm: Put the resume_pending hart in the interruptible hart mask
143
87aa306 platform: recalculate heap size to support new tlb entry number
144
a2e254e lib: sbi: skip wait_for_coldboot when coolboot done
145
6112d58 lib: utils/fdt: Allow to use reg-names when parsing ACLINT
146
35cba92 lib: sbi_tlb: Check tlb_range_flush_limit only once per request
147
a894187 lib: sbi_ipi: Do not ignore errors from sbi_ipi_send()
148
446fa65 lib: sbi_ipi: Process self-IPIs in sbi_ipi_send()
149
2707250 lib: sbi_ipi: Drop unnecessary ipi_process check
150
925ce14 lib: sbi: Simplify the initialization of root_hmask in sbi_domain_init
151
2c8be56 lib: sbi: Improve the code of privilege mode and extensions detection
152
056fe6f lib: sbi: Refactor the code for enable extensions in menvfg CSR
153
776770d lib: sbi: Using one array to define the name of extensions
154
3daac8f lib: sbi: Detect extensions from the ISA string in DT
155
416ceb3 lib: sbi_tlb: Reduce size of struct sbi_tlb_info
156
80169b2 platform: generic: Fine tune fw_platform_calculate_heap_size()
157
cdebae2 lib: utils/irqchip: Add shared MMIO region for PLIC in root domain
158
3284bea lib: sbi: Allow ecall handlers to directly update register state
159
5a57e8c lib: sbi: Remove the SBI_ETRAP error code
160
2b80b92 lib: sbi: Do not enter OpenSBI with mseccfg.MML == 1
161
63e09ad lib: sbi: Fix shift bug in sbi_system_reset
162
ba29293 lib: utils/timer: mtimer: only use regname for aclint
163
bbd065d lib: sbi: Detect Zicntr extension only based on traps
164
a2b255b include: Bump-up version to 1.4
165
166
Signed-off-by: Bin Meng <bmeng@tinylab.org>
167
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
168
Message-Id: <20240102151153.133896-1-bmeng@tinylab.org>
9
Message-ID: <20250106054336.1878291-2-frank.chang@sifive.com>
169
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
170
---
11
---
171
.../opensbi-riscv32-generic-fw_dynamic.bin | Bin 135376 -> 267416 bytes
12
target/riscv/cpu_cfg.h | 1 +
172
.../opensbi-riscv64-generic-fw_dynamic.bin | Bin 138368 -> 270808 bytes
13
1 file changed, 1 insertion(+)
173
roms/opensbi | 2 +-
174
3 files changed, 1 insertion(+), 1 deletion(-)
175
14
176
diff --git a/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin b/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin
15
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
177
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
178
Binary files a/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin and b/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin differ
17
--- a/target/riscv/cpu_cfg.h
179
diff --git a/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin b/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin
18
+++ b/target/riscv/cpu_cfg.h
180
index XXXXXXX..XXXXXXX 100644
19
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
181
Binary files a/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin and b/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin differ
20
bool ext_ssaia;
182
diff --git a/roms/opensbi b/roms/opensbi
21
bool ext_sscofpmf;
183
index XXXXXXX..XXXXXXX 160000
22
bool ext_smepmp;
184
--- a/roms/opensbi
23
+ bool ext_smrnmi;
185
+++ b/roms/opensbi
24
bool ext_ssnpm;
186
@@ -1 +1 @@
25
bool ext_smnpm;
187
-Subproject commit 057eb10b6d523540012e6947d5c9f63e95244e94
26
bool ext_smmpm;
188
+Subproject commit a2b255b88918715173942f2c5e1f97ac9e90c877
189
--
27
--
190
2.43.0
28
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Tommy Wu <tommy.wu@sifive.com>
2
2
3
Some profiles, like RVA22S64, has a priv_spec requirement.
3
The Smrnmi extension adds the 'mnscratch', 'mnepc', 'mncause',
4
'mnstatus' CSRs.
4
5
5
Make this requirement explicit for all profiles. We'll validate this
6
Signed-off-by: Frank Chang <frank.chang@sifive.com>
6
requirement finalize() time and, in case the user chooses an
7
Signed-off-by: Tommy Wu <tommy.wu@sifive.com>
7
incompatible priv_spec while activating a profile, a warning will be
8
shown.
9
10
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-ID: <20231218125334.37184-21-dbarboza@ventanamicro.com>
9
Message-ID: <20250106054336.1878291-3-frank.chang@sifive.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
11
---
16
target/riscv/cpu.h | 2 ++
12
target/riscv/cpu.h | 7 ++++
17
target/riscv/cpu.c | 1 +
13
target/riscv/cpu_bits.h | 11 ++++++
18
target/riscv/tcg/tcg-cpu.c | 31 +++++++++++++++++++++++++++++++
14
target/riscv/cpu.c | 5 +++
19
3 files changed, 34 insertions(+)
15
target/riscv/csr.c | 82 +++++++++++++++++++++++++++++++++++++++++
16
4 files changed, 105 insertions(+)
20
17
21
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
18
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
22
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/cpu.h
20
--- a/target/riscv/cpu.h
24
+++ b/target/riscv/cpu.h
21
+++ b/target/riscv/cpu.h
25
@@ -XXX,XX +XXX,XX @@ typedef struct riscv_cpu_profile {
22
@@ -XXX,XX +XXX,XX @@ struct CPUArchState {
26
uint32_t misa_ext;
23
uint64_t kvm_timer_state;
27
bool enabled;
24
uint64_t kvm_timer_frequency;
28
bool user_set;
25
#endif /* CONFIG_KVM */
29
+ int priv_spec;
26
+
30
const int32_t ext_offsets[];
27
+ /* RNMI */
31
} RISCVCPUProfile;
28
+ target_ulong mnscratch;
32
29
+ target_ulong mnepc;
33
#define RISCV_PROFILE_EXT_LIST_END -1
30
+ target_ulong mncause; /* mncause without bit XLEN-1 set to 1 */
34
+#define RISCV_PROFILE_ATTR_UNUSED -1
31
+ target_ulong mnstatus;
35
32
+ target_ulong rnmip;
36
extern RISCVCPUProfile *riscv_profiles[];
33
};
37
34
35
/*
36
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/cpu_bits.h
39
+++ b/target/riscv/cpu_bits.h
40
@@ -XXX,XX +XXX,XX @@
41
#define CSR_PMPADDR14 0x3be
42
#define CSR_PMPADDR15 0x3bf
43
44
+/* RNMI */
45
+#define CSR_MNSCRATCH 0x740
46
+#define CSR_MNEPC 0x741
47
+#define CSR_MNCAUSE 0x742
48
+#define CSR_MNSTATUS 0x744
49
+
50
/* Debug/Trace Registers (shared with Debug Mode) */
51
#define CSR_TSELECT 0x7a0
52
#define CSR_TDATA1 0x7a1
53
@@ -XXX,XX +XXX,XX @@ typedef enum {
54
#define SATP64_ASID 0x0FFFF00000000000ULL
55
#define SATP64_PPN 0x00000FFFFFFFFFFFULL
56
57
+/* RNMI mnstatus CSR mask */
58
+#define MNSTATUS_NMIE 0x00000008
59
+#define MNSTATUS_MNPV 0x00000080
60
+#define MNSTATUS_MNPP 0x00001800
61
+
62
/* VM modes (satp.mode) privileged ISA 1.10 */
63
#define VM_1_10_MBARE 0
64
#define VM_1_10_SV32 1
38
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
65
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
39
index XXXXXXX..XXXXXXX 100644
66
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/cpu.c
67
--- a/target/riscv/cpu.c
41
+++ b/target/riscv/cpu.c
68
+++ b/target/riscv/cpu.c
42
@@ -XXX,XX +XXX,XX @@ Property riscv_cpu_options[] = {
69
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type)
43
static RISCVCPUProfile RVA22U64 = {
70
riscv_trigger_reset_hold(env);
44
.name = "rva22u64",
45
.misa_ext = RVI | RVM | RVA | RVF | RVD | RVC | RVU,
46
+ .priv_spec = RISCV_PROFILE_ATTR_UNUSED,
47
.ext_offsets = {
48
CPU_CFG_OFFSET(ext_zicsr), CPU_CFG_OFFSET(ext_zihintpause),
49
CPU_CFG_OFFSET(ext_zba), CPU_CFG_OFFSET(ext_zbb),
50
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
51
index XXXXXXX..XXXXXXX 100644
52
--- a/target/riscv/tcg/tcg-cpu.c
53
+++ b/target/riscv/tcg/tcg-cpu.c
54
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_write_misa_bit(RISCVCPU *cpu, uint32_t bit,
55
}
71
}
56
}
72
57
73
+ if (cpu->cfg.ext_smrnmi) {
58
+static const char *cpu_priv_ver_to_str(int priv_ver)
74
+ env->rnmip = 0;
59
+{
75
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_NMIE, false);
60
+ switch (priv_ver) {
61
+ case PRIV_VERSION_1_10_0:
62
+ return "v1.10.0";
63
+ case PRIV_VERSION_1_11_0:
64
+ return "v1.11.0";
65
+ case PRIV_VERSION_1_12_0:
66
+ return "v1.12.0";
67
+ }
76
+ }
68
+
77
+
69
+ g_assert_not_reached();
78
if (kvm_enabled()) {
79
kvm_riscv_reset_vcpu(cpu);
80
}
81
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
82
index XXXXXXX..XXXXXXX 100644
83
--- a/target/riscv/csr.c
84
+++ b/target/riscv/csr.c
85
@@ -XXX,XX +XXX,XX @@ static RISCVException debug(CPURISCVState *env, int csrno)
86
87
return RISCV_EXCP_ILLEGAL_INST;
88
}
89
+
90
+static RISCVException rnmi(CPURISCVState *env, int csrno)
91
+{
92
+ RISCVCPU *cpu = env_archcpu(env);
93
+
94
+ if (cpu->cfg.ext_smrnmi) {
95
+ return RISCV_EXCP_NONE;
96
+ }
97
+
98
+ return RISCV_EXCP_ILLEGAL_INST;
99
+}
100
#endif
101
102
static RISCVException seed(CPURISCVState *env, int csrno)
103
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mcontext(CPURISCVState *env, int csrno,
104
return RISCV_EXCP_NONE;
105
}
106
107
+static RISCVException read_mnscratch(CPURISCVState *env, int csrno,
108
+ target_ulong *val)
109
+{
110
+ *val = env->mnscratch;
111
+ return RISCV_EXCP_NONE;
70
+}
112
+}
71
+
113
+
72
static void riscv_cpu_synchronize_from_tb(CPUState *cs,
114
+static int write_mnscratch(CPURISCVState *env, int csrno, target_ulong val)
73
const TranslationBlock *tb)
115
+{
74
{
116
+ env->mnscratch = val;
75
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
117
+ return RISCV_EXCP_NONE;
76
static void riscv_cpu_validate_profile(RISCVCPU *cpu,
118
+}
77
RISCVCPUProfile *profile)
78
{
79
+ CPURISCVState *env = &cpu->env;
80
const char *warn_msg = "Profile %s mandates disabled extension %s";
81
bool send_warn = profile->user_set && profile->enabled;
82
bool profile_impl = true;
83
int i;
84
85
+ if (profile->priv_spec != RISCV_PROFILE_ATTR_UNUSED &&
86
+ profile->priv_spec != env->priv_ver) {
87
+ profile_impl = false;
88
+
119
+
89
+ if (send_warn) {
120
+static int read_mnepc(CPURISCVState *env, int csrno, target_ulong *val)
90
+ warn_report("Profile %s requires priv spec %s, "
121
+{
91
+ "but priv ver %s was set", profile->name,
122
+ *val = env->mnepc;
92
+ cpu_priv_ver_to_str(profile->priv_spec),
123
+ return RISCV_EXCP_NONE;
93
+ cpu_priv_ver_to_str(env->priv_ver));
124
+}
125
+
126
+static int write_mnepc(CPURISCVState *env, int csrno, target_ulong val)
127
+{
128
+ env->mnepc = val;
129
+ return RISCV_EXCP_NONE;
130
+}
131
+
132
+static int read_mncause(CPURISCVState *env, int csrno, target_ulong *val)
133
+{
134
+ *val = env->mncause;
135
+ return RISCV_EXCP_NONE;
136
+}
137
+
138
+static int write_mncause(CPURISCVState *env, int csrno, target_ulong val)
139
+{
140
+ env->mncause = val;
141
+ return RISCV_EXCP_NONE;
142
+}
143
+
144
+static int read_mnstatus(CPURISCVState *env, int csrno, target_ulong *val)
145
+{
146
+ *val = env->mnstatus;
147
+ return RISCV_EXCP_NONE;
148
+}
149
+
150
+static int write_mnstatus(CPURISCVState *env, int csrno, target_ulong val)
151
+{
152
+ target_ulong mask = (MNSTATUS_NMIE | MNSTATUS_MNPP);
153
+
154
+ if (riscv_has_ext(env, RVH)) {
155
+ /* Flush tlb on mnstatus fields that affect VM. */
156
+ if ((val ^ env->mnstatus) & MNSTATUS_MNPV) {
157
+ tlb_flush(env_cpu(env));
94
+ }
158
+ }
159
+
160
+ mask |= MNSTATUS_MNPV;
95
+ }
161
+ }
96
+
162
+
97
for (i = 0; misa_bits[i] != 0; i++) {
163
+ /* mnstatus.mnie can only be cleared by hardware. */
98
uint32_t bit = misa_bits[i];
164
+ env->mnstatus = (env->mnstatus & MNSTATUS_NMIE) | (val & mask);
99
165
+ return RISCV_EXCP_NONE;
100
@@ -XXX,XX +XXX,XX @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
166
+}
101
profile->user_set = true;
102
profile->enabled = value;
103
104
+ if (profile->enabled) {
105
+ cpu->env.priv_ver = profile->priv_spec;
106
+ }
107
+
167
+
108
for (i = 0; misa_bits[i] != 0; i++) {
168
#endif
109
uint32_t bit = misa_bits[i];
169
110
170
/* Crypto Extension */
171
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
172
write_sstateen_1_3,
173
.min_priv_ver = PRIV_VERSION_1_12_0 },
174
175
+ /* RNMI */
176
+ [CSR_MNSCRATCH] = { "mnscratch", rnmi, read_mnscratch, write_mnscratch,
177
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
178
+ [CSR_MNEPC] = { "mnepc", rnmi, read_mnepc, write_mnepc,
179
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
180
+ [CSR_MNCAUSE] = { "mncause", rnmi, read_mncause, write_mncause,
181
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
182
+ [CSR_MNSTATUS] = { "mnstatus", rnmi, read_mnstatus, write_mnstatus,
183
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
184
+
185
/* Supervisor Trap Setup */
186
[CSR_SSTATUS] = { "sstatus", smode, read_sstatus, write_sstatus,
187
NULL, read_sstatus_i128 },
111
--
188
--
112
2.43.0
189
2.48.1
diff view generated by jsdifflib
1
From: Sunil V L <sunilvl@ventanamicro.com>
1
From: Tommy Wu <tommy.wu@sifive.com>
2
2
3
ACPI DSDT generator needs information like ECAM range, PIO range, 32-bit
3
Because the RNMI interrupt trap handler address is implementation defined.
4
and 64-bit PCI MMIO range etc related to the PCI host bridge. Instead of
4
We add the 'rnmi-interrupt-vector' and 'rnmi-exception-vector' as the property
5
making these values machine specific, create properties for the GPEX
5
of the harts. It’s very easy for users to set the address based on their
6
host bridge with default value 0. During initialization, the firmware
6
expectation. This patch also adds the functionality to handle the RNMI signals.
7
can initialize these properties with correct values for the platform.
7
8
This basically allows DSDT generator code independent of the machine
8
Signed-off-by: Frank Chang <frank.chang@sifive.com>
9
specific memory map accesses.
9
Signed-off-by: Tommy Wu <tommy.wu@sifive.com>
10
11
Suggested-by: Igor Mammedov <imammedo@redhat.com>
12
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
13
Acked-by: Alistair Francis <alistair.francis@wdc.com>
14
Acked-by: Michael S. Tsirkin <mst@redhat.com>
15
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
16
Message-ID: <20231218150247.466427-11-sunilvl@ventanamicro.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Message-ID: <20250106054336.1878291-4-frank.chang@sifive.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
---
14
---
19
include/hw/pci-host/gpex.h | 28 ++++++++++++++++++++--------
15
include/hw/riscv/riscv_hart.h | 4 ++
20
hw/pci-host/gpex-acpi.c | 13 +++++++++++++
16
target/riscv/cpu.h | 3 ++
21
hw/pci-host/gpex.c | 12 ++++++++++++
17
target/riscv/cpu_bits.h | 12 +++++
22
3 files changed, 45 insertions(+), 8 deletions(-)
18
hw/riscv/riscv_hart.c | 41 ++++++++++++++++
23
19
target/riscv/cpu.c | 11 +++++
24
diff --git a/include/hw/pci-host/gpex.h b/include/hw/pci-host/gpex.h
20
target/riscv/cpu_helper.c | 88 ++++++++++++++++++++++++++++++++---
25
index XXXXXXX..XXXXXXX 100644
21
6 files changed, 152 insertions(+), 7 deletions(-)
26
--- a/include/hw/pci-host/gpex.h
22
27
+++ b/include/hw/pci-host/gpex.h
23
diff --git a/include/hw/riscv/riscv_hart.h b/include/hw/riscv/riscv_hart.h
28
@@ -XXX,XX +XXX,XX @@ struct GPEXRootState {
24
index XXXXXXX..XXXXXXX 100644
29
/*< public >*/
25
--- a/include/hw/riscv/riscv_hart.h
26
+++ b/include/hw/riscv/riscv_hart.h
27
@@ -XXX,XX +XXX,XX @@ struct RISCVHartArrayState {
28
uint32_t hartid_base;
29
char *cpu_type;
30
uint64_t resetvec;
31
+ uint32_t num_rnmi_irqvec;
32
+ uint64_t *rnmi_irqvec;
33
+ uint32_t num_rnmi_excpvec;
34
+ uint64_t *rnmi_excpvec;
35
RISCVCPU *harts;
30
};
36
};
31
37
32
+struct GPEXConfig {
38
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
33
+ MemMapEntry ecam;
39
index XXXXXXX..XXXXXXX 100644
34
+ MemMapEntry mmio32;
40
--- a/target/riscv/cpu.h
35
+ MemMapEntry mmio64;
41
+++ b/target/riscv/cpu.h
36
+ MemMapEntry pio;
42
@@ -XXX,XX +XXX,XX @@ struct CPUArchState {
37
+ int irq;
43
target_ulong mncause; /* mncause without bit XLEN-1 set to 1 */
38
+ PCIBus *bus;
44
target_ulong mnstatus;
39
+};
45
target_ulong rnmip;
40
+
46
+ uint64_t rnmi_irqvec;
41
struct GPEXHost {
47
+ uint64_t rnmi_excpvec;
42
/*< private >*/
43
PCIExpressHost parent_obj;
44
@@ -XXX,XX +XXX,XX @@ struct GPEXHost {
45
int irq_num[GPEX_NUM_IRQS];
46
47
bool allow_unmapped_accesses;
48
-};
49
50
-struct GPEXConfig {
51
- MemMapEntry ecam;
52
- MemMapEntry mmio32;
53
- MemMapEntry mmio64;
54
- MemMapEntry pio;
55
- int irq;
56
- PCIBus *bus;
57
+ struct GPEXConfig gpex_cfg;
58
};
48
};
59
49
60
int gpex_set_irq_num(GPEXHost *s, int index, int gsi);
50
/*
61
51
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env);
62
void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg);
52
int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts);
63
+void acpi_dsdt_add_gpex_host(Aml *scope, uint32_t irq);
53
uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask,
64
+
54
uint64_t value);
65
+#define PCI_HOST_PIO_BASE "x-pio-base"
55
+void riscv_cpu_set_rnmi(RISCVCPU *cpu, uint32_t irq, bool level);
66
+#define PCI_HOST_PIO_SIZE "x-pio-size"
56
void riscv_cpu_interrupt(CPURISCVState *env);
67
+#define PCI_HOST_ECAM_BASE "x-ecam-base"
57
#define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */
68
+#define PCI_HOST_ECAM_SIZE "x-ecam-size"
58
void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void *),
69
+#define PCI_HOST_BELOW_4G_MMIO_BASE "x-below-4g-mmio-base"
59
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
70
+#define PCI_HOST_BELOW_4G_MMIO_SIZE "x-below-4g-mmio-size"
60
index XXXXXXX..XXXXXXX 100644
71
+#define PCI_HOST_ABOVE_4G_MMIO_BASE "x-above-4g-mmio-base"
61
--- a/target/riscv/cpu_bits.h
72
+#define PCI_HOST_ABOVE_4G_MMIO_SIZE "x-above-4g-mmio-size"
62
+++ b/target/riscv/cpu_bits.h
73
63
@@ -XXX,XX +XXX,XX @@ typedef enum {
74
#endif /* HW_GPEX_H */
64
/* Default Reset Vector address */
75
diff --git a/hw/pci-host/gpex-acpi.c b/hw/pci-host/gpex-acpi.c
65
#define DEFAULT_RSTVEC 0x1000
76
index XXXXXXX..XXXXXXX 100644
66
77
--- a/hw/pci-host/gpex-acpi.c
67
+/* Default RNMI Interrupt Vector address */
78
+++ b/hw/pci-host/gpex-acpi.c
68
+#define DEFAULT_RNMI_IRQVEC 0x0
79
@@ -XXX,XX +XXX,XX @@ void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg)
69
+
80
70
+/* Default RNMI Exception Vector address */
81
crs_range_set_free(&crs_range_set);
71
+#define DEFAULT_RNMI_EXCPVEC 0x0
72
+
73
/* Exception causes */
74
typedef enum RISCVException {
75
RISCV_EXCP_NONE = -1, /* sentinel value */
76
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
77
/* -1 is due to bit zero of hgeip and hgeie being ROZ. */
78
#define IRQ_LOCAL_GUEST_MAX (TARGET_LONG_BITS - 1)
79
80
+/* RNMI causes */
81
+#define RNMI_MAX 16
82
+
83
/* mip masks */
84
#define MIP_USIP (1 << IRQ_U_SOFT)
85
#define MIP_SSIP (1 << IRQ_S_SOFT)
86
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
87
#define MHPMEVENT_IDX_MASK 0xFFFFF
88
#define MHPMEVENT_SSCOF_RESVD 16
89
90
+/* RISC-V-specific interrupt pending bits. */
91
+#define CPU_INTERRUPT_RNMI CPU_INTERRUPT_TGT_EXT_0
92
+
93
/* JVT CSR bits */
94
#define JVT_MODE 0x3F
95
#define JVT_BASE (~0x3F)
96
diff --git a/hw/riscv/riscv_hart.c b/hw/riscv/riscv_hart.c
97
index XXXXXXX..XXXXXXX 100644
98
--- a/hw/riscv/riscv_hart.c
99
+++ b/hw/riscv/riscv_hart.c
100
@@ -XXX,XX +XXX,XX @@
101
#include "target/riscv/cpu.h"
102
#include "hw/qdev-properties.h"
103
#include "hw/riscv/riscv_hart.h"
104
+#include "qemu/error-report.h"
105
106
static const Property riscv_harts_props[] = {
107
DEFINE_PROP_UINT32("num-harts", RISCVHartArrayState, num_harts, 1),
108
@@ -XXX,XX +XXX,XX @@ static const Property riscv_harts_props[] = {
109
DEFINE_PROP_STRING("cpu-type", RISCVHartArrayState, cpu_type),
110
DEFINE_PROP_UINT64("resetvec", RISCVHartArrayState, resetvec,
111
DEFAULT_RSTVEC),
112
+
113
+ /*
114
+ * Smrnmi implementation-defined interrupt and exception trap handlers.
115
+ *
116
+ * When an RNMI interrupt is detected, the hart then enters M-mode and
117
+ * jumps to the address defined by "rnmi-interrupt-vector".
118
+ *
119
+ * When the hart encounters an exception while executing in M-mode with
120
+ * the mnstatus.NMIE bit clear, the hart then jumps to the address
121
+ * defined by "rnmi-exception-vector".
122
+ */
123
+ DEFINE_PROP_ARRAY("rnmi-interrupt-vector", RISCVHartArrayState,
124
+ num_rnmi_irqvec, rnmi_irqvec, qdev_prop_uint64,
125
+ uint64_t),
126
+ DEFINE_PROP_ARRAY("rnmi-exception-vector", RISCVHartArrayState,
127
+ num_rnmi_excpvec, rnmi_excpvec, qdev_prop_uint64,
128
+ uint64_t),
129
};
130
131
static void riscv_harts_cpu_reset(void *opaque)
132
@@ -XXX,XX +XXX,XX @@ static bool riscv_hart_realize(RISCVHartArrayState *s, int idx,
133
{
134
object_initialize_child(OBJECT(s), "harts[*]", &s->harts[idx], cpu_type);
135
qdev_prop_set_uint64(DEVICE(&s->harts[idx]), "resetvec", s->resetvec);
136
+
137
+ if (s->harts[idx].cfg.ext_smrnmi) {
138
+ if (idx < s->num_rnmi_irqvec) {
139
+ qdev_prop_set_uint64(DEVICE(&s->harts[idx]),
140
+ "rnmi-interrupt-vector", s->rnmi_irqvec[idx]);
141
+ }
142
+
143
+ if (idx < s->num_rnmi_excpvec) {
144
+ qdev_prop_set_uint64(DEVICE(&s->harts[idx]),
145
+ "rnmi-exception-vector", s->rnmi_excpvec[idx]);
146
+ }
147
+ } else {
148
+ if (s->num_rnmi_irqvec > 0) {
149
+ warn_report_once("rnmi-interrupt-vector property is ignored "
150
+ "because Smrnmi extension is not enabled.");
151
+ }
152
+
153
+ if (s->num_rnmi_excpvec > 0) {
154
+ warn_report_once("rnmi-exception-vector property is ignored "
155
+ "because Smrnmi extension is not enabled.");
156
+ }
157
+ }
158
+
159
s->harts[idx].env.mhartid = s->hartid_base + idx;
160
qemu_register_reset(riscv_harts_cpu_reset, &s->harts[idx]);
161
return qdev_realize(DEVICE(&s->harts[idx]), NULL, errp);
162
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
163
index XXXXXXX..XXXXXXX 100644
164
--- a/target/riscv/cpu.c
165
+++ b/target/riscv/cpu.c
166
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_set_irq(void *opaque, int irq, int level)
167
g_assert_not_reached();
168
}
82
}
169
}
83
+
170
+
84
+void acpi_dsdt_add_gpex_host(Aml *scope, uint32_t irq)
171
+static void riscv_cpu_set_nmi(void *opaque, int irq, int level)
85
+{
172
+{
86
+ bool ambig;
173
+ riscv_cpu_set_rnmi(RISCV_CPU(opaque), irq, level);
87
+ Object *obj = object_resolve_path_type("", TYPE_GPEX_HOST, &ambig);
174
+}
88
+
175
#endif /* CONFIG_USER_ONLY */
89
+ if (!obj || ambig) {
176
177
static bool riscv_cpu_is_dynamic(Object *cpu_obj)
178
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj)
179
#ifndef CONFIG_USER_ONLY
180
qdev_init_gpio_in(DEVICE(obj), riscv_cpu_set_irq,
181
IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);
182
+ qdev_init_gpio_in_named(DEVICE(cpu), riscv_cpu_set_nmi,
183
+ "riscv.cpu.rnmi", RNMI_MAX);
184
#endif /* CONFIG_USER_ONLY */
185
186
general_user_opts = g_hash_table_new(g_str_hash, g_str_equal);
187
@@ -XXX,XX +XXX,XX @@ static const Property riscv_cpu_properties[] = {
188
189
#ifndef CONFIG_USER_ONLY
190
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
191
+ DEFINE_PROP_UINT64("rnmi-interrupt-vector", RISCVCPU, env.rnmi_irqvec,
192
+ DEFAULT_RNMI_IRQVEC),
193
+ DEFINE_PROP_UINT64("rnmi-exception-vector", RISCVCPU, env.rnmi_excpvec,
194
+ DEFAULT_RNMI_EXCPVEC),
195
#endif
196
197
DEFINE_PROP_BOOL("short-isa-string", RISCVCPU, cfg.short_isa_string, false),
198
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
199
index XXXXXXX..XXXXXXX 100644
200
--- a/target/riscv/cpu_helper.c
201
+++ b/target/riscv/cpu_helper.c
202
@@ -XXX,XX +XXX,XX @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env)
203
uint64_t vsbits, irq_delegated;
204
int virq;
205
206
+ /* Priority: RNMI > Other interrupt. */
207
+ if (riscv_cpu_cfg(env)->ext_smrnmi) {
208
+ /* If mnstatus.NMIE == 0, all interrupts are disabled. */
209
+ if (!get_field(env->mnstatus, MNSTATUS_NMIE)) {
210
+ return RISCV_EXCP_NONE;
211
+ }
212
+
213
+ if (env->rnmip) {
214
+ return ctz64(env->rnmip); /* since non-zero */
215
+ }
216
+ }
217
+
218
/* Determine interrupt enable state of all privilege modes */
219
if (env->virt_enabled) {
220
mie = 1;
221
@@ -XXX,XX +XXX,XX @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env)
222
223
bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
224
{
225
- if (interrupt_request & CPU_INTERRUPT_HARD) {
226
+ uint32_t mask = CPU_INTERRUPT_HARD | CPU_INTERRUPT_RNMI;
227
+
228
+ if (interrupt_request & mask) {
229
RISCVCPU *cpu = RISCV_CPU(cs);
230
CPURISCVState *env = &cpu->env;
231
int interruptno = riscv_cpu_local_irq_pending(env);
232
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen)
233
env->geilen = geilen;
234
}
235
236
+void riscv_cpu_set_rnmi(RISCVCPU *cpu, uint32_t irq, bool level)
237
+{
238
+ CPURISCVState *env = &cpu->env;
239
+ CPUState *cs = CPU(cpu);
240
+ bool release_lock = false;
241
+
242
+ if (!bql_locked()) {
243
+ release_lock = true;
244
+ bql_lock();
245
+ }
246
+
247
+ if (level) {
248
+ env->rnmip |= 1 << irq;
249
+ cpu_interrupt(cs, CPU_INTERRUPT_RNMI);
250
+ } else {
251
+ env->rnmip &= ~(1 << irq);
252
+ cpu_reset_interrupt(cs, CPU_INTERRUPT_RNMI);
253
+ }
254
+
255
+ if (release_lock) {
256
+ bql_unlock();
257
+ }
258
+}
259
+
260
int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts)
261
{
262
CPURISCVState *env = &cpu->env;
263
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
264
bool write_gva = false;
265
bool always_storeamo = (env->excp_uw2 & RISCV_UW2_ALWAYS_STORE_AMO);
266
uint64_t s;
267
+ int mode;
268
269
/*
270
* cs->exception is 32-bits wide unlike mcause which is XLEN-bits wide
271
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
272
target_ulong htval = 0;
273
target_ulong mtval2 = 0;
274
int sxlen = 0;
275
- int mxlen = 0;
276
+ int mxlen = 16 << riscv_cpu_mxl(env);
277
+ bool nnmi_excep = false;
278
+
279
+ if (cpu->cfg.ext_smrnmi && env->rnmip && async) {
280
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_NMIE, false);
281
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPV,
282
+ env->virt_enabled);
283
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPP,
284
+ env->priv);
285
+ env->mncause = cause | ((target_ulong)1U << (mxlen - 1));
286
+ env->mnepc = env->pc;
287
+ env->pc = env->rnmi_irqvec;
288
+
289
+ /* Trapping to M mode, virt is disabled */
290
+ riscv_cpu_set_mode(env, PRV_M, false);
291
+
90
+ return;
292
+ return;
91
+ }
293
+ }
92
+
294
93
+ GPEX_HOST(obj)->gpex_cfg.irq = irq;
295
if (!async) {
94
+ acpi_dsdt_add_gpex(scope, &GPEX_HOST(obj)->gpex_cfg);
296
/* set tval to badaddr for traps with address information */
95
+}
297
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
96
diff --git a/hw/pci-host/gpex.c b/hw/pci-host/gpex.c
298
__func__, env->mhartid, async, cause, env->pc, tval,
97
index XXXXXXX..XXXXXXX 100644
299
riscv_cpu_get_trap_name(cause, async));
98
--- a/hw/pci-host/gpex.c
300
99
+++ b/hw/pci-host/gpex.c
301
- if (env->priv <= PRV_S && cause < 64 &&
100
@@ -XXX,XX +XXX,XX @@ static Property gpex_host_properties[] = {
302
- (((deleg >> cause) & 1) || s_injected || vs_injected)) {
101
*/
303
+ mode = env->priv <= PRV_S && cause < 64 &&
102
DEFINE_PROP_BOOL("allow-unmapped-accesses", GPEXHost,
304
+ (((deleg >> cause) & 1) || s_injected || vs_injected) ? PRV_S : PRV_M;
103
allow_unmapped_accesses, true),
305
+
104
+ DEFINE_PROP_UINT64(PCI_HOST_ECAM_BASE, GPEXHost, gpex_cfg.ecam.base, 0),
306
+ if (mode == PRV_S) {
105
+ DEFINE_PROP_SIZE(PCI_HOST_ECAM_SIZE, GPEXHost, gpex_cfg.ecam.size, 0),
307
/* handle the trap in S-mode */
106
+ DEFINE_PROP_UINT64(PCI_HOST_PIO_BASE, GPEXHost, gpex_cfg.pio.base, 0),
308
/* save elp status */
107
+ DEFINE_PROP_SIZE(PCI_HOST_PIO_SIZE, GPEXHost, gpex_cfg.pio.size, 0),
309
if (cpu_get_fcfien(env)) {
108
+ DEFINE_PROP_UINT64(PCI_HOST_BELOW_4G_MMIO_BASE, GPEXHost,
310
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
109
+ gpex_cfg.mmio32.base, 0),
311
((async && (env->stvec & 3) == 1) ? cause * 4 : 0);
110
+ DEFINE_PROP_SIZE(PCI_HOST_BELOW_4G_MMIO_SIZE, GPEXHost,
312
riscv_cpu_set_mode(env, PRV_S, virt);
111
+ gpex_cfg.mmio32.size, 0),
313
} else {
112
+ DEFINE_PROP_UINT64(PCI_HOST_ABOVE_4G_MMIO_BASE, GPEXHost,
314
+ /*
113
+ gpex_cfg.mmio64.base, 0),
315
+ * If the hart encounters an exception while executing in M-mode
114
+ DEFINE_PROP_SIZE(PCI_HOST_ABOVE_4G_MMIO_SIZE, GPEXHost,
316
+ * with the mnstatus.NMIE bit clear, the exception is an RNMI exception.
115
+ gpex_cfg.mmio64.size, 0),
317
+ */
116
DEFINE_PROP_END_OF_LIST(),
318
+ nnmi_excep = cpu->cfg.ext_smrnmi &&
117
};
319
+ !get_field(env->mnstatus, MNSTATUS_NMIE) &&
320
+ !async;
321
+
322
/* handle the trap in M-mode */
323
/* save elp status */
324
if (cpu_get_fcfien(env)) {
325
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
326
s = set_field(s, MSTATUS_MPP, env->priv);
327
s = set_field(s, MSTATUS_MIE, 0);
328
env->mstatus = s;
329
- mxlen = 16 << riscv_cpu_mxl(env);
330
env->mcause = cause | ((target_ulong)async << (mxlen - 1));
331
env->mepc = env->pc;
332
env->mtval = tval;
333
env->mtval2 = mtval2;
334
env->mtinst = tinst;
335
- env->pc = (env->mtvec >> 2 << 2) +
336
- ((async && (env->mtvec & 3) == 1) ? cause * 4 : 0);
337
+
338
+ /*
339
+ * For RNMI exception, program counter is set to the RNMI exception
340
+ * trap handler address.
341
+ */
342
+ if (nnmi_excep) {
343
+ env->pc = env->rnmi_excpvec;
344
+ } else {
345
+ env->pc = (env->mtvec >> 2 << 2) +
346
+ ((async && (env->mtvec & 3) == 1) ? cause * 4 : 0);
347
+ }
348
riscv_cpu_set_mode(env, PRV_M, virt);
349
}
118
350
119
--
351
--
120
2.43.0
352
2.48.1
353
354
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Tommy Wu <tommy.wu@sifive.com>
2
2
3
The TCG emulation implements all the extensions described in the
3
This patch adds a new instruction 'mnret'. 'mnret' is an M-mode-only
4
RVA22U64 profile, both mandatory and optional. The mandatory extensions
4
instruction that uses the values in `mnepc` and `mnstatus` to return to the
5
will be enabled via the profile flag. We'll leave the optional
5
program counter, privilege mode, and virtualization mode of the
6
extensions to be enabled by hand.
6
interrupted context.
7
7
8
Given that this is the first profile we're implementing in TCG we'll
8
Signed-off-by: Frank Chang <frank.chang@sifive.com>
9
need some ground work first:
9
Signed-off-by: Tommy Wu <tommy.wu@sifive.com>
10
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
- all profiles declared in riscv_profiles[] will be exposed to users.
12
TCG is the main accelerator we're considering when adding profile
13
support in QEMU, so for now it's safe to assume that all profiles in
14
riscv_profiles[] will be relevant to TCG;
15
16
- we'll not support user profile settings for vendor CPUs. The flags
17
will still be exposed but users won't be able to change them;
18
19
- profile support, albeit available for all non-vendor CPUs, will be
20
based on top of the new 'rv64i' CPU. Setting a profile to 'true' means
21
enable all mandatory extensions of this profile, setting it to 'false'
22
will disable all mandatory profile extensions of the CPU, which will
23
obliterate preset defaults. This is not a problem for a bare CPU like
24
rv64i but it can allow for silly scenarios when using other CPUs. E.g.
25
an user can do "-cpu rv64,rva22u64=false" and have a bunch of default
26
rv64 extensions disabled. The recommended way of using profiles is the
27
rv64i CPU, but users are free to experiment.
28
29
For now we'll handle multi-letter extensions only. MISA extensions need
30
additional steps that we'll take care later. At this point we can boot a
31
Linux buildroot using rva22u64 using the following options:
32
33
-cpu rv64i,rva22u64=true,sv39=true,g=true,c=true,s=true
34
35
Note that being an usermode/application profile we still need to
36
explicitly set 's=true' to enable Supervisor mode to boot Linux.
37
38
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
39
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
40
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
41
Message-ID: <20231218125334.37184-11-dbarboza@ventanamicro.com>
12
Message-ID: <20250106054336.1878291-5-frank.chang@sifive.com>
42
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
43
---
14
---
44
target/riscv/tcg/tcg-cpu.c | 80 ++++++++++++++++++++++++++++++++++++++
15
target/riscv/helper.h | 1 +
45
1 file changed, 80 insertions(+)
16
target/riscv/insn32.decode | 3 ++
17
target/riscv/op_helper.c | 45 ++++++++++++++++---
18
.../riscv/insn_trans/trans_privileged.c.inc | 20 +++++++++
19
4 files changed, 64 insertions(+), 5 deletions(-)
46
20
47
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
21
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
48
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
49
--- a/target/riscv/tcg/tcg-cpu.c
23
--- a/target/riscv/helper.h
50
+++ b/target/riscv/tcg/tcg-cpu.c
24
+++ b/target/riscv/helper.h
51
@@ -XXX,XX +XXX,XX @@ static bool cpu_cfg_offset_is_named_feat(uint32_t ext_offset)
25
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl)
52
return false;
26
#ifndef CONFIG_USER_ONLY
27
DEF_HELPER_1(sret, tl, env)
28
DEF_HELPER_1(mret, tl, env)
29
+DEF_HELPER_1(mnret, tl, env)
30
DEF_HELPER_1(wfi, void, env)
31
DEF_HELPER_1(wrs_nto, void, env)
32
DEF_HELPER_1(tlb_flush, void, env)
33
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/riscv/insn32.decode
36
+++ b/target/riscv/insn32.decode
37
@@ -XXX,XX +XXX,XX @@ wfi 0001000 00101 00000 000 00000 1110011
38
sfence_vma 0001001 ..... ..... 000 00000 1110011 @sfence_vma
39
sfence_vm 0001000 00100 ..... 000 00000 1110011 @sfence_vm
40
41
+# *** NMI ***
42
+mnret 0111000 00010 00000 000 00000 1110011
43
+
44
# *** RV32I Base Instruction Set ***
45
lui .................... ..... 0110111 @u
46
{
47
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/target/riscv/op_helper.c
50
+++ b/target/riscv/op_helper.c
51
@@ -XXX,XX +XXX,XX @@ target_ulong helper_sret(CPURISCVState *env)
52
return retpc;
53
}
53
}
54
54
55
+static void riscv_cpu_enable_named_feat(RISCVCPU *cpu, uint32_t feat_offset)
55
-target_ulong helper_mret(CPURISCVState *env)
56
+{
56
+static void check_ret_from_m_mode(CPURISCVState *env, target_ulong retpc,
57
+ switch (feat_offset) {
57
+ target_ulong prev_priv)
58
+ case CPU_CFG_OFFSET(zic64b):
58
{
59
+ cpu->cfg.cbom_blocksize = 64;
59
if (!(env->priv >= PRV_M)) {
60
+ cpu->cfg.cbop_blocksize = 64;
60
riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
61
+ cpu->cfg.cboz_blocksize = 64;
61
}
62
+ break;
62
63
+ default:
63
- target_ulong retpc = env->mepc;
64
+ g_assert_not_reached();
64
if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) {
65
+ }
65
riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
66
}
67
68
- uint64_t mstatus = env->mstatus;
69
- target_ulong prev_priv = get_field(mstatus, MSTATUS_MPP);
70
-
71
if (riscv_cpu_cfg(env)->pmp &&
72
!pmp_get_num_rules(env) && (prev_priv != PRV_M)) {
73
riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
74
}
66
+}
75
+}
67
+
76
+
68
static void cpu_bump_multi_ext_priv_ver(CPURISCVState *env,
77
+target_ulong helper_mret(CPURISCVState *env)
69
uint32_t ext_offset)
78
+{
70
{
79
+ target_ulong retpc = env->mepc;
71
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
80
+ uint64_t mstatus = env->mstatus;
72
}
81
+ target_ulong prev_priv = get_field(mstatus, MSTATUS_MPP);
82
+
83
+ check_ret_from_m_mode(env, retpc, prev_priv);
84
85
target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV) &&
86
(prev_priv != PRV_M);
87
@@ -XXX,XX +XXX,XX @@ target_ulong helper_mret(CPURISCVState *env)
88
return retpc;
73
}
89
}
74
90
75
+static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
91
+target_ulong helper_mnret(CPURISCVState *env)
76
+ void *opaque, Error **errp)
77
+{
92
+{
78
+ RISCVCPUProfile *profile = opaque;
93
+ target_ulong retpc = env->mnepc;
79
+ RISCVCPU *cpu = RISCV_CPU(obj);
94
+ target_ulong prev_priv = get_field(env->mnstatus, MNSTATUS_MNPP);
80
+ bool value;
95
+ target_ulong prev_virt;
81
+ int i, ext_offset;
82
+
96
+
83
+ if (riscv_cpu_is_vendor(obj)) {
97
+ check_ret_from_m_mode(env, retpc, prev_priv);
84
+ error_setg(errp, "Profile %s is not available for vendor CPUs",
98
+
85
+ profile->name);
99
+ prev_virt = get_field(env->mnstatus, MNSTATUS_MNPV) &&
86
+ return;
100
+ (prev_priv != PRV_M);
101
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_NMIE, true);
102
+
103
+ /*
104
+ * If MNRET changes the privilege mode to a mode
105
+ * less privileged than M, it also sets mstatus.MPRV to 0.
106
+ */
107
+ if (prev_priv < PRV_M) {
108
+ env->mstatus = set_field(env->mstatus, MSTATUS_MPRV, false);
87
+ }
109
+ }
88
+
110
+
89
+ if (cpu->env.misa_mxl != MXL_RV64) {
111
+ if (riscv_has_ext(env, RVH) && prev_virt) {
90
+ error_setg(errp, "Profile %s only available for 64 bit CPUs",
112
+ riscv_cpu_swap_hypervisor_regs(env);
91
+ profile->name);
92
+ return;
93
+ }
113
+ }
94
+
114
+
95
+ if (!visit_type_bool(v, name, &value, errp)) {
115
+ riscv_cpu_set_mode(env, prev_priv, prev_virt);
96
+ return;
97
+ }
98
+
116
+
99
+ profile->user_set = true;
117
+ return retpc;
100
+ profile->enabled = value;
101
+
102
+ for (i = 0; profile->ext_offsets[i] != RISCV_PROFILE_EXT_LIST_END; i++) {
103
+ ext_offset = profile->ext_offsets[i];
104
+
105
+ if (profile->enabled) {
106
+ if (cpu_cfg_offset_is_named_feat(ext_offset)) {
107
+ riscv_cpu_enable_named_feat(cpu, ext_offset);
108
+ }
109
+
110
+ cpu_bump_multi_ext_priv_ver(&cpu->env, ext_offset);
111
+ }
112
+
113
+ g_hash_table_insert(multi_ext_user_opts,
114
+ GUINT_TO_POINTER(ext_offset),
115
+ (gpointer)profile->enabled);
116
+ isa_ext_update_enabled(cpu, ext_offset, profile->enabled);
117
+ }
118
+}
118
+}
119
+
119
+
120
+static void cpu_get_profile(Object *obj, Visitor *v, const char *name,
120
void helper_wfi(CPURISCVState *env)
121
+ void *opaque, Error **errp)
121
{
122
CPUState *cs = env_cpu(env);
123
diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
124
index XXXXXXX..XXXXXXX 100644
125
--- a/target/riscv/insn_trans/trans_privileged.c.inc
126
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
127
@@ -XXX,XX +XXX,XX @@
128
* this program. If not, see <http://www.gnu.org/licenses/>.
129
*/
130
131
+#define REQUIRE_SMRNMI(ctx) do { \
132
+ if (!ctx->cfg_ptr->ext_smrnmi) { \
133
+ return false; \
134
+ } \
135
+} while (0)
136
+
137
static bool trans_ecall(DisasContext *ctx, arg_ecall *a)
138
{
139
/* always generates U-level ECALL, fixed in do_interrupt handler */
140
@@ -XXX,XX +XXX,XX @@ static bool trans_mret(DisasContext *ctx, arg_mret *a)
141
#endif
142
}
143
144
+static bool trans_mnret(DisasContext *ctx, arg_mnret *a)
122
+{
145
+{
123
+ RISCVCPUProfile *profile = opaque;
146
+#ifndef CONFIG_USER_ONLY
124
+ bool value = profile->enabled;
147
+ REQUIRE_SMRNMI(ctx);
125
+
148
+ decode_save_opc(ctx, 0);
126
+ visit_type_bool(v, name, &value, errp);
149
+ gen_helper_mnret(cpu_pc, tcg_env);
150
+ tcg_gen_exit_tb(NULL, 0); /* no chaining */
151
+ ctx->base.is_jmp = DISAS_NORETURN;
152
+ return true;
153
+#else
154
+ return false;
155
+#endif
127
+}
156
+}
128
+
157
+
129
+static void riscv_cpu_add_profiles(Object *cpu_obj)
158
static bool trans_wfi(DisasContext *ctx, arg_wfi *a)
130
+{
131
+ for (int i = 0; riscv_profiles[i] != NULL; i++) {
132
+ const RISCVCPUProfile *profile = riscv_profiles[i];
133
+
134
+ object_property_add(cpu_obj, profile->name, "bool",
135
+ cpu_get_profile, cpu_set_profile,
136
+ NULL, (void *)profile);
137
+ }
138
+}
139
+
140
static bool cpu_ext_is_deprecated(const char *ext_name)
141
{
159
{
142
return isupper(ext_name[0]);
160
#ifndef CONFIG_USER_ONLY
143
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
144
145
riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_deprecated_exts);
146
147
+ riscv_cpu_add_profiles(obj);
148
+
149
for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {
150
qdev_property_add_static(DEVICE(obj), prop);
151
}
152
--
161
--
153
2.43.0
162
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Tommy Wu <tommy.wu@sifive.com>
2
2
3
This CPU was suggested by Alistair [1] and others during the profile
3
This adds the properties for ISA extension Smrnmi.
4
design discussions. It consists of the bare 'rv64i' CPU with rva22u64
5
enabled by default, like an alias of '-cpu rv64i,rva22u64=true'.
6
4
7
Users now have an even easier way of consuming this user-mode profile by
5
Also, when Smrnmi is present, the firmware (e.g., OpenSBI) must set
8
doing '-cpu rva22u64'. Extensions can be enabled/disabled at will on top
6
mnstatus.NMIE to 1 before enabling any interrupts. Otherwise, all
9
of it.
7
interrupts will be disabled. Since our current OpenSBI does not
8
support Smrnmi yet, let's disable Smrnmi for the 'max' type CPU for
9
now. We can re-enable it once OpenSBI includes proper support for it.
10
10
11
We can boot Linux with this "user-mode" CPU by doing:
11
Signed-off-by: Frank Chang <frank.chang@sifive.com>
12
12
Signed-off-by: Tommy Wu <tommy.wu@sifive.com>
13
-cpu rva22u64,sv39=true,s=true,zifencei=true
14
15
[1] https://lore.kernel.org/qemu-riscv/CAKmqyKP7xzZ9Sx=-Lbx2Ob0qCfB7Z+JO944FQ2TQ+49mqo0q_Q@mail.gmail.com/
16
17
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
18
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
14
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
19
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Message-ID: <20231218125334.37184-19-dbarboza@ventanamicro.com>
16
Message-ID: <20250106054336.1878291-6-frank.chang@sifive.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
---
18
---
23
target/riscv/cpu-qom.h | 1 +
19
target/riscv/cpu.c | 2 ++
24
target/riscv/cpu.c | 17 +++++++++++++++++
20
target/riscv/tcg/tcg-cpu.c | 9 +++++++++
25
target/riscv/tcg/tcg-cpu.c | 9 +++++++++
21
2 files changed, 11 insertions(+)
26
3 files changed, 27 insertions(+)
27
22
28
diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/riscv/cpu-qom.h
31
+++ b/target/riscv/cpu-qom.h
32
@@ -XXX,XX +XXX,XX @@
33
#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64")
34
#define TYPE_RISCV_CPU_BASE128 RISCV_CPU_TYPE_NAME("x-rv128")
35
#define TYPE_RISCV_CPU_RV64I RISCV_CPU_TYPE_NAME("rv64i")
36
+#define TYPE_RISCV_CPU_RVA22U64 RISCV_CPU_TYPE_NAME("rva22u64")
37
#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")
38
#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")
39
#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")
40
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
23
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
41
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
42
--- a/target/riscv/cpu.c
25
--- a/target/riscv/cpu.c
43
+++ b/target/riscv/cpu.c
26
+++ b/target/riscv/cpu.c
44
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = {
27
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
45
DEFINE_PROP_END_OF_LIST(),
28
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
46
};
29
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
47
30
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
48
+#if defined(TARGET_RISCV64)
31
+ ISA_EXT_DATA_ENTRY(smrnmi, PRIV_VERSION_1_12_0, ext_smrnmi),
49
+static void rva22u64_profile_cpu_init(Object *obj)
32
ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm),
50
+{
33
ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm),
51
+ rv64i_bare_cpu_init(obj);
34
ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen),
52
+
35
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
53
+ RVA22U64.enabled = true;
36
54
+}
37
MULTI_EXT_CFG_BOOL("smaia", ext_smaia, false),
55
+#endif
38
MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false),
56
+
39
+ MULTI_EXT_CFG_BOOL("smrnmi", ext_smrnmi, false),
57
static const gchar *riscv_gdb_arch_name(CPUState *cs)
40
MULTI_EXT_CFG_BOOL("smmpm", ext_smmpm, false),
58
{
41
MULTI_EXT_CFG_BOOL("smnpm", ext_smnpm, false),
59
RISCVCPU *cpu = RISCV_CPU(cs);
42
MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false),
60
@@ -XXX,XX +XXX,XX @@ char *riscv_isa_string(RISCVCPU *cpu)
61
.instance_init = initfn \
62
}
63
64
+#define DEFINE_PROFILE_CPU(type_name, initfn) \
65
+ { \
66
+ .name = type_name, \
67
+ .parent = TYPE_RISCV_BARE_CPU, \
68
+ .instance_init = initfn \
69
+ }
70
+
71
static const TypeInfo riscv_cpu_type_infos[] = {
72
{
73
.name = TYPE_RISCV_CPU,
74
@@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = {
75
DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_VEYRON_V1, rv64_veyron_v1_cpu_init),
76
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE128, rv128_base_cpu_init),
77
DEFINE_BARE_CPU(TYPE_RISCV_CPU_RV64I, rv64i_bare_cpu_init),
78
+ DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA22U64, rva22u64_profile_cpu_init),
79
#endif
80
};
81
82
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
43
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
83
index XXXXXXX..XXXXXXX 100644
44
index XXXXXXX..XXXXXXX 100644
84
--- a/target/riscv/tcg/tcg-cpu.c
45
--- a/target/riscv/tcg/tcg-cpu.c
85
+++ b/target/riscv/tcg/tcg-cpu.c
46
+++ b/target/riscv/tcg/tcg-cpu.c
86
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_profiles(Object *cpu_obj)
47
@@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj)
87
object_property_add(cpu_obj, profile->name, "bool",
48
if (env->misa_mxl != MXL_RV32) {
88
cpu_get_profile, cpu_set_profile,
49
isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcf), false);
89
NULL, (void *)profile);
50
}
90
+
51
+
91
+ /*
52
+ /*
92
+ * CPUs might enable a profile right from the start.
53
+ * ext_smrnmi requires OpenSBI changes that our current
93
+ * Enable its mandatory extensions right away in this
54
+ * image does not have. Disable it for now.
94
+ * case.
55
+ */
95
+ */
56
+ if (cpu->cfg.ext_smrnmi) {
96
+ if (profile->enabled) {
57
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_smrnmi), false);
97
+ object_property_set_bool(cpu_obj, profile->name, true, NULL);
58
+ qemu_log("Smrnmi is disabled in the 'max' type CPU\n");
98
+ }
59
+ }
99
}
100
}
60
}
101
61
62
static bool riscv_cpu_has_max_extensions(Object *cpu_obj)
102
--
63
--
103
2.43.0
64
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Frank Chang <frank.chang@sifive.com>
2
2
3
We'll add a new bare CPU type that won't have any default priv_ver. This
3
Zicfilp extension introduces the MNPELP (bit 9) in mnstatus.
4
means that the CPU will default to priv_ver = 0, i.e. 1.10.0.
4
The MNPELP field holds the previous ELP.
5
5
6
At the same we'll allow these CPUs to enable extensions at will, but
6
When a RNMI trap is delivered, the MNPELP is set to ELP and ELP set
7
then, if the extension has a priv_ver newer than 1.10, we'll end up
7
to NO_LP_EXPECTED. Upon a mnret, if the mnstatus.MNPP holds the
8
disabling it. Users will then need to manually set priv_ver to something
8
value y, then ELP is set to the value of MNPELP if yLPE is 1;
9
other than 1.10 to enable the extensions they want, which is not ideal.
9
otherwise, it is set to NO_LP_EXPECTED.
10
10
11
Change the setter() of extensions to allow user enabled extensions to
11
Signed-off-by: Frank Chang <frank.chang@sifive.com>
12
bump the priv_ver of the CPU. This will make it convenient for users to
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
enable extensions for CPUs that doesn't set a default priv_ver.
14
15
This change does not affect any existing CPU: vendor CPUs does not allow
16
extensions to be enabled, and generic CPUs are already set to priv_ver
17
LATEST.
18
19
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
20
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
21
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
22
Message-ID: <20231218125334.37184-4-dbarboza@ventanamicro.com>
14
Message-ID: <20250106054336.1878291-7-frank.chang@sifive.com>
23
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
24
---
16
---
25
target/riscv/tcg/tcg-cpu.c | 32 ++++++++++++++++++++++++++++++++
17
target/riscv/cpu_bits.h | 1 +
26
1 file changed, 32 insertions(+)
18
target/riscv/cpu_helper.c | 11 ++++++++++-
19
target/riscv/op_helper.c | 9 +++++++++
20
3 files changed, 20 insertions(+), 1 deletion(-)
27
21
28
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
22
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
29
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
30
--- a/target/riscv/tcg/tcg-cpu.c
24
--- a/target/riscv/cpu_bits.h
31
+++ b/target/riscv/tcg/tcg-cpu.c
25
+++ b/target/riscv/cpu_bits.h
32
@@ -XXX,XX +XXX,XX @@ static int cpu_cfg_ext_get_min_version(uint32_t ext_offset)
26
@@ -XXX,XX +XXX,XX @@ typedef enum {
33
g_assert_not_reached();
27
/* RNMI mnstatus CSR mask */
34
}
28
#define MNSTATUS_NMIE 0x00000008
35
29
#define MNSTATUS_MNPV 0x00000080
36
+static void cpu_bump_multi_ext_priv_ver(CPURISCVState *env,
30
+#define MNSTATUS_MNPELP 0x00000200
37
+ uint32_t ext_offset)
31
#define MNSTATUS_MNPP 0x00001800
38
+{
32
39
+ int ext_priv_ver;
33
/* VM modes (satp.mode) privileged ISA 1.10 */
40
+
34
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
41
+ if (env->priv_ver == PRIV_VERSION_LATEST) {
35
index XXXXXXX..XXXXXXX 100644
42
+ return;
36
--- a/target/riscv/cpu_helper.c
43
+ }
37
+++ b/target/riscv/cpu_helper.c
44
+
38
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
45
+ ext_priv_ver = cpu_cfg_ext_get_min_version(ext_offset);
39
env->mnepc = env->pc;
46
+
40
env->pc = env->rnmi_irqvec;
47
+ if (env->priv_ver < ext_priv_ver) {
41
48
+ /*
42
+ if (cpu_get_fcfien(env)) {
49
+ * Note: the 'priv_spec' command line option, if present,
43
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPELP, env->elp);
50
+ * will take precedence over this priv_ver bump.
51
+ */
52
+ env->priv_ver = ext_priv_ver;
53
+ }
54
+}
55
+
56
static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset,
57
bool value)
58
{
59
@@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
60
return;
61
}
62
63
+ if (misa_bit == RVH && env->priv_ver < PRIV_VERSION_1_12_0) {
64
+ /*
65
+ * Note: the 'priv_spec' command line option, if present,
66
+ * will take precedence over this priv_ver bump.
67
+ */
68
+ env->priv_ver = PRIV_VERSION_1_12_0;
69
+ }
44
+ }
70
+
45
+
71
env->misa_ext |= misa_bit;
46
/* Trapping to M mode, virt is disabled */
72
env->misa_ext_mask |= misa_bit;
47
riscv_cpu_set_mode(env, PRV_M, false);
73
} else {
48
74
@@ -XXX,XX +XXX,XX @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
49
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
75
return;
50
/* handle the trap in M-mode */
76
}
51
/* save elp status */
77
52
if (cpu_get_fcfien(env)) {
78
+ if (value) {
53
- env->mstatus = set_field(env->mstatus, MSTATUS_MPELP, env->elp);
79
+ cpu_bump_multi_ext_priv_ver(&cpu->env, multi_ext_cfg->offset);
54
+ if (nnmi_excep) {
55
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPELP,
56
+ env->elp);
57
+ } else {
58
+ env->mstatus = set_field(env->mstatus, MSTATUS_MPELP, env->elp);
59
+ }
60
}
61
62
if (riscv_has_ext(env, RVH)) {
63
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
64
index XXXXXXX..XXXXXXX 100644
65
--- a/target/riscv/op_helper.c
66
+++ b/target/riscv/op_helper.c
67
@@ -XXX,XX +XXX,XX @@ target_ulong helper_mnret(CPURISCVState *env)
68
69
riscv_cpu_set_mode(env, prev_priv, prev_virt);
70
71
+ /*
72
+ * If forward cfi enabled for new priv, restore elp status
73
+ * and clear mnpelp in mnstatus
74
+ */
75
+ if (cpu_get_fcfien(env)) {
76
+ env->elp = get_field(env->mnstatus, MNSTATUS_MNPELP);
80
+ }
77
+ }
78
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPELP, 0);
81
+
79
+
82
isa_ext_update_enabled(cpu, multi_ext_cfg->offset, value);
80
return retpc;
83
}
81
}
84
82
85
--
83
--
86
2.43.0
84
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
KVM_REG_RISCV_FP_F regs have u32 size according to the API, but by using
3
Keep kvm_riscv_get_timebase_frequency() prototype aligned with
4
kvm_riscv_reg_id() in RISCV_FP_F_REG() we're returning u64 sizes when
4
the other ones declared in "kvm_riscv.h", have it take a RISCVCPU
5
running with TARGET_RISCV64. The most likely reason why no one noticed
5
cpu as argument. Include "target/riscv/cpu-qom.h" which declares
6
this is because we're not implementing kvm_cpu_synchronize_state() in
6
the RISCVCPU typedef.
7
RISC-V yet.
8
7
9
Create a new helper that returns a KVM ID with u32 size and use it in
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
10
RISCV_FP_F_REG().
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
10
Message-ID: <20250112231344.34632-2-philmd@linaro.org>
12
Reported-by: Andrew Jones <ajones@ventanamicro.com>
13
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
14
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
15
Message-ID: <20231208183835.2411523-2-dbarboza@ventanamicro.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
12
---
18
target/riscv/kvm/kvm-cpu.c | 11 ++++++++---
13
target/riscv/kvm/kvm_riscv.h | 4 +++-
19
1 file changed, 8 insertions(+), 3 deletions(-)
14
hw/riscv/virt.c | 2 +-
15
target/riscv/kvm/kvm-cpu.c | 4 ++--
16
3 files changed, 6 insertions(+), 4 deletions(-)
20
17
18
diff --git a/target/riscv/kvm/kvm_riscv.h b/target/riscv/kvm/kvm_riscv.h
19
index XXXXXXX..XXXXXXX 100644
20
--- a/target/riscv/kvm/kvm_riscv.h
21
+++ b/target/riscv/kvm/kvm_riscv.h
22
@@ -XXX,XX +XXX,XX @@
23
#ifndef QEMU_KVM_RISCV_H
24
#define QEMU_KVM_RISCV_H
25
26
+#include "target/riscv/cpu-qom.h"
27
+
28
void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
29
void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level);
30
void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
31
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
32
void riscv_kvm_aplic_request(void *opaque, int irq, int level);
33
int kvm_riscv_sync_mpstate_to_kvm(RISCVCPU *cpu, int state);
34
void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
35
-uint64_t kvm_riscv_get_timebase_frequency(CPUState *cs);
36
+uint64_t kvm_riscv_get_timebase_frequency(RISCVCPU *cpu);
37
38
#endif
39
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
40
index XXXXXXX..XXXXXXX 100644
41
--- a/hw/riscv/virt.c
42
+++ b/hw/riscv/virt.c
43
@@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap,
44
qemu_fdt_add_subnode(ms->fdt, "/cpus");
45
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "timebase-frequency",
46
kvm_enabled() ?
47
- kvm_riscv_get_timebase_frequency(first_cpu) :
48
+ kvm_riscv_get_timebase_frequency(RISCV_CPU(first_cpu)) :
49
RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ);
50
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0);
51
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1);
21
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
52
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
22
index XXXXXXX..XXXXXXX 100644
53
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/kvm/kvm-cpu.c
54
--- a/target/riscv/kvm/kvm-cpu.c
24
+++ b/target/riscv/kvm/kvm-cpu.c
55
+++ b/target/riscv/kvm/kvm-cpu.c
25
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type,
56
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_put_regs_timer(CPUState *cs)
26
return id;
57
env->kvm_timer_dirty = false;
27
}
58
}
28
59
29
+static uint64_t kvm_riscv_reg_id_u32(uint64_t type, uint64_t idx)
60
-uint64_t kvm_riscv_get_timebase_frequency(CPUState *cs)
30
+{
61
+uint64_t kvm_riscv_get_timebase_frequency(RISCVCPU *cpu)
31
+ return KVM_REG_RISCV | KVM_REG_SIZE_U32 | type | idx;
62
{
32
+}
63
uint64_t reg;
33
+
64
34
#define RISCV_CORE_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CORE, \
65
- KVM_RISCV_GET_TIMER(cs, frequency, reg);
35
KVM_REG_RISCV_CORE_REG(name))
66
+ KVM_RISCV_GET_TIMER(CPU(cpu), frequency, reg);
36
67
37
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type,
68
return reg;
38
#define RISCV_TIMER_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_TIMER, \
69
}
39
KVM_REG_RISCV_TIMER_REG(name))
40
41
-#define RISCV_FP_F_REG(env, idx) kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_F, idx)
42
+#define RISCV_FP_F_REG(idx) kvm_riscv_reg_id_u32(KVM_REG_RISCV_FP_F, idx)
43
44
#define RISCV_FP_D_REG(env, idx) kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_D, idx)
45
46
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_get_regs_fp(CPUState *cs)
47
if (riscv_has_ext(env, RVF)) {
48
uint32_t reg;
49
for (i = 0; i < 32; i++) {
50
- ret = kvm_get_one_reg(cs, RISCV_FP_F_REG(env, i), &reg);
51
+ ret = kvm_get_one_reg(cs, RISCV_FP_F_REG(i), &reg);
52
if (ret) {
53
return ret;
54
}
55
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_put_regs_fp(CPUState *cs)
56
uint32_t reg;
57
for (i = 0; i < 32; i++) {
58
reg = env->fpr[i];
59
- ret = kvm_set_one_reg(cs, RISCV_FP_F_REG(env, i), &reg);
60
+ ret = kvm_set_one_reg(cs, RISCV_FP_F_REG(i), &reg);
61
if (ret) {
62
return ret;
63
}
64
--
70
--
65
2.43.0
71
2.48.1
72
73
diff view generated by jsdifflib
1
From: Yong-Xuan Wang <yongxuan.wang@sifive.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The interrupts-extended property of PLIC only has 2 * hart number
3
virt_machine_init() creates the HARTs vCPUs, then later
4
fields when KVM enabled, copy 4 * hart number fields to fdt will
4
virt_machine_done() calls create_fdt_sockets(), so the
5
expose some uninitialized value.
5
latter has access to the first vCPU via:
6
6
7
In this patch, I also refactor the code about the setting of
7
RISCVVirtState {
8
interrupts-extended property of PLIC for improved readability.
8
RISCVHartArrayState {
9
RISCVCPU *harts;
10
...
9
11
10
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
12
} soc[VIRT_SOCKETS_MAX];
11
Reviewed-by: Jim Shu <jim.shu@sifive.com>
13
...
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
14
13
Message-ID: <20231218090543.22353-1-yongxuan.wang@sifive.com>
15
} s;
16
17
Directly use that instead of the &first_cpu global.
18
19
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
20
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
21
Message-ID: <20250112231344.34632-3-philmd@linaro.org>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
23
---
16
hw/riscv/virt.c | 47 +++++++++++++++++++++++++++--------------------
24
hw/riscv/virt.c | 2 +-
17
1 file changed, 27 insertions(+), 20 deletions(-)
25
1 file changed, 1 insertion(+), 1 deletion(-)
18
26
19
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
27
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
20
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/riscv/virt.c
29
--- a/hw/riscv/virt.c
22
+++ b/hw/riscv/virt.c
30
+++ b/hw/riscv/virt.c
23
@@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_plic(RISCVVirtState *s,
31
@@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap,
24
"sifive,plic-1.0.0", "riscv,plic0"
32
qemu_fdt_add_subnode(ms->fdt, "/cpus");
25
};
33
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "timebase-frequency",
26
34
kvm_enabled() ?
27
- if (kvm_enabled()) {
35
- kvm_riscv_get_timebase_frequency(RISCV_CPU(first_cpu)) :
28
- plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 2);
36
+ kvm_riscv_get_timebase_frequency(&s->soc->harts[0]) :
29
- } else {
37
RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ);
30
- plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 4);
38
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0);
31
- }
39
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1);
32
-
33
- for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) {
34
- if (kvm_enabled()) {
35
- plic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]);
36
- plic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT);
37
- } else {
38
- plic_cells[cpu * 4 + 0] = cpu_to_be32(intc_phandles[cpu]);
39
- plic_cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_EXT);
40
- plic_cells[cpu * 4 + 2] = cpu_to_be32(intc_phandles[cpu]);
41
- plic_cells[cpu * 4 + 3] = cpu_to_be32(IRQ_S_EXT);
42
- }
43
- }
44
-
45
plic_phandles[socket] = (*phandle)++;
46
plic_addr = memmap[VIRT_PLIC].base + (memmap[VIRT_PLIC].size * socket);
47
plic_name = g_strdup_printf("/soc/plic@%lx", plic_addr);
48
@@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_plic(RISCVVirtState *s,
49
(char **)&plic_compat,
50
ARRAY_SIZE(plic_compat));
51
qemu_fdt_setprop(ms->fdt, plic_name, "interrupt-controller", NULL, 0);
52
- qemu_fdt_setprop(ms->fdt, plic_name, "interrupts-extended",
53
- plic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 4);
54
+
55
+ if (kvm_enabled()) {
56
+ plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 2);
57
+
58
+ for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) {
59
+ plic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]);
60
+ plic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT);
61
+ }
62
+
63
+ qemu_fdt_setprop(ms->fdt, plic_name, "interrupts-extended",
64
+ plic_cells,
65
+ s->soc[socket].num_harts * sizeof(uint32_t) * 2);
66
+ } else {
67
+ plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 4);
68
+
69
+ for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) {
70
+ plic_cells[cpu * 4 + 0] = cpu_to_be32(intc_phandles[cpu]);
71
+ plic_cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_EXT);
72
+ plic_cells[cpu * 4 + 2] = cpu_to_be32(intc_phandles[cpu]);
73
+ plic_cells[cpu * 4 + 3] = cpu_to_be32(IRQ_S_EXT);
74
+ }
75
+
76
+ qemu_fdt_setprop(ms->fdt, plic_name, "interrupts-extended",
77
+ plic_cells,
78
+ s->soc[socket].num_harts * sizeof(uint32_t) * 4);
79
+ }
80
+
81
qemu_fdt_setprop_cells(ms->fdt, plic_name, "reg",
82
0x0, plic_addr, 0x0, memmap[VIRT_PLIC].size);
83
qemu_fdt_setprop_cell(ms->fdt, plic_name, "riscv,ndev",
84
--
40
--
85
2.43.0
41
2.48.1
42
43
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Kaiwen Xue <kaiwenx@rivosinc.com>
2
2
3
QEMU already implements zicbom (Cache Block Management Operations) and
3
This adds the properties for sxcsrind. Definitions of new registers and
4
zicboz (Cache Block Zero Operations). Commit 59cb29d6a5 ("target/riscv:
4
implementations will come with future patches.
5
add Zicbop cbo.prefetch{i, r, m} placeholder") added placeholders for
6
what would be the instructions for zicbop (Cache Block Prefetch
7
Operations), which are now no-ops.
8
5
9
The RVA22U64 profile mandates zicbop, which means that applications that
6
Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com>
10
run with this profile might expect zicbop to be present in the riscv,isa
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
DT and might behave badly if it's absent.
8
Acked-by: Alistair Francis <alistair.francis@wdc.com>
12
9
Signed-off-by: Atish Patra <atishp@rivosinc.com>
13
Adding zicbop as an extension will make our future RVA22U64
10
Message-ID: <20250110-counter_delegation-v5-1-e83d797ae294@rivosinc.com>
14
implementation more in line with what userspace expects and, if/when
15
cache block prefetch operations became relevant to QEMU, we already have
16
the extension flag to turn then on/off as needed.
17
18
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
19
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
20
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
21
Message-ID: <20231218125334.37184-6-dbarboza@ventanamicro.com>
22
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
23
---
12
---
24
target/riscv/cpu_cfg.h | 2 ++
13
target/riscv/cpu_cfg.h | 2 ++
25
hw/riscv/virt.c | 5 +++++
14
target/riscv/cpu.c | 2 ++
26
target/riscv/cpu.c | 3 +++
15
2 files changed, 4 insertions(+)
27
3 files changed, 10 insertions(+)
28
16
29
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
17
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
30
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/cpu_cfg.h
19
--- a/target/riscv/cpu_cfg.h
32
+++ b/target/riscv/cpu_cfg.h
20
+++ b/target/riscv/cpu_cfg.h
33
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
21
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
34
bool ext_zicntr;
22
bool ext_smstateen;
35
bool ext_zicsr;
23
bool ext_sstc;
36
bool ext_zicbom;
24
bool ext_smcntrpmf;
37
+ bool ext_zicbop;
25
+ bool ext_smcsrind;
38
bool ext_zicboz;
26
+ bool ext_sscsrind;
39
bool ext_zicond;
27
bool ext_svadu;
40
bool ext_zihintntl;
28
bool ext_svinval;
41
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
29
bool ext_svnapot;
42
uint16_t vlen;
43
uint16_t elen;
44
uint16_t cbom_blocksize;
45
+ uint16_t cbop_blocksize;
46
uint16_t cboz_blocksize;
47
bool mmu;
48
bool pmp;
49
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/hw/riscv/virt.c
52
+++ b/hw/riscv/virt.c
53
@@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket,
54
cpu_ptr->cfg.cboz_blocksize);
55
}
56
57
+ if (cpu_ptr->cfg.ext_zicbop) {
58
+ qemu_fdt_setprop_cell(ms->fdt, cpu_name, "riscv,cbop-block-size",
59
+ cpu_ptr->cfg.cbop_blocksize);
60
+ }
61
+
62
qemu_fdt_setprop_string(ms->fdt, cpu_name, "compatible", "riscv");
63
qemu_fdt_setprop_string(ms->fdt, cpu_name, "status", "okay");
64
qemu_fdt_setprop_cell(ms->fdt, cpu_name, "reg",
65
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
30
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
66
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
67
--- a/target/riscv/cpu.c
32
--- a/target/riscv/cpu.c
68
+++ b/target/riscv/cpu.c
33
+++ b/target/riscv/cpu.c
69
@@ -XXX,XX +XXX,XX @@ const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV,
34
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
70
*/
35
ISA_EXT_DATA_ENTRY(shvstvecd, PRIV_VERSION_1_12_0, has_priv_1_12),
71
const RISCVIsaExtData isa_edata_arr[] = {
36
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
72
ISA_EXT_DATA_ENTRY(zicbom, PRIV_VERSION_1_12_0, ext_zicbom),
37
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
73
+ ISA_EXT_DATA_ENTRY(zicbop, PRIV_VERSION_1_12_0, ext_zicbop),
38
+ ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind),
74
ISA_EXT_DATA_ENTRY(zicboz, PRIV_VERSION_1_12_0, ext_zicboz),
39
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
75
ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond),
40
ISA_EXT_DATA_ENTRY(smrnmi, PRIV_VERSION_1_12_0, ext_smrnmi),
76
ISA_EXT_DATA_ENTRY(zicntr, PRIV_VERSION_1_12_0, ext_zicntr),
41
ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm),
77
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
42
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
78
MULTI_EXT_CFG_BOOL("zhinxmin", ext_zhinxmin, false),
43
ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11),
79
44
ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf),
80
MULTI_EXT_CFG_BOOL("zicbom", ext_zicbom, true),
45
ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
81
+ MULTI_EXT_CFG_BOOL("zicbop", ext_zicbop, true),
46
+ ISA_EXT_DATA_ENTRY(sscsrind, PRIV_VERSION_1_12_0, ext_sscsrind),
82
MULTI_EXT_CFG_BOOL("zicboz", ext_zicboz, true),
47
ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm),
83
48
ISA_EXT_DATA_ENTRY(ssstateen, PRIV_VERSION_1_12_0, ext_ssstateen),
84
MULTI_EXT_CFG_BOOL("zmmul", ext_zmmul, false),
49
ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc),
85
@@ -XXX,XX +XXX,XX @@ Property riscv_cpu_options[] = {
86
DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
87
88
DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64),
89
+ DEFINE_PROP_UINT16("cbop_blocksize", RISCVCPU, cfg.cbop_blocksize, 64),
90
DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
91
92
DEFINE_PROP_END_OF_LIST(),
93
--
50
--
94
2.43.0
51
2.48.1
diff view generated by jsdifflib
1
From: Alistair Francis <alistair23@gmail.com>
1
From: Kaiwen Xue <kaiwenx@rivosinc.com>
2
2
3
The CSRs will always be between either CSR_MHPMCOUNTER3 and
3
Since xiselect and xireg also will be of use in sxcsrind, AIA should
4
CSR_MHPMCOUNTER31 or CSR_MHPMCOUNTER3H and CSR_MHPMCOUNTER31H.
4
have its own separated interface when those CSRs are accessed.
5
5
6
So although ctr_index can't be negative, Coverity doesn't know this and
6
Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com>
7
it isn't obvious to human readers either. Let's add an assert to ensure
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
that Coverity knows the values will be within range.
8
Signed-off-by: Atish Patra <atishp@rivosinc.com>
9
9
Message-ID: <20250110-counter_delegation-v5-2-e83d797ae294@rivosinc.com>
10
To simplify the code let's also change the RV32 adjustment.
11
12
Fixes: Coverity CID 1523910
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
15
Message-ID: <20240108001328.280222-2-alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
11
---
18
target/riscv/csr.c | 5 ++++-
12
target/riscv/csr.c | 165 ++++++++++++++++++++++++++++++++++++++-------
19
1 file changed, 4 insertions(+), 1 deletion(-)
13
1 file changed, 139 insertions(+), 26 deletions(-)
20
14
21
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
22
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/csr.c
17
--- a/target/riscv/csr.c
24
+++ b/target/riscv/csr.c
18
+++ b/target/riscv/csr.c
25
@@ -XXX,XX +XXX,XX @@ static RISCVException mctr(CPURISCVState *env, int csrno)
19
@@ -XXX,XX +XXX,XX @@
26
20
#include "system/cpu-timers.h"
27
if ((riscv_cpu_mxl(env) == MXL_RV32) && csrno >= CSR_MCYCLEH) {
21
#include "qemu/guest-random.h"
28
/* Offset for RV32 mhpmcounternh counters */
22
#include "qapi/error.h"
29
- base_csrno += 0x80;
23
+#include <stdbool.h>
30
+ csrno -= 0x80;
24
25
/* CSR function table public API */
26
void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops)
27
@@ -XXX,XX +XXX,XX @@ static RISCVException aia_any32(CPURISCVState *env, int csrno)
28
return any32(env, csrno);
29
}
30
31
+static RISCVException csrind_or_aia_any(CPURISCVState *env, int csrno)
32
+{
33
+ if (!riscv_cpu_cfg(env)->ext_smaia && !riscv_cpu_cfg(env)->ext_smcsrind) {
34
+ return RISCV_EXCP_ILLEGAL_INST;
35
+ }
36
+
37
+ return any(env, csrno);
38
+}
39
+
40
static RISCVException smode(CPURISCVState *env, int csrno)
41
{
42
if (riscv_has_ext(env, RVS)) {
43
@@ -XXX,XX +XXX,XX @@ static RISCVException aia_smode32(CPURISCVState *env, int csrno)
44
return smode32(env, csrno);
45
}
46
47
+static bool csrind_extensions_present(CPURISCVState *env)
48
+{
49
+ return riscv_cpu_cfg(env)->ext_smcsrind || riscv_cpu_cfg(env)->ext_sscsrind;
50
+}
51
+
52
+static bool aia_extensions_present(CPURISCVState *env)
53
+{
54
+ return riscv_cpu_cfg(env)->ext_smaia || riscv_cpu_cfg(env)->ext_ssaia;
55
+}
56
+
57
+static bool csrind_or_aia_extensions_present(CPURISCVState *env)
58
+{
59
+ return csrind_extensions_present(env) || aia_extensions_present(env);
60
+}
61
+
62
+static RISCVException csrind_or_aia_smode(CPURISCVState *env, int csrno)
63
+{
64
+ if (!csrind_or_aia_extensions_present(env)) {
65
+ return RISCV_EXCP_ILLEGAL_INST;
66
+ }
67
+
68
+ return smode(env, csrno);
69
+}
70
+
71
static RISCVException hmode(CPURISCVState *env, int csrno)
72
{
73
if (riscv_has_ext(env, RVH)) {
74
@@ -XXX,XX +XXX,XX @@ static RISCVException hmode32(CPURISCVState *env, int csrno)
75
76
}
77
78
+static RISCVException csrind_or_aia_hmode(CPURISCVState *env, int csrno)
79
+{
80
+ if (!csrind_or_aia_extensions_present(env)) {
81
+ return RISCV_EXCP_ILLEGAL_INST;
82
+ }
83
+
84
+ return hmode(env, csrno);
85
+}
86
+
87
static RISCVException umode(CPURISCVState *env, int csrno)
88
{
89
if (riscv_has_ext(env, RVU)) {
90
@@ -XXX,XX +XXX,XX @@ static int aia_xlate_vs_csrno(CPURISCVState *env, int csrno)
91
};
92
}
93
94
+static int csrind_xlate_vs_csrno(CPURISCVState *env, int csrno)
95
+{
96
+ if (!env->virt_enabled) {
97
+ return csrno;
98
+ }
99
+
100
+ switch (csrno) {
101
+ case CSR_SISELECT:
102
+ return CSR_VSISELECT;
103
+ case CSR_SIREG:
104
+ return CSR_VSIREG;
105
+ default:
106
+ return csrno;
107
+ };
108
+}
109
+
110
static RISCVException rmw_xiselect(CPURISCVState *env, int csrno,
111
target_ulong *val, target_ulong new_val,
112
target_ulong wr_mask)
113
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xiselect(CPURISCVState *env, int csrno,
114
target_ulong *iselect;
115
116
/* Translate CSR number for VS-mode */
117
- csrno = aia_xlate_vs_csrno(env, csrno);
118
+ csrno = csrind_xlate_vs_csrno(env, csrno);
119
120
/* Find the iselect CSR based on CSR number */
121
switch (csrno) {
122
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xiselect(CPURISCVState *env, int csrno,
123
return RISCV_EXCP_NONE;
124
}
125
126
+static bool xiselect_aia_range(target_ulong isel)
127
+{
128
+ return (ISELECT_IPRIO0 <= isel && isel <= ISELECT_IPRIO15) ||
129
+ (ISELECT_IMSIC_FIRST <= isel && isel <= ISELECT_IMSIC_LAST);
130
+}
131
+
132
static int rmw_iprio(target_ulong xlen,
133
target_ulong iselect, uint8_t *iprio,
134
target_ulong *val, target_ulong new_val,
135
@@ -XXX,XX +XXX,XX @@ static int rmw_iprio(target_ulong xlen,
136
return 0;
137
}
138
139
-static RISCVException rmw_xireg(CPURISCVState *env, int csrno,
140
- target_ulong *val, target_ulong new_val,
141
- target_ulong wr_mask)
142
+static RISCVException rmw_xireg_aia(CPURISCVState *env, int csrno,
143
+ target_ulong isel, target_ulong *val,
144
+ target_ulong new_val, target_ulong wr_mask)
145
{
146
- bool virt, isel_reserved;
147
- uint8_t *iprio;
148
+ bool virt = false, isel_reserved = false;
149
int ret = -EINVAL;
150
- target_ulong priv, isel, vgein;
151
-
152
- /* Translate CSR number for VS-mode */
153
- csrno = aia_xlate_vs_csrno(env, csrno);
154
+ uint8_t *iprio;
155
+ target_ulong priv, vgein;
156
157
- /* Decode register details from CSR number */
158
- virt = false;
159
- isel_reserved = false;
160
+ /* VS-mode CSR number passed in has already been translated */
161
switch (csrno) {
162
case CSR_MIREG:
163
+ if (!riscv_cpu_cfg(env)->ext_smaia) {
164
+ goto done;
165
+ }
166
iprio = env->miprio;
167
- isel = env->miselect;
168
priv = PRV_M;
169
break;
170
case CSR_SIREG:
171
- if (env->priv == PRV_S && env->mvien & MIP_SEIP &&
172
+ if (!riscv_cpu_cfg(env)->ext_ssaia ||
173
+ (env->priv == PRV_S && env->mvien & MIP_SEIP &&
174
env->siselect >= ISELECT_IMSIC_EIDELIVERY &&
175
- env->siselect <= ISELECT_IMSIC_EIE63) {
176
+ env->siselect <= ISELECT_IMSIC_EIE63)) {
177
goto done;
178
}
179
iprio = env->siprio;
180
- isel = env->siselect;
181
priv = PRV_S;
182
break;
183
case CSR_VSIREG:
184
+ if (!riscv_cpu_cfg(env)->ext_ssaia) {
185
+ goto done;
186
+ }
187
iprio = env->hviprio;
188
- isel = env->vsiselect;
189
priv = PRV_S;
190
virt = true;
191
break;
192
default:
193
- goto done;
194
+ goto done;
195
};
196
197
/* Find the selected guest interrupt file */
198
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xireg(CPURISCVState *env, int csrno,
31
}
199
}
32
+
200
33
+ g_assert(csrno >= CSR_MHPMCOUNTER3 && csrno <= CSR_MHPMCOUNTER31);
201
done:
34
+
202
+ /*
35
ctr_index = csrno - base_csrno;
203
+ * If AIA is not enabled, illegal instruction exception is always
36
if ((BIT(ctr_index) & pmu_avail_ctrs >> 3) == 0) {
204
+ * returned regardless of whether we are in VS-mode or not
37
/* The PMU is not enabled or counter is out of range */
205
+ */
206
if (ret) {
207
return (env->virt_enabled && virt && !isel_reserved) ?
208
RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST;
209
}
210
+
211
+ return RISCV_EXCP_NONE;
212
+}
213
+
214
+static RISCVException rmw_xireg(CPURISCVState *env, int csrno,
215
+ target_ulong *val, target_ulong new_val,
216
+ target_ulong wr_mask)
217
+{
218
+ bool virt = false;
219
+ int ret = -EINVAL;
220
+ target_ulong isel;
221
+
222
+ /* Translate CSR number for VS-mode */
223
+ csrno = csrind_xlate_vs_csrno(env, csrno);
224
+
225
+ /* Decode register details from CSR number */
226
+ switch (csrno) {
227
+ case CSR_MIREG:
228
+ isel = env->miselect;
229
+ break;
230
+ case CSR_SIREG:
231
+ isel = env->siselect;
232
+ break;
233
+ case CSR_VSIREG:
234
+ isel = env->vsiselect;
235
+ virt = true;
236
+ break;
237
+ default:
238
+ goto done;
239
+ };
240
+
241
+ if (xiselect_aia_range(isel)) {
242
+ return rmw_xireg_aia(env, csrno, isel, val, new_val, wr_mask);
243
+ }
244
+
245
+done:
246
+ if (ret) {
247
+ return (env->virt_enabled && virt) ?
248
+ RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST;
249
+ }
250
return RISCV_EXCP_NONE;
251
}
252
253
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
254
[CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip },
255
256
/* Machine-Level Window to Indirectly Accessed Registers (AIA) */
257
- [CSR_MISELECT] = { "miselect", aia_any, NULL, NULL, rmw_xiselect },
258
- [CSR_MIREG] = { "mireg", aia_any, NULL, NULL, rmw_xireg },
259
+ [CSR_MISELECT] = { "miselect", csrind_or_aia_any, NULL, NULL,
260
+ rmw_xiselect },
261
+ [CSR_MIREG] = { "mireg", csrind_or_aia_any, NULL, NULL,
262
+ rmw_xireg },
263
264
/* Machine-Level Interrupts (AIA) */
265
[CSR_MTOPEI] = { "mtopei", aia_any, NULL, NULL, rmw_xtopei },
266
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
267
[CSR_SATP] = { "satp", satp, read_satp, write_satp },
268
269
/* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */
270
- [CSR_SISELECT] = { "siselect", aia_smode, NULL, NULL, rmw_xiselect },
271
- [CSR_SIREG] = { "sireg", aia_smode, NULL, NULL, rmw_xireg },
272
+ [CSR_SISELECT] = { "siselect", csrind_or_aia_smode, NULL, NULL,
273
+ rmw_xiselect },
274
+ [CSR_SIREG] = { "sireg", csrind_or_aia_smode, NULL, NULL,
275
+ rmw_xireg },
276
277
/* Supervisor-Level Interrupts (AIA) */
278
[CSR_STOPEI] = { "stopei", aia_smode, NULL, NULL, rmw_xtopei },
279
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
280
/*
281
* VS-Level Window to Indirectly Accessed Registers (H-extension with AIA)
282
*/
283
- [CSR_VSISELECT] = { "vsiselect", aia_hmode, NULL, NULL,
284
- rmw_xiselect },
285
- [CSR_VSIREG] = { "vsireg", aia_hmode, NULL, NULL, rmw_xireg },
286
+ [CSR_VSISELECT] = { "vsiselect", csrind_or_aia_hmode, NULL, NULL,
287
+ rmw_xiselect },
288
+ [CSR_VSIREG] = { "vsireg", csrind_or_aia_hmode, NULL, NULL,
289
+ rmw_xireg },
290
291
/* VS-Level Interrupts (H-extension with AIA) */
292
[CSR_VSTOPEI] = { "vstopei", aia_hmode, NULL, NULL, rmw_xtopei },
38
--
293
--
39
2.43.0
294
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Atish Patra <atishp@rivosinc.com>
2
2
3
Add support for RVV and Vector CSR KVM regs vstart, vl and vtype.
3
As per the ratified AIA spec v1.0, three stateen bits control AIA CSR
4
access.
4
5
5
Support for vregs[] requires KVM side changes and an extra reg (vlenb)
6
Bit 60 controls the indirect CSRs
6
and will be added later.
7
Bit 59 controls the most AIA CSR state
8
Bit 58 controls the IMSIC state such as stopei and vstopei
7
9
8
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Enable the corresponding bits in [m|h]stateen and enable corresponding
11
checks in the CSR accessor functions.
12
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-ID: <20231218204321.75757-5-dbarboza@ventanamicro.com>
14
Signed-off-by: Atish Patra <atishp@rivosinc.com>
15
Message-ID: <20250110-counter_delegation-v5-3-e83d797ae294@rivosinc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
17
---
13
target/riscv/kvm/kvm-cpu.c | 74 ++++++++++++++++++++++++++++++++++++++
18
target/riscv/csr.c | 85 +++++++++++++++++++++++++++++++++++++++++++++-
14
1 file changed, 74 insertions(+)
19
1 file changed, 84 insertions(+), 1 deletion(-)
15
20
16
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
21
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
17
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/kvm/kvm-cpu.c
23
--- a/target/riscv/csr.c
19
+++ b/target/riscv/kvm/kvm-cpu.c
24
+++ b/target/riscv/csr.c
20
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id_u64(uint64_t type, uint64_t idx)
25
@@ -XXX,XX +XXX,XX @@ static RISCVException smode32(CPURISCVState *env, int csrno)
21
26
22
#define RISCV_FP_D_REG(idx) kvm_riscv_reg_id_u64(KVM_REG_RISCV_FP_D, idx)
27
static RISCVException aia_smode(CPURISCVState *env, int csrno)
23
28
{
24
+#define RISCV_VECTOR_CSR_REG(env, name) \
29
+ int ret;
25
+ kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_VECTOR, \
26
+ KVM_REG_RISCV_VECTOR_CSR_REG(name))
27
+
30
+
28
#define KVM_RISCV_GET_CSR(cs, env, csr, reg) \
31
if (!riscv_cpu_cfg(env)->ext_ssaia) {
29
do { \
32
return RISCV_EXCP_ILLEGAL_INST;
30
int _ret = kvm_get_one_reg(cs, RISCV_CSR_REG(env, csr), &reg); \
33
}
31
@@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_misa_ext_cfgs[] = {
34
32
KVM_MISA_CFG(RVH, KVM_RISCV_ISA_EXT_H),
35
+ if (csrno == CSR_STOPEI) {
33
KVM_MISA_CFG(RVI, KVM_RISCV_ISA_EXT_I),
36
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_IMSIC);
34
KVM_MISA_CFG(RVM, KVM_RISCV_ISA_EXT_M),
37
+ } else {
35
+ KVM_MISA_CFG(RVV, KVM_RISCV_ISA_EXT_V),
38
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_AIA);
36
};
37
38
static void kvm_cpu_get_misa_ext_cfg(Object *obj, Visitor *v,
39
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_put_regs_timer(CPUState *cs)
40
env->kvm_timer_dirty = false;
41
}
42
43
+static int kvm_riscv_get_regs_vector(CPUState *cs)
44
+{
45
+ CPURISCVState *env = &RISCV_CPU(cs)->env;
46
+ target_ulong reg;
47
+ int ret = 0;
48
+
49
+ if (!riscv_has_ext(env, RVV)) {
50
+ return 0;
51
+ }
39
+ }
52
+
40
+
53
+ ret = kvm_get_one_reg(cs, RISCV_VECTOR_CSR_REG(env, vstart), &reg);
41
+ if (ret != RISCV_EXCP_NONE) {
54
+ if (ret) {
55
+ return ret;
56
+ }
57
+ env->vstart = reg;
58
+
59
+ ret = kvm_get_one_reg(cs, RISCV_VECTOR_CSR_REG(env, vl), &reg);
60
+ if (ret) {
61
+ return ret;
62
+ }
63
+ env->vl = reg;
64
+
65
+ ret = kvm_get_one_reg(cs, RISCV_VECTOR_CSR_REG(env, vtype), &reg);
66
+ if (ret) {
67
+ return ret;
68
+ }
69
+ env->vtype = reg;
70
+
71
+ return 0;
72
+}
73
+
74
+static int kvm_riscv_put_regs_vector(CPUState *cs)
75
+{
76
+ CPURISCVState *env = &RISCV_CPU(cs)->env;
77
+ target_ulong reg;
78
+ int ret = 0;
79
+
80
+ if (!riscv_has_ext(env, RVV)) {
81
+ return 0;
82
+ }
83
+
84
+ reg = env->vstart;
85
+ ret = kvm_set_one_reg(cs, RISCV_VECTOR_CSR_REG(env, vstart), &reg);
86
+ if (ret) {
87
+ return ret;
42
+ return ret;
88
+ }
43
+ }
89
+
44
+
90
+ reg = env->vl;
45
return smode(env, csrno);
91
+ ret = kvm_set_one_reg(cs, RISCV_VECTOR_CSR_REG(env, vl), &reg);
46
}
92
+ if (ret) {
47
48
static RISCVException aia_smode32(CPURISCVState *env, int csrno)
49
{
50
+ int ret;
51
+
52
if (!riscv_cpu_cfg(env)->ext_ssaia) {
53
return RISCV_EXCP_ILLEGAL_INST;
54
}
55
56
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_AIA);
57
+ if (ret != RISCV_EXCP_NONE) {
93
+ return ret;
58
+ return ret;
94
+ }
59
+ }
95
+
60
+
96
+ reg = env->vtype;
61
+ if (ret != RISCV_EXCP_NONE) {
97
+ ret = kvm_set_one_reg(cs, RISCV_VECTOR_CSR_REG(env, vtype), &reg);
98
+
99
+ return ret;
100
+}
101
+
102
typedef struct KVMScratchCPU {
103
int kvmfd;
104
int vmfd;
105
@@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs)
106
return ret;
107
}
108
109
+ ret = kvm_riscv_get_regs_vector(cs);
110
+ if (ret) {
111
+ return ret;
62
+ return ret;
112
+ }
63
+ }
113
+
64
+
114
return ret;
65
return smode32(env, csrno);
115
}
66
}
116
67
117
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level)
68
@@ -XXX,XX +XXX,XX @@ static RISCVException hgatp(CPURISCVState *env, int csrno)
118
return ret;
69
119
}
70
static RISCVException aia_hmode(CPURISCVState *env, int csrno)
120
71
{
121
+ ret = kvm_riscv_put_regs_vector(cs);
72
+ int ret;
122
+ if (ret) {
73
+
74
if (!riscv_cpu_cfg(env)->ext_ssaia) {
75
return RISCV_EXCP_ILLEGAL_INST;
76
}
77
78
- return hmode(env, csrno);
79
+ if (csrno == CSR_VSTOPEI) {
80
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_IMSIC);
81
+ } else {
82
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_AIA);
83
+ }
84
+
85
+ if (ret != RISCV_EXCP_NONE) {
123
+ return ret;
86
+ return ret;
124
+ }
87
+ }
125
+
88
+
126
if (KVM_PUT_RESET_STATE == level) {
89
+ return hmode(env, csrno);
127
RISCVCPU *cpu = RISCV_CPU(cs);
90
}
128
if (cs->cpu_index == 0) {
91
92
static RISCVException aia_hmode32(CPURISCVState *env, int csrno)
93
{
94
+ int ret;
95
+
96
+ if (!riscv_cpu_cfg(env)->ext_ssaia) {
97
+ return RISCV_EXCP_ILLEGAL_INST;
98
+ }
99
+
100
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_AIA);
101
+ if (ret != RISCV_EXCP_NONE) {
102
+ return ret;
103
+ }
104
+
105
if (!riscv_cpu_cfg(env)->ext_ssaia) {
106
return RISCV_EXCP_ILLEGAL_INST;
107
}
108
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xiselect(CPURISCVState *env, int csrno,
109
target_ulong wr_mask)
110
{
111
target_ulong *iselect;
112
+ int ret;
113
+
114
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT);
115
+ if (ret != RISCV_EXCP_NONE) {
116
+ return ret;
117
+ }
118
119
/* Translate CSR number for VS-mode */
120
csrno = csrind_xlate_vs_csrno(env, csrno);
121
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xireg(CPURISCVState *env, int csrno,
122
int ret = -EINVAL;
123
target_ulong isel;
124
125
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT);
126
+ if (ret != RISCV_EXCP_NONE) {
127
+ return ret;
128
+ }
129
+
130
/* Translate CSR number for VS-mode */
131
csrno = csrind_xlate_vs_csrno(env, csrno);
132
133
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstateen0(CPURISCVState *env, int csrno,
134
wr_mask |= SMSTATEEN0_P1P13;
135
}
136
137
+ if (riscv_cpu_cfg(env)->ext_smaia) {
138
+ wr_mask |= SMSTATEEN0_SVSLCT;
139
+ }
140
+
141
+ /*
142
+ * As per the AIA specification, SMSTATEEN0_IMSIC is valid only if IMSIC is
143
+ * implemented. However, that information is with MachineState and we can't
144
+ * figure that out in csr.c. Just enable if Smaia is available.
145
+ */
146
+ if (riscv_cpu_cfg(env)->ext_smaia) {
147
+ wr_mask |= (SMSTATEEN0_AIA | SMSTATEEN0_IMSIC);
148
+ }
149
+
150
return write_mstateen(env, csrno, wr_mask, new_val);
151
}
152
153
@@ -XXX,XX +XXX,XX @@ static RISCVException write_hstateen0(CPURISCVState *env, int csrno,
154
wr_mask |= SMSTATEEN0_FCSR;
155
}
156
157
+ if (riscv_cpu_cfg(env)->ext_ssaia) {
158
+ wr_mask |= SMSTATEEN0_SVSLCT;
159
+ }
160
+
161
+ /*
162
+ * As per the AIA specification, SMSTATEEN0_IMSIC is valid only if IMSIC is
163
+ * implemented. However, that information is with MachineState and we can't
164
+ * figure that out in csr.c. Just enable if Ssaia is available.
165
+ */
166
+ if (riscv_cpu_cfg(env)->ext_ssaia) {
167
+ wr_mask |= (SMSTATEEN0_AIA | SMSTATEEN0_IMSIC);
168
+ }
169
+
170
return write_hstateen(env, csrno, wr_mask, new_val);
171
}
172
129
--
173
--
130
2.43.0
174
2.48.1
diff view generated by jsdifflib
1
From: Sunil V L <sunilvl@ventanamicro.com>
1
From: Kaiwen Xue <kaiwenx@rivosinc.com>
2
2
3
Update the GPEX host bridge properties related to MMIO ranges with
3
This adds the indirect access registers required by sscsrind/smcsrind
4
values set for the virt machine.
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
6
whether each extension is enabled and the value stored in xiselect.
5
7
6
Suggested-by: Igor Mammedov <imammedo@redhat.com>
8
Co-developed-by: Atish Patra <atishp@rivosinc.com>
7
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
9
Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Acked-by: Michael S. Tsirkin <mst@redhat.com>
11
Acked-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-ID: <20231218150247.466427-12-sunilvl@ventanamicro.com>
12
Signed-off-by: Atish Patra <atishp@rivosinc.com>
13
Message-ID: <20250110-counter_delegation-v5-4-e83d797ae294@rivosinc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
15
---
13
include/hw/riscv/virt.h | 1 +
16
target/riscv/cpu_bits.h | 28 +++++++-
14
hw/riscv/virt.c | 47 ++++++++++++++++++++++++++++-------------
17
target/riscv/csr.c | 144 ++++++++++++++++++++++++++++++++++++++--
15
2 files changed, 33 insertions(+), 15 deletions(-)
18
2 files changed, 166 insertions(+), 6 deletions(-)
16
19
17
diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h
20
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
18
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/riscv/virt.h
22
--- a/target/riscv/cpu_bits.h
20
+++ b/include/hw/riscv/virt.h
23
+++ b/target/riscv/cpu_bits.h
21
@@ -XXX,XX +XXX,XX @@ struct RISCVVirtState {
24
@@ -XXX,XX +XXX,XX @@
22
char *oem_table_id;
25
#define CSR_MISELECT 0x350
23
OnOffAuto acpi;
26
#define CSR_MIREG 0x351
24
const MemMapEntry *memmap;
27
25
+ struct GPEXHost *gpex_host;
28
+/* Machine Indirect Register Alias */
26
};
29
+#define CSR_MIREG2 0x352
27
30
+#define CSR_MIREG3 0x353
28
enum {
31
+#define CSR_MIREG4 0x355
29
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
32
+#define CSR_MIREG5 0x356
33
+#define CSR_MIREG6 0x357
34
+
35
/* Machine-Level Interrupts (AIA) */
36
#define CSR_MTOPEI 0x35c
37
#define CSR_MTOPI 0xfb0
38
@@ -XXX,XX +XXX,XX @@
39
#define CSR_SISELECT 0x150
40
#define CSR_SIREG 0x151
41
42
+/* Supervisor Indirect Register Alias */
43
+#define CSR_SIREG2 0x152
44
+#define CSR_SIREG3 0x153
45
+#define CSR_SIREG4 0x155
46
+#define CSR_SIREG5 0x156
47
+#define CSR_SIREG6 0x157
48
+
49
/* Supervisor-Level Interrupts (AIA) */
50
#define CSR_STOPEI 0x15c
51
#define CSR_STOPI 0xdb0
52
@@ -XXX,XX +XXX,XX @@
53
#define CSR_VSISELECT 0x250
54
#define CSR_VSIREG 0x251
55
56
+/* Virtual Supervisor Indirect Alias */
57
+#define CSR_VSIREG2 0x252
58
+#define CSR_VSIREG3 0x253
59
+#define CSR_VSIREG4 0x255
60
+#define CSR_VSIREG5 0x256
61
+#define CSR_VSIREG6 0x257
62
+
63
/* VS-Level Interrupts (H-extension with AIA) */
64
#define CSR_VSTOPEI 0x25c
65
#define CSR_VSTOPI 0xeb0
66
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
67
#define ISELECT_IMSIC_EIE63 0xff
68
#define ISELECT_IMSIC_FIRST ISELECT_IMSIC_EIDELIVERY
69
#define ISELECT_IMSIC_LAST ISELECT_IMSIC_EIE63
70
-#define ISELECT_MASK 0x1ff
71
+#define ISELECT_MASK_AIA 0x1ff
72
+
73
+/* MISELECT, SISELECT, and VSISELECT bits (AIA) */
74
+#define ISELECT_MASK_SXCSRIND 0xfff
75
76
/* Dummy [M|S|VS]ISELECT value for emulating [M|S|VS]TOPEI CSRs */
77
-#define ISELECT_IMSIC_TOPEI (ISELECT_MASK + 1)
78
+#define ISELECT_IMSIC_TOPEI (ISELECT_MASK_AIA + 1)
79
80
/* IMSIC bits (AIA) */
81
#define IMSIC_TOPEI_IID_SHIFT 16
82
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
30
index XXXXXXX..XXXXXXX 100644
83
index XXXXXXX..XXXXXXX 100644
31
--- a/hw/riscv/virt.c
84
--- a/target/riscv/csr.c
32
+++ b/hw/riscv/virt.c
85
+++ b/target/riscv/csr.c
33
@@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap)
86
@@ -XXX,XX +XXX,XX @@ static RISCVException aia_any32(CPURISCVState *env, int csrno)
87
return any32(env, csrno);
34
}
88
}
35
89
36
static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem,
90
+static RISCVException csrind_any(CPURISCVState *env, int csrno)
37
- hwaddr ecam_base, hwaddr ecam_size,
91
+{
38
- hwaddr mmio_base, hwaddr mmio_size,
92
+ if (!riscv_cpu_cfg(env)->ext_smcsrind) {
39
- hwaddr high_mmio_base,
93
+ return RISCV_EXCP_ILLEGAL_INST;
40
- hwaddr high_mmio_size,
94
+ }
41
- hwaddr pio_base,
95
+
42
- DeviceState *irqchip)
96
+ return RISCV_EXCP_NONE;
43
+ DeviceState *irqchip,
97
+}
44
+ RISCVVirtState *s)
98
+
99
static RISCVException csrind_or_aia_any(CPURISCVState *env, int csrno)
45
{
100
{
46
DeviceState *dev;
101
if (!riscv_cpu_cfg(env)->ext_smaia && !riscv_cpu_cfg(env)->ext_smcsrind) {
47
MemoryRegion *ecam_alias, *ecam_reg;
102
@@ -XXX,XX +XXX,XX @@ static bool csrind_or_aia_extensions_present(CPURISCVState *env)
48
MemoryRegion *mmio_alias, *high_mmio_alias, *mmio_reg;
103
return csrind_extensions_present(env) || aia_extensions_present(env);
49
+ hwaddr ecam_base = s->memmap[VIRT_PCIE_ECAM].base;
50
+ hwaddr ecam_size = s->memmap[VIRT_PCIE_ECAM].size;
51
+ hwaddr mmio_base = s->memmap[VIRT_PCIE_MMIO].base;
52
+ hwaddr mmio_size = s->memmap[VIRT_PCIE_MMIO].size;
53
+ hwaddr high_mmio_base = virt_high_pcie_memmap.base;
54
+ hwaddr high_mmio_size = virt_high_pcie_memmap.size;
55
+ hwaddr pio_base = s->memmap[VIRT_PCIE_PIO].base;
56
+ hwaddr pio_size = s->memmap[VIRT_PCIE_PIO].size;
57
qemu_irq irq;
58
int i;
59
60
dev = qdev_new(TYPE_GPEX_HOST);
61
62
+ /* Set GPEX object properties for the virt machine */
63
+ object_property_set_uint(OBJECT(GPEX_HOST(dev)), PCI_HOST_ECAM_BASE,
64
+ ecam_base, NULL);
65
+ object_property_set_int(OBJECT(GPEX_HOST(dev)), PCI_HOST_ECAM_SIZE,
66
+ ecam_size, NULL);
67
+ object_property_set_uint(OBJECT(GPEX_HOST(dev)),
68
+ PCI_HOST_BELOW_4G_MMIO_BASE,
69
+ mmio_base, NULL);
70
+ object_property_set_int(OBJECT(GPEX_HOST(dev)), PCI_HOST_BELOW_4G_MMIO_SIZE,
71
+ mmio_size, NULL);
72
+ object_property_set_uint(OBJECT(GPEX_HOST(dev)),
73
+ PCI_HOST_ABOVE_4G_MMIO_BASE,
74
+ high_mmio_base, NULL);
75
+ object_property_set_int(OBJECT(GPEX_HOST(dev)), PCI_HOST_ABOVE_4G_MMIO_SIZE,
76
+ high_mmio_size, NULL);
77
+ object_property_set_uint(OBJECT(GPEX_HOST(dev)), PCI_HOST_PIO_BASE,
78
+ pio_base, NULL);
79
+ object_property_set_int(OBJECT(GPEX_HOST(dev)), PCI_HOST_PIO_SIZE,
80
+ pio_size, NULL);
81
+
82
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
83
84
ecam_alias = g_new0(MemoryRegion, 1);
85
@@ -XXX,XX +XXX,XX @@ static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem,
86
gpex_set_irq_num(GPEX_HOST(dev), i, PCIE_IRQ + i);
87
}
88
89
+ GPEX_HOST(dev)->gpex_cfg.bus = PCI_HOST_BRIDGE(GPEX_HOST(dev))->bus;
90
return dev;
91
}
104
}
92
105
93
@@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine)
106
+static RISCVException csrind_smode(CPURISCVState *env, int csrno)
94
qdev_get_gpio_in(virtio_irqchip, VIRTIO_IRQ + i));
107
+{
95
}
108
+ if (!csrind_extensions_present(env)) {
96
109
+ return RISCV_EXCP_ILLEGAL_INST;
97
- gpex_pcie_init(system_memory,
110
+ }
98
- memmap[VIRT_PCIE_ECAM].base,
111
+
99
- memmap[VIRT_PCIE_ECAM].size,
112
+ return smode(env, csrno);
100
- memmap[VIRT_PCIE_MMIO].base,
113
+}
101
- memmap[VIRT_PCIE_MMIO].size,
114
+
102
- virt_high_pcie_memmap.base,
115
static RISCVException csrind_or_aia_smode(CPURISCVState *env, int csrno)
103
- virt_high_pcie_memmap.size,
116
{
104
- memmap[VIRT_PCIE_PIO].base,
117
if (!csrind_or_aia_extensions_present(env)) {
105
- pcie_irqchip);
118
@@ -XXX,XX +XXX,XX @@ static RISCVException hmode32(CPURISCVState *env, int csrno)
106
+ gpex_pcie_init(system_memory, pcie_irqchip, s);
119
107
120
}
108
create_platform_bus(s, mmio_irqchip);
121
109
122
+static RISCVException csrind_hmode(CPURISCVState *env, int csrno)
123
+{
124
+ if (!csrind_extensions_present(env)) {
125
+ return RISCV_EXCP_ILLEGAL_INST;
126
+ }
127
+
128
+ return hmode(env, csrno);
129
+}
130
+
131
static RISCVException csrind_or_aia_hmode(CPURISCVState *env, int csrno)
132
{
133
if (!csrind_or_aia_extensions_present(env)) {
134
@@ -XXX,XX +XXX,XX @@ static int csrind_xlate_vs_csrno(CPURISCVState *env, int csrno)
135
case CSR_SISELECT:
136
return CSR_VSISELECT;
137
case CSR_SIREG:
138
- return CSR_VSIREG;
139
+ case CSR_SIREG2:
140
+ case CSR_SIREG3:
141
+ case CSR_SIREG4:
142
+ case CSR_SIREG5:
143
+ case CSR_SIREG6:
144
+ return CSR_VSIREG + (csrno - CSR_SIREG);
145
default:
146
return csrno;
147
};
148
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xiselect(CPURISCVState *env, int csrno,
149
*val = *iselect;
150
}
151
152
- wr_mask &= ISELECT_MASK;
153
+ if (riscv_cpu_cfg(env)->ext_smcsrind || riscv_cpu_cfg(env)->ext_sscsrind) {
154
+ wr_mask &= ISELECT_MASK_SXCSRIND;
155
+ } else {
156
+ wr_mask &= ISELECT_MASK_AIA;
157
+ }
158
+
159
if (wr_mask) {
160
*iselect = (*iselect & ~wr_mask) | (new_val & wr_mask);
161
}
162
@@ -XXX,XX +XXX,XX @@ done:
163
return RISCV_EXCP_NONE;
164
}
165
166
+/*
167
+ * rmw_xireg_csrind: Perform indirect access to xireg and xireg2-xireg6
168
+ *
169
+ * Perform indirect access to xireg and xireg2-xireg6.
170
+ * This is a generic interface for all xireg CSRs. Apart from AIA, all other
171
+ * extension using csrind should be implemented here.
172
+ */
173
+static int rmw_xireg_csrind(CPURISCVState *env, int csrno,
174
+ target_ulong isel, target_ulong *val,
175
+ target_ulong new_val, target_ulong wr_mask)
176
+{
177
+ return -EINVAL;
178
+}
179
+
180
+static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val,
181
+ target_ulong new_val, target_ulong wr_mask)
182
+{
183
+ bool virt = false;
184
+ int ret = -EINVAL;
185
+ target_ulong isel;
186
+
187
+ ret = smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT);
188
+ if (ret != RISCV_EXCP_NONE) {
189
+ return ret;
190
+ }
191
+
192
+ /* Translate CSR number for VS-mode */
193
+ csrno = csrind_xlate_vs_csrno(env, csrno);
194
+
195
+ if (CSR_MIREG <= csrno && csrno <= CSR_MIREG6 &&
196
+ csrno != CSR_MIREG4 - 1) {
197
+ isel = env->miselect;
198
+ } else if (CSR_SIREG <= csrno && csrno <= CSR_SIREG6 &&
199
+ csrno != CSR_SIREG4 - 1) {
200
+ isel = env->siselect;
201
+ } else if (CSR_VSIREG <= csrno && csrno <= CSR_VSIREG6 &&
202
+ csrno != CSR_VSIREG4 - 1) {
203
+ isel = env->vsiselect;
204
+ virt = true;
205
+ } else {
206
+ goto done;
207
+ }
208
+
209
+ return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask);
210
+
211
+done:
212
+ return (env->virt_enabled && virt) ?
213
+ RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST;
214
+}
215
+
216
static RISCVException rmw_xireg(CPURISCVState *env, int csrno,
217
target_ulong *val, target_ulong new_val,
218
target_ulong wr_mask)
219
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xireg(CPURISCVState *env, int csrno,
220
goto done;
221
};
222
223
+ /*
224
+ * Use the xiselect range to determine actual op on xireg.
225
+ *
226
+ * Since we only checked the existence of AIA or Indirect Access in the
227
+ * predicate, we should check the existence of the exact extension when
228
+ * we get to a specific range and return illegal instruction exception even
229
+ * in VS-mode.
230
+ */
231
if (xiselect_aia_range(isel)) {
232
return rmw_xireg_aia(env, csrno, isel, val, new_val, wr_mask);
233
+ } else if (riscv_cpu_cfg(env)->ext_smcsrind ||
234
+ riscv_cpu_cfg(env)->ext_sscsrind) {
235
+ return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask);
236
+ } else {
237
+ return RISCV_EXCP_ILLEGAL_INST;
238
}
239
240
done:
241
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstateen0(CPURISCVState *env, int csrno,
242
wr_mask |= SMSTATEEN0_P1P13;
243
}
244
245
- if (riscv_cpu_cfg(env)->ext_smaia) {
246
+ if (riscv_cpu_cfg(env)->ext_smaia || riscv_cpu_cfg(env)->ext_smcsrind) {
247
wr_mask |= SMSTATEEN0_SVSLCT;
248
}
249
250
@@ -XXX,XX +XXX,XX @@ static RISCVException write_hstateen0(CPURISCVState *env, int csrno,
251
wr_mask |= SMSTATEEN0_FCSR;
252
}
253
254
- if (riscv_cpu_cfg(env)->ext_ssaia) {
255
+ if (riscv_cpu_cfg(env)->ext_ssaia || riscv_cpu_cfg(env)->ext_sscsrind) {
256
wr_mask |= SMSTATEEN0_SVSLCT;
257
}
258
259
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
260
[CSR_MIREG] = { "mireg", csrind_or_aia_any, NULL, NULL,
261
rmw_xireg },
262
263
+ /* Machine Indirect Register Alias */
264
+ [CSR_MIREG2] = { "mireg2", csrind_any, NULL, NULL, rmw_xiregi,
265
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
266
+ [CSR_MIREG3] = { "mireg3", csrind_any, NULL, NULL, rmw_xiregi,
267
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
268
+ [CSR_MIREG4] = { "mireg4", csrind_any, NULL, NULL, rmw_xiregi,
269
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
270
+ [CSR_MIREG5] = { "mireg5", csrind_any, NULL, NULL, rmw_xiregi,
271
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
272
+ [CSR_MIREG6] = { "mireg6", csrind_any, NULL, NULL, rmw_xiregi,
273
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
274
+
275
/* Machine-Level Interrupts (AIA) */
276
[CSR_MTOPEI] = { "mtopei", aia_any, NULL, NULL, rmw_xtopei },
277
[CSR_MTOPI] = { "mtopi", aia_any, read_mtopi },
278
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
279
[CSR_SIREG] = { "sireg", csrind_or_aia_smode, NULL, NULL,
280
rmw_xireg },
281
282
+ /* Supervisor Indirect Register Alias */
283
+ [CSR_SIREG2] = { "sireg2", csrind_smode, NULL, NULL, rmw_xiregi,
284
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
285
+ [CSR_SIREG3] = { "sireg3", csrind_smode, NULL, NULL, rmw_xiregi,
286
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
287
+ [CSR_SIREG4] = { "sireg4", csrind_smode, NULL, NULL, rmw_xiregi,
288
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
289
+ [CSR_SIREG5] = { "sireg5", csrind_smode, NULL, NULL, rmw_xiregi,
290
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
291
+ [CSR_SIREG6] = { "sireg6", csrind_smode, NULL, NULL, rmw_xiregi,
292
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
293
+
294
/* Supervisor-Level Interrupts (AIA) */
295
[CSR_STOPEI] = { "stopei", aia_smode, NULL, NULL, rmw_xtopei },
296
[CSR_STOPI] = { "stopi", aia_smode, read_stopi },
297
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
298
[CSR_VSIREG] = { "vsireg", csrind_or_aia_hmode, NULL, NULL,
299
rmw_xireg },
300
301
+ /* Virtual Supervisor Indirect Alias */
302
+ [CSR_VSIREG2] = { "vsireg2", csrind_hmode, NULL, NULL, rmw_xiregi,
303
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
304
+ [CSR_VSIREG3] = { "vsireg3", csrind_hmode, NULL, NULL, rmw_xiregi,
305
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
306
+ [CSR_VSIREG4] = { "vsireg4", csrind_hmode, NULL, NULL, rmw_xiregi,
307
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
308
+ [CSR_VSIREG5] = { "vsireg5", csrind_hmode, NULL, NULL, rmw_xiregi,
309
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
310
+ [CSR_VSIREG6] = { "vsireg6", csrind_hmode, NULL, NULL, rmw_xiregi,
311
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
312
+
313
/* VS-Level Interrupts (H-extension with AIA) */
314
[CSR_VSTOPEI] = { "vstopei", aia_hmode, NULL, NULL, rmw_xtopei },
315
[CSR_VSTOPI] = { "vstopi", aia_hmode, read_vstopi },
110
--
316
--
111
2.43.0
317
2.48.1
diff view generated by jsdifflib
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
1
From: Atish Patra <atishp@rivosinc.com>
2
2
3
Add support for amocas.w/d/q instructions which are part of the ratified
3
This adds the properties for counter delegation ISA extensions
4
Zacas extension: https://github.com/riscv/riscv-zacas
4
(Smcdeleg/Ssccfg). Definitions of new registers and and implementation
5
will come in the next set of patches.
5
6
6
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
7
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
8
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
9
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Message-ID: <20231207153842.32401-2-rbradford@rivosinc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Atish Patra <atishp@rivosinc.com>
10
Message-ID: <20250110-counter_delegation-v5-5-e83d797ae294@rivosinc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
12
---
13
target/riscv/cpu_cfg.h | 1 +
13
target/riscv/cpu_cfg.h | 2 ++
14
target/riscv/insn32.decode | 6 +
14
target/riscv/cpu.c | 2 ++
15
target/riscv/cpu.c | 2 +
15
2 files changed, 4 insertions(+)
16
target/riscv/tcg/tcg-cpu.c | 5 +
17
target/riscv/translate.c | 1 +
18
target/riscv/insn_trans/trans_rvzacas.c.inc | 150 ++++++++++++++++++++
19
6 files changed, 165 insertions(+)
20
create mode 100644 target/riscv/insn_trans/trans_rvzacas.c.inc
21
16
22
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
17
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
23
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/cpu_cfg.h
19
--- a/target/riscv/cpu_cfg.h
25
+++ b/target/riscv/cpu_cfg.h
20
+++ b/target/riscv/cpu_cfg.h
26
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
21
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
27
bool ext_svnapot;
22
bool ext_ztso;
28
bool ext_svpbmt;
23
bool ext_smstateen;
29
bool ext_zdinx;
24
bool ext_sstc;
30
+ bool ext_zacas;
25
+ bool ext_smcdeleg;
31
bool ext_zawrs;
26
+ bool ext_ssccfg;
32
bool ext_zfa;
27
bool ext_smcntrpmf;
33
bool ext_zfbfmin;
28
bool ext_smcsrind;
34
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
29
bool ext_sscsrind;
35
index XXXXXXX..XXXXXXX 100644
36
--- a/target/riscv/insn32.decode
37
+++ b/target/riscv/insn32.decode
38
@@ -XXX,XX +XXX,XX @@ vgmul_vv 101000 1 ..... 10001 010 ..... 1110111 @r2_vm_1
39
vsm4k_vi 100001 1 ..... ..... 010 ..... 1110111 @r_vm_1
40
vsm4r_vv 101000 1 ..... 10000 010 ..... 1110111 @r2_vm_1
41
vsm4r_vs 101001 1 ..... 10000 010 ..... 1110111 @r2_vm_1
42
+
43
+# *** RV32 Zacas Standard Extension ***
44
+amocas_w 00101 . . ..... ..... 010 ..... 0101111 @atom_st
45
+amocas_d 00101 . . ..... ..... 011 ..... 0101111 @atom_st
46
+# *** RV64 Zacas Standard Extension ***
47
+amocas_q 00101 . . ..... ..... 100 ..... 0101111 @atom_st
48
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
30
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
49
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
50
--- a/target/riscv/cpu.c
32
--- a/target/riscv/cpu.c
51
+++ b/target/riscv/cpu.c
33
+++ b/target/riscv/cpu.c
52
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
34
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
53
ISA_EXT_DATA_ENTRY(zihintpause, PRIV_VERSION_1_10_0, ext_zihintpause),
35
ISA_EXT_DATA_ENTRY(shvstvala, PRIV_VERSION_1_12_0, has_priv_1_12),
54
ISA_EXT_DATA_ENTRY(zihpm, PRIV_VERSION_1_12_0, ext_zihpm),
36
ISA_EXT_DATA_ENTRY(shvstvecd, PRIV_VERSION_1_12_0, has_priv_1_12),
55
ISA_EXT_DATA_ENTRY(zmmul, PRIV_VERSION_1_12_0, ext_zmmul),
37
ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia),
56
+ ISA_EXT_DATA_ENTRY(zacas, PRIV_VERSION_1_12_0, ext_zacas),
38
+ ISA_EXT_DATA_ENTRY(smcdeleg, PRIV_VERSION_1_13_0, ext_smcdeleg),
57
ISA_EXT_DATA_ENTRY(zawrs, PRIV_VERSION_1_12_0, ext_zawrs),
39
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
58
ISA_EXT_DATA_ENTRY(zfa, PRIV_VERSION_1_12_0, ext_zfa),
40
ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind),
59
ISA_EXT_DATA_ENTRY(zfbfmin, PRIV_VERSION_1_12_0, ext_zfbfmin),
41
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
60
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
42
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
61
MULTI_EXT_CFG_BOOL("zicsr", ext_zicsr, true),
43
ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm),
62
MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true),
44
ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen),
63
MULTI_EXT_CFG_BOOL("zihintpause", ext_zihintpause, true),
45
ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia),
64
+ MULTI_EXT_CFG_BOOL("zacas", ext_zacas, false),
46
+ ISA_EXT_DATA_ENTRY(ssccfg, PRIV_VERSION_1_13_0, ext_ssccfg),
65
MULTI_EXT_CFG_BOOL("zawrs", ext_zawrs, true),
47
ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11),
66
MULTI_EXT_CFG_BOOL("zfa", ext_zfa, true),
48
ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf),
67
MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false),
49
ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
68
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
69
index XXXXXXX..XXXXXXX 100644
70
--- a/target/riscv/tcg/tcg-cpu.c
71
+++ b/target/riscv/tcg/tcg-cpu.c
72
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
73
return;
74
}
75
76
+ if ((cpu->cfg.ext_zacas) && !riscv_has_ext(env, RVA)) {
77
+ error_setg(errp, "Zacas extension requires A extension");
78
+ return;
79
+ }
80
+
81
if ((cpu->cfg.ext_zawrs) && !riscv_has_ext(env, RVA)) {
82
error_setg(errp, "Zawrs extension requires A extension");
83
return;
84
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
85
index XXXXXXX..XXXXXXX 100644
86
--- a/target/riscv/translate.c
87
+++ b/target/riscv/translate.c
88
@@ -XXX,XX +XXX,XX @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
89
#include "insn_trans/trans_rvv.c.inc"
90
#include "insn_trans/trans_rvb.c.inc"
91
#include "insn_trans/trans_rvzicond.c.inc"
92
+#include "insn_trans/trans_rvzacas.c.inc"
93
#include "insn_trans/trans_rvzawrs.c.inc"
94
#include "insn_trans/trans_rvzicbo.c.inc"
95
#include "insn_trans/trans_rvzfa.c.inc"
96
diff --git a/target/riscv/insn_trans/trans_rvzacas.c.inc b/target/riscv/insn_trans/trans_rvzacas.c.inc
97
new file mode 100644
98
index XXXXXXX..XXXXXXX
99
--- /dev/null
100
+++ b/target/riscv/insn_trans/trans_rvzacas.c.inc
101
@@ -XXX,XX +XXX,XX @@
102
+/*
103
+ * RISC-V translation routines for the RV64 Zacas Standard Extension.
104
+ *
105
+ * Copyright (c) 2020-2023 PLCT Lab
106
+ *
107
+ * This program is free software; you can redistribute it and/or modify it
108
+ * under the terms and conditions of the GNU General Public License,
109
+ * version 2 or later, as published by the Free Software Foundation.
110
+ *
111
+ * This program is distributed in the hope it will be useful, but WITHOUT
112
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
113
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
114
+ * more details.
115
+ *
116
+ * You should have received a copy of the GNU General Public License along with
117
+ * this program. If not, see <http://www.gnu.org/licenses/>.
118
+ */
119
+
120
+#define REQUIRE_ZACAS(ctx) do { \
121
+ if (!ctx->cfg_ptr->ext_zacas) { \
122
+ return false; \
123
+ } \
124
+} while (0)
125
+
126
+static bool gen_cmpxchg(DisasContext *ctx, arg_atomic *a, MemOp mop)
127
+{
128
+ TCGv dest = get_gpr(ctx, a->rd, EXT_NONE);
129
+ TCGv src1 = get_address(ctx, a->rs1, 0);
130
+ TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE);
131
+
132
+ decode_save_opc(ctx);
133
+ tcg_gen_atomic_cmpxchg_tl(dest, src1, dest, src2, ctx->mem_idx, mop);
134
+
135
+ gen_set_gpr(ctx, a->rd, dest);
136
+ return true;
137
+}
138
+
139
+static bool trans_amocas_w(DisasContext *ctx, arg_amocas_w *a)
140
+{
141
+ REQUIRE_ZACAS(ctx);
142
+ return gen_cmpxchg(ctx, a, MO_ALIGN | MO_TESL);
143
+}
144
+
145
+static TCGv_i64 get_gpr_pair(DisasContext *ctx, int reg_num)
146
+{
147
+ TCGv_i64 t;
148
+
149
+ assert(get_ol(ctx) == MXL_RV32);
150
+
151
+ if (reg_num == 0) {
152
+ return tcg_constant_i64(0);
153
+ }
154
+
155
+ t = tcg_temp_new_i64();
156
+ tcg_gen_concat_tl_i64(t, cpu_gpr[reg_num], cpu_gpr[reg_num + 1]);
157
+ return t;
158
+}
159
+
160
+static void gen_set_gpr_pair(DisasContext *ctx, int reg_num, TCGv_i64 t)
161
+{
162
+ assert(get_ol(ctx) == MXL_RV32);
163
+
164
+ if (reg_num != 0) {
165
+#ifdef TARGET_RISCV32
166
+ tcg_gen_extr_i64_i32(cpu_gpr[reg_num], cpu_gpr[reg_num + 1], t);
167
+#else
168
+ tcg_gen_ext32s_i64(cpu_gpr[reg_num], t);
169
+ tcg_gen_sari_i64(cpu_gpr[reg_num + 1], t, 32);
170
+#endif
171
+
172
+ if (get_xl_max(ctx) == MXL_RV128) {
173
+ tcg_gen_sari_tl(cpu_gprh[reg_num], cpu_gpr[reg_num], 63);
174
+ tcg_gen_sari_tl(cpu_gprh[reg_num + 1], cpu_gpr[reg_num + 1], 63);
175
+ }
176
+ }
177
+}
178
+
179
+static bool gen_cmpxchg64(DisasContext *ctx, arg_atomic *a, MemOp mop)
180
+{
181
+ /*
182
+ * Encodings with odd numbered registers specified in rs2 and rd are
183
+ * reserved.
184
+ */
185
+ if ((a->rs2 | a->rd) & 1) {
186
+ return false;
187
+ }
188
+
189
+ TCGv_i64 dest = get_gpr_pair(ctx, a->rd);
190
+ TCGv src1 = get_address(ctx, a->rs1, 0);
191
+ TCGv_i64 src2 = get_gpr_pair(ctx, a->rs2);
192
+
193
+ decode_save_opc(ctx);
194
+ tcg_gen_atomic_cmpxchg_i64(dest, src1, dest, src2, ctx->mem_idx, mop);
195
+
196
+ gen_set_gpr_pair(ctx, a->rd, dest);
197
+ return true;
198
+}
199
+
200
+static bool trans_amocas_d(DisasContext *ctx, arg_amocas_d *a)
201
+{
202
+ REQUIRE_ZACAS(ctx);
203
+ switch (get_ol(ctx)) {
204
+ case MXL_RV32:
205
+ return gen_cmpxchg64(ctx, a, MO_ALIGN | MO_TEUQ);
206
+ case MXL_RV64:
207
+ case MXL_RV128:
208
+ return gen_cmpxchg(ctx, a, MO_ALIGN | MO_TEUQ);
209
+ default:
210
+ g_assert_not_reached();
211
+ }
212
+}
213
+
214
+static bool trans_amocas_q(DisasContext *ctx, arg_amocas_q *a)
215
+{
216
+ REQUIRE_ZACAS(ctx);
217
+ REQUIRE_64BIT(ctx);
218
+
219
+ /*
220
+ * Encodings with odd numbered registers specified in rs2 and rd are
221
+ * reserved.
222
+ */
223
+ if ((a->rs2 | a->rd) & 1) {
224
+ return false;
225
+ }
226
+
227
+#ifdef TARGET_RISCV64
228
+ TCGv_i128 dest = tcg_temp_new_i128();
229
+ TCGv src1 = get_address(ctx, a->rs1, 0);
230
+ TCGv_i128 src2 = tcg_temp_new_i128();
231
+ TCGv_i64 src2l = get_gpr(ctx, a->rs2, EXT_NONE);
232
+ TCGv_i64 src2h = get_gpr(ctx, a->rs2 == 0 ? 0 : a->rs2 + 1, EXT_NONE);
233
+ TCGv_i64 destl = get_gpr(ctx, a->rd, EXT_NONE);
234
+ TCGv_i64 desth = get_gpr(ctx, a->rd == 0 ? 0 : a->rd + 1, EXT_NONE);
235
+
236
+ tcg_gen_concat_i64_i128(src2, src2l, src2h);
237
+ tcg_gen_concat_i64_i128(dest, destl, desth);
238
+ decode_save_opc(ctx);
239
+ tcg_gen_atomic_cmpxchg_i128(dest, src1, dest, src2, ctx->mem_idx,
240
+ (MO_ALIGN | MO_TEUO));
241
+
242
+ tcg_gen_extr_i128_i64(destl, desth, dest);
243
+
244
+ if (a->rd != 0) {
245
+ gen_set_gpr(ctx, a->rd, destl);
246
+ gen_set_gpr(ctx, a->rd + 1, desth);
247
+ }
248
+#endif
249
+
250
+ return true;
251
+}
252
--
50
--
253
2.43.0
51
2.48.1
diff view generated by jsdifflib
1
From: Bin Meng <bmeng@tinylab.org>
1
From: Kaiwen Xue <kaiwenx@rivosinc.com>
2
2
3
Currently, the documentation outlines the process for building the
3
This adds definitions for counter delegation, including the new
4
S-mode U-Boot image using `make menuconfig` and manual actions within
4
scountinhibit register and the mstateen.CD bit.
5
the menuconfig UI. However, this approach is fragile due to Kconfig
6
options potentially changing across different releases. For example,
7
CONFIG_OF_PRIOR_STAGE has been replaced by CONFIG_BOARD since v2022.01
8
release, and CONFIG_TEXT_BASE has been moved to the 'General setup'
9
menu from the 'Boot options' menu in v2024.01 release.
10
5
11
This update aims to make the S-mode U-Boot image build instructions
6
Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com>
12
future-proof. It leverages the 'config' script provided in the U-Boot
13
source tree to edit the .config file, followed by a `make olddefconfig`.
14
15
Validated with U-Boot v2024.01 release.
16
17
Signed-off-by: Bin Meng <bmeng@tinylab.org>
18
19
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Message-ID: <20240104071523.273702-1-bmeng@tinylab.org>
8
Signed-off-by: Atish Patra <atishp@rivosinc.com>
9
Message-ID: <20250110-counter_delegation-v5-6-e83d797ae294@rivosinc.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
---
11
---
23
docs/system/riscv/sifive_u.rst | 33 ++++++++++++---------------------
12
target/riscv/cpu.h | 1 +
24
1 file changed, 12 insertions(+), 21 deletions(-)
13
target/riscv/cpu_bits.h | 8 +++++++-
14
target/riscv/machine.c | 1 +
15
3 files changed, 9 insertions(+), 1 deletion(-)
25
16
26
diff --git a/docs/system/riscv/sifive_u.rst b/docs/system/riscv/sifive_u.rst
17
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
27
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
28
--- a/docs/system/riscv/sifive_u.rst
19
--- a/target/riscv/cpu.h
29
+++ b/docs/system/riscv/sifive_u.rst
20
+++ b/target/riscv/cpu.h
30
@@ -XXX,XX +XXX,XX @@ command line options with ``qemu-system-riscv32``.
21
@@ -XXX,XX +XXX,XX @@ struct CPUArchState {
31
Running U-Boot
22
uint32_t scounteren;
32
--------------
23
uint32_t mcounteren;
33
24
34
-U-Boot mainline v2021.07 release is tested at the time of writing. To build a
25
+ uint32_t scountinhibit;
35
+U-Boot mainline v2024.01 release is tested at the time of writing. To build a
26
uint32_t mcountinhibit;
36
U-Boot mainline bootloader that can be booted by the ``sifive_u`` machine, use
27
37
the sifive_unleashed_defconfig with similar commands as described above for
28
/* PMU cycle & instret privilege mode filtering */
38
Linux:
29
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
39
@@ -XXX,XX +XXX,XX @@ configuration of U-Boot:
30
index XXXXXXX..XXXXXXX 100644
40
31
--- a/target/riscv/cpu_bits.h
41
$ export CROSS_COMPILE=riscv64-linux-
32
+++ b/target/riscv/cpu_bits.h
42
$ make sifive_unleashed_defconfig
33
@@ -XXX,XX +XXX,XX @@
43
- $ make menuconfig
34
#define CSR_SSTATEEN2 0x10E
44
-
35
#define CSR_SSTATEEN3 0x10F
45
-then manually select the following configuration:
36
46
-
37
+/* Supervisor Counter Delegation */
47
- * Device Tree Control ---> Provider of DTB for DT Control ---> Prior Stage bootloader DTB
38
+#define CSR_SCOUNTINHIBIT 0x120
48
-
39
+
49
-and unselect the following configuration:
40
/* Supervisor Trap Handling */
50
-
41
#define CSR_SSCRATCH 0x140
51
- * Library routines ---> Allow access to binman information in the device tree
42
#define CSR_SEPC 0x141
52
+ $ ./scripts/config --enable OF_BOARD
43
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
53
+ $ ./scripts/config --disable BINMAN_FDT
44
#define MENVCFG_CBCFE BIT(6)
54
+ $ ./scripts/config --disable SPL
45
#define MENVCFG_CBZE BIT(7)
55
+ $ make olddefconfig
46
#define MENVCFG_PMM (3ULL << 32)
56
47
+#define MENVCFG_CDE (1ULL << 60)
57
This changes U-Boot to use the QEMU generated device tree blob, and bypass
48
#define MENVCFG_ADUE (1ULL << 61)
58
running the U-Boot SPL stage.
49
#define MENVCFG_PBMTE (1ULL << 62)
59
@@ -XXX,XX +XXX,XX @@ It's possible to create a 32-bit U-Boot S-mode image as well.
50
#define MENVCFG_STCE (1ULL << 63)
60
51
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
61
$ export CROSS_COMPILE=riscv64-linux-
52
#define ISELECT_IMSIC_LAST ISELECT_IMSIC_EIE63
62
$ make sifive_unleashed_defconfig
53
#define ISELECT_MASK_AIA 0x1ff
63
- $ make menuconfig
54
64
-
55
-/* MISELECT, SISELECT, and VSISELECT bits (AIA) */
65
-then manually update the following configuration in U-Boot:
56
+/* [M|S|VS]SELCT value for Indirect CSR Access Extension */
66
-
57
+#define ISELECT_CD_FIRST 0x40
67
- * Device Tree Control ---> Provider of DTB for DT Control ---> Prior Stage bootloader DTB
58
+#define ISELECT_CD_LAST 0x5f
68
- * RISC-V architecture ---> Base ISA ---> RV32I
59
#define ISELECT_MASK_SXCSRIND 0xfff
69
- * Boot options ---> Boot images ---> Text Base ---> 0x80400000
60
70
-
61
/* Dummy [M|S|VS]ISELECT value for emulating [M|S|VS]TOPEI CSRs */
71
-and unselect the following configuration:
62
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
72
-
63
index XXXXXXX..XXXXXXX 100644
73
- * Library routines ---> Allow access to binman information in the device tree
64
--- a/target/riscv/machine.c
74
+ $ ./scripts/config --disable ARCH_RV64I
65
+++ b/target/riscv/machine.c
75
+ $ ./scripts/config --enable ARCH_RV32I
66
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = {
76
+ $ ./scripts/config --set-val TEXT_BASE 0x80400000
67
VMSTATE_UINTTL(env.siselect, RISCVCPU),
77
+ $ ./scripts/config --enable OF_BOARD
68
VMSTATE_UINT32(env.scounteren, RISCVCPU),
78
+ $ ./scripts/config --disable BINMAN_FDT
69
VMSTATE_UINT32(env.mcounteren, RISCVCPU),
79
+ $ ./scripts/config --disable SPL
70
+ VMSTATE_UINT32(env.scountinhibit, RISCVCPU),
80
+ $ make olddefconfig
71
VMSTATE_UINT32(env.mcountinhibit, RISCVCPU),
81
72
VMSTATE_STRUCT_ARRAY(env.pmu_ctrs, RISCVCPU, RV_MAX_MHPMCOUNTERS, 0,
82
Use the same command line options to boot the 32-bit U-Boot S-mode image:
73
vmstate_pmu_ctr_state, PMUCTRState),
83
84
--
74
--
85
2.43.0
75
2.48.1
diff view generated by jsdifflib
1
From: Sunil V L <sunilvl@ventanamicro.com>
1
From: Kaiwen Xue <kaiwenx@rivosinc.com>
2
2
3
Add basic IO controllers and devices like PCI, VirtIO and UART in the
3
This adds checks in ops performed on xireg and xireg2-xireg6 so that the
4
ACPI namespace.
4
counter delegation function will receive a valid xiselect value with the
5
proper extensions enabled.
5
6
6
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
7
Co-developed-by: Atish Patra <atishp@rivosinc.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com>
8
Acked-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Acked-by: Michael S. Tsirkin <mst@redhat.com>
10
Signed-off-by: Atish Patra <atishp@rivosinc.com>
10
Message-ID: <20231218150247.466427-13-sunilvl@ventanamicro.com>
11
Message-ID: <20250110-counter_delegation-v5-7-e83d797ae294@rivosinc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
---
13
hw/riscv/virt-acpi-build.c | 79 ++++++++++++++++++++++++++++++++++++--
14
target/riscv/csr.c | 36 +++++++++++++++++++++++++++++++++++-
14
hw/riscv/Kconfig | 1 +
15
1 file changed, 35 insertions(+), 1 deletion(-)
15
2 files changed, 76 insertions(+), 4 deletions(-)
16
16
17
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
17
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
18
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/riscv/virt-acpi-build.c
19
--- a/target/riscv/csr.c
20
+++ b/hw/riscv/virt-acpi-build.c
20
+++ b/target/riscv/csr.c
21
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@ static bool xiselect_aia_range(target_ulong isel)
22
#include "hw/acpi/acpi-defs.h"
22
(ISELECT_IMSIC_FIRST <= isel && isel <= ISELECT_IMSIC_LAST);
23
#include "hw/acpi/acpi.h"
24
#include "hw/acpi/aml-build.h"
25
+#include "hw/acpi/pci.h"
26
#include "hw/acpi/utils.h"
27
+#include "hw/intc/riscv_aclint.h"
28
#include "hw/nvram/fw_cfg_acpi.h"
29
+#include "hw/pci-host/gpex.h"
30
+#include "hw/riscv/virt.h"
31
+#include "hw/riscv/numa.h"
32
+#include "hw/virtio/virtio-acpi.h"
33
+#include "migration/vmstate.h"
34
#include "qapi/error.h"
35
#include "qemu/error-report.h"
36
#include "sysemu/reset.h"
37
-#include "migration/vmstate.h"
38
-#include "hw/riscv/virt.h"
39
-#include "hw/riscv/numa.h"
40
-#include "hw/intc/riscv_aclint.h"
41
42
#define ACPI_BUILD_TABLE_SIZE 0x20000
43
#define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
44
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s)
45
}
46
}
23
}
47
24
48
+static void
25
+static bool xiselect_cd_range(target_ulong isel)
49
+acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap,
50
+ uint32_t uart_irq)
51
+{
26
+{
52
+ Aml *dev = aml_device("COM0");
27
+ return (ISELECT_CD_FIRST <= isel && isel <= ISELECT_CD_LAST);
53
+ aml_append(dev, aml_name_decl("_HID", aml_string("PNP0501")));
54
+ aml_append(dev, aml_name_decl("_UID", aml_int(0)));
55
+
56
+ Aml *crs = aml_resource_template();
57
+ aml_append(crs, aml_memory32_fixed(uart_memmap->base,
58
+ uart_memmap->size, AML_READ_WRITE));
59
+ aml_append(crs,
60
+ aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
61
+ AML_EXCLUSIVE, &uart_irq, 1));
62
+ aml_append(dev, aml_name_decl("_CRS", crs));
63
+
64
+ Aml *pkg = aml_package(2);
65
+ aml_append(pkg, aml_string("clock-frequency"));
66
+ aml_append(pkg, aml_int(3686400));
67
+
68
+ Aml *UUID = aml_touuid("DAFFD814-6EBA-4D8C-8A91-BC9BBF4AA301");
69
+
70
+ Aml *pkg1 = aml_package(1);
71
+ aml_append(pkg1, pkg);
72
+
73
+ Aml *package = aml_package(2);
74
+ aml_append(package, UUID);
75
+ aml_append(package, pkg1);
76
+
77
+ aml_append(dev, aml_name_decl("_DSD", package));
78
+ aml_append(scope, dev);
79
+}
28
+}
80
+
29
+
81
/* RHCT Node[N] starts at offset 56 */
30
static int rmw_iprio(target_ulong xlen,
82
#define RHCT_NODE_ARRAY_OFFSET 56
31
target_ulong iselect, uint8_t *iprio,
83
32
target_ulong *val, target_ulong new_val,
84
@@ -XXX,XX +XXX,XX @@ static void build_dsdt(GArray *table_data,
33
@@ -XXX,XX +XXX,XX @@ done:
85
RISCVVirtState *s)
34
return RISCV_EXCP_NONE;
35
}
36
37
+static int rmw_xireg_cd(CPURISCVState *env, int csrno,
38
+ target_ulong isel, target_ulong *val,
39
+ target_ulong new_val, target_ulong wr_mask)
40
+{
41
+ if (!riscv_cpu_cfg(env)->ext_smcdeleg) {
42
+ return RISCV_EXCP_ILLEGAL_INST;
43
+ }
44
+ /* TODO: Implement the functionality later */
45
+ return RISCV_EXCP_NONE;
46
+}
47
+
48
/*
49
* rmw_xireg_csrind: Perform indirect access to xireg and xireg2-xireg6
50
*
51
@@ -XXX,XX +XXX,XX @@ static int rmw_xireg_csrind(CPURISCVState *env, int csrno,
52
target_ulong isel, target_ulong *val,
53
target_ulong new_val, target_ulong wr_mask)
86
{
54
{
87
Aml *scope, *dsdt;
55
- return -EINVAL;
88
+ MachineState *ms = MACHINE(s);
56
+ int ret = -EINVAL;
89
+ uint8_t socket_count;
57
+ bool virt = csrno == CSR_VSIREG ? true : false;
90
const MemMapEntry *memmap = s->memmap;
91
AcpiTable table = { .sig = "DSDT", .rev = 2, .oem_id = s->oem_id,
92
.oem_table_id = s->oem_table_id };
93
@@ -XXX,XX +XXX,XX @@ static void build_dsdt(GArray *table_data,
94
95
fw_cfg_acpi_dsdt_add(scope, &memmap[VIRT_FW_CFG]);
96
97
+ socket_count = riscv_socket_count(ms);
98
+
58
+
99
+ acpi_dsdt_add_uart(scope, &memmap[VIRT_UART0], UART0_IRQ);
59
+ if (xiselect_cd_range(isel)) {
100
+
60
+ ret = rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask);
101
+ if (socket_count == 1) {
102
+ virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base,
103
+ memmap[VIRT_VIRTIO].size,
104
+ VIRTIO_IRQ, 0, VIRTIO_COUNT);
105
+ acpi_dsdt_add_gpex_host(scope, PCIE_IRQ);
106
+ } else if (socket_count == 2) {
107
+ virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base,
108
+ memmap[VIRT_VIRTIO].size,
109
+ VIRTIO_IRQ + VIRT_IRQCHIP_NUM_SOURCES, 0,
110
+ VIRTIO_COUNT);
111
+ acpi_dsdt_add_gpex_host(scope, PCIE_IRQ + VIRT_IRQCHIP_NUM_SOURCES);
112
+ } else {
61
+ } else {
113
+ virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base,
62
+ /*
114
+ memmap[VIRT_VIRTIO].size,
63
+ * As per the specification, access to unimplented region is undefined
115
+ VIRTIO_IRQ + VIRT_IRQCHIP_NUM_SOURCES, 0,
64
+ * but recommendation is to raise illegal instruction exception.
116
+ VIRTIO_COUNT);
65
+ */
117
+ acpi_dsdt_add_gpex_host(scope, PCIE_IRQ + VIRT_IRQCHIP_NUM_SOURCES * 2);
66
+ return RISCV_EXCP_ILLEGAL_INST;
118
+ }
67
+ }
119
+
68
+
120
aml_append(dsdt, scope);
69
+ if (ret) {
121
70
+ return (env->virt_enabled && virt) ?
122
/* copy AML table into ACPI tables blob and patch header there */
71
+ RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST;
123
@@ -XXX,XX +XXX,XX @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)
124
acpi_add_table(table_offsets, tables_blob);
125
build_rhct(tables_blob, tables->linker, s);
126
127
+ acpi_add_table(table_offsets, tables_blob);
128
+ {
129
+ AcpiMcfgInfo mcfg = {
130
+ .base = s->memmap[VIRT_PCIE_MMIO].base,
131
+ .size = s->memmap[VIRT_PCIE_MMIO].size,
132
+ };
133
+ build_mcfg(tables_blob, tables->linker, &mcfg, s->oem_id,
134
+ s->oem_table_id);
135
+ }
72
+ }
136
+
73
+
137
/* XSDT is pointed to by RSDP */
74
+ return RISCV_EXCP_NONE;
138
xsdt = tables_blob->len;
75
}
139
build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id,
76
140
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
77
static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val,
141
index XXXXXXX..XXXXXXX 100644
142
--- a/hw/riscv/Kconfig
143
+++ b/hw/riscv/Kconfig
144
@@ -XXX,XX +XXX,XX @@ config RISCV_VIRT
145
select FW_CFG_DMA
146
select PLATFORM_BUS
147
select ACPI
148
+ select ACPI_PCI
149
150
config SHAKTI_C
151
bool
152
--
78
--
153
2.43.0
79
2.48.1
diff view generated by jsdifflib
1
From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
1
From: Kaiwen Xue <kaiwenx@rivosinc.com>
2
2
3
If CPU does not implement the Vector extension, it usually means
3
The Smcdeleg/Ssccfg adds the support for counter delegation via
4
mstatus vs hardwire to zero. So we should not allow write a
4
S*indcsr and Ssccfg.
5
non-zero value to this field.
6
5
7
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
6
It also adds a new shadow CSR scountinhibit and menvcfg enable bit (CDE)
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
to enable this extension and scountovf virtualization.
9
Message-ID: <20231215023313.1708-1-zhiwei_liu@linux.alibaba.com>
8
9
Signed-off-by: Kaiwen Xue <kaiwenx@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>
13
Signed-off-by: Atish Patra <atishp@rivosinc.com>
14
Message-ID: <20250110-counter_delegation-v5-8-e83d797ae294@rivosinc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
16
---
12
target/riscv/csr.c | 5 ++++-
17
target/riscv/csr.c | 304 +++++++++++++++++++++++++++++++++++++++++++--
13
1 file changed, 4 insertions(+), 1 deletion(-)
18
1 file changed, 292 insertions(+), 12 deletions(-)
14
19
15
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
20
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
16
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/csr.c
22
--- a/target/riscv/csr.c
18
+++ b/target/riscv/csr.c
23
+++ b/target/riscv/csr.c
19
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
24
@@ -XXX,XX +XXX,XX @@ static RISCVException aia_smode32(CPURISCVState *env, int csrno)
20
mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE |
25
return smode32(env, csrno);
21
MSTATUS_SPP | MSTATUS_MPRV | MSTATUS_SUM |
26
}
22
MSTATUS_MPP | MSTATUS_MXR | MSTATUS_TVM | MSTATUS_TSR |
27
23
- MSTATUS_TW | MSTATUS_VS;
28
+static RISCVException scountinhibit_pred(CPURISCVState *env, int csrno)
24
+ MSTATUS_TW;
29
+{
25
30
+ RISCVCPU *cpu = env_archcpu(env);
26
if (riscv_has_ext(env, RVF)) {
31
+
27
mask |= MSTATUS_FS;
32
+ if (!cpu->cfg.ext_ssccfg || !cpu->cfg.ext_smcdeleg) {
33
+ return RISCV_EXCP_ILLEGAL_INST;
34
+ }
35
+
36
+ if (env->virt_enabled) {
37
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
38
+ }
39
+
40
+ return smode(env, csrno);
41
+}
42
+
43
static bool csrind_extensions_present(CPURISCVState *env)
44
{
45
return riscv_cpu_cfg(env)->ext_smcsrind || riscv_cpu_cfg(env)->ext_sscsrind;
46
@@ -XXX,XX +XXX,XX @@ done:
47
return result;
48
}
49
50
-static RISCVException write_mhpmcounter(CPURISCVState *env, int csrno,
51
- target_ulong val)
52
+static RISCVException riscv_pmu_write_ctr(CPURISCVState *env, target_ulong val,
53
+ uint32_t ctr_idx)
54
{
55
- int ctr_idx = csrno - CSR_MCYCLE;
56
PMUCTRState *counter = &env->pmu_ctrs[ctr_idx];
57
uint64_t mhpmctr_val = val;
58
59
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mhpmcounter(CPURISCVState *env, int csrno,
60
return RISCV_EXCP_NONE;
61
}
62
63
-static RISCVException write_mhpmcounterh(CPURISCVState *env, int csrno,
64
- target_ulong val)
65
+static RISCVException riscv_pmu_write_ctrh(CPURISCVState *env, target_ulong val,
66
+ uint32_t ctr_idx)
67
{
68
- int ctr_idx = csrno - CSR_MCYCLEH;
69
PMUCTRState *counter = &env->pmu_ctrs[ctr_idx];
70
uint64_t mhpmctr_val = counter->mhpmcounter_val;
71
uint64_t mhpmctrh_val = val;
72
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mhpmcounterh(CPURISCVState *env, int csrno,
73
return RISCV_EXCP_NONE;
74
}
75
76
+static int write_mhpmcounter(CPURISCVState *env, int csrno, target_ulong val)
77
+{
78
+ int ctr_idx = csrno - CSR_MCYCLE;
79
+
80
+ return riscv_pmu_write_ctr(env, val, ctr_idx);
81
+}
82
+
83
+static int write_mhpmcounterh(CPURISCVState *env, int csrno, target_ulong val)
84
+{
85
+ int ctr_idx = csrno - CSR_MCYCLEH;
86
+
87
+ return riscv_pmu_write_ctrh(env, val, ctr_idx);
88
+}
89
+
90
RISCVException riscv_pmu_read_ctr(CPURISCVState *env, target_ulong *val,
91
bool upper_half, uint32_t ctr_idx)
92
{
93
@@ -XXX,XX +XXX,XX @@ static RISCVException read_hpmcounterh(CPURISCVState *env, int csrno,
94
return riscv_pmu_read_ctr(env, val, true, ctr_index);
95
}
96
97
+static int rmw_cd_mhpmcounter(CPURISCVState *env, int ctr_idx,
98
+ target_ulong *val, target_ulong new_val,
99
+ target_ulong wr_mask)
100
+{
101
+ if (wr_mask != 0 && wr_mask != -1) {
102
+ return -EINVAL;
103
+ }
104
+
105
+ if (!wr_mask && val) {
106
+ riscv_pmu_read_ctr(env, val, false, ctr_idx);
107
+ } else if (wr_mask) {
108
+ riscv_pmu_write_ctr(env, new_val, ctr_idx);
109
+ } else {
110
+ return -EINVAL;
111
+ }
112
+
113
+ return 0;
114
+}
115
+
116
+static int rmw_cd_mhpmcounterh(CPURISCVState *env, int ctr_idx,
117
+ target_ulong *val, target_ulong new_val,
118
+ target_ulong wr_mask)
119
+{
120
+ if (wr_mask != 0 && wr_mask != -1) {
121
+ return -EINVAL;
122
+ }
123
+
124
+ if (!wr_mask && val) {
125
+ riscv_pmu_read_ctr(env, val, true, ctr_idx);
126
+ } else if (wr_mask) {
127
+ riscv_pmu_write_ctrh(env, new_val, ctr_idx);
128
+ } else {
129
+ return -EINVAL;
130
+ }
131
+
132
+ return 0;
133
+}
134
+
135
+static int rmw_cd_mhpmevent(CPURISCVState *env, int evt_index,
136
+ target_ulong *val, target_ulong new_val,
137
+ target_ulong wr_mask)
138
+{
139
+ uint64_t mhpmevt_val = new_val;
140
+
141
+ if (wr_mask != 0 && wr_mask != -1) {
142
+ return -EINVAL;
143
+ }
144
+
145
+ if (!wr_mask && val) {
146
+ *val = env->mhpmevent_val[evt_index];
147
+ if (riscv_cpu_cfg(env)->ext_sscofpmf) {
148
+ *val &= ~MHPMEVENT_BIT_MINH;
149
+ }
150
+ } else if (wr_mask) {
151
+ wr_mask &= ~MHPMEVENT_BIT_MINH;
152
+ mhpmevt_val = (new_val & wr_mask) |
153
+ (env->mhpmevent_val[evt_index] & ~wr_mask);
154
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
155
+ mhpmevt_val = mhpmevt_val |
156
+ ((uint64_t)env->mhpmeventh_val[evt_index] << 32);
157
+ }
158
+ env->mhpmevent_val[evt_index] = mhpmevt_val;
159
+ riscv_pmu_update_event_map(env, mhpmevt_val, evt_index);
160
+ } else {
161
+ return -EINVAL;
162
+ }
163
+
164
+ return 0;
165
+}
166
+
167
+static int rmw_cd_mhpmeventh(CPURISCVState *env, int evt_index,
168
+ target_ulong *val, target_ulong new_val,
169
+ target_ulong wr_mask)
170
+{
171
+ uint64_t mhpmevth_val;
172
+ uint64_t mhpmevt_val = env->mhpmevent_val[evt_index];
173
+
174
+ if (wr_mask != 0 && wr_mask != -1) {
175
+ return -EINVAL;
176
+ }
177
+
178
+ if (!wr_mask && val) {
179
+ *val = env->mhpmeventh_val[evt_index];
180
+ if (riscv_cpu_cfg(env)->ext_sscofpmf) {
181
+ *val &= ~MHPMEVENTH_BIT_MINH;
182
+ }
183
+ } else if (wr_mask) {
184
+ wr_mask &= ~MHPMEVENTH_BIT_MINH;
185
+ env->mhpmeventh_val[evt_index] =
186
+ (new_val & wr_mask) | (env->mhpmeventh_val[evt_index] & ~wr_mask);
187
+ mhpmevth_val = env->mhpmeventh_val[evt_index];
188
+ mhpmevt_val = mhpmevt_val | (mhpmevth_val << 32);
189
+ riscv_pmu_update_event_map(env, mhpmevt_val, evt_index);
190
+ } else {
191
+ return -EINVAL;
192
+ }
193
+
194
+ return 0;
195
+}
196
+
197
+static int rmw_cd_ctr_cfg(CPURISCVState *env, int cfg_index, target_ulong *val,
198
+ target_ulong new_val, target_ulong wr_mask)
199
+{
200
+ switch (cfg_index) {
201
+ case 0: /* CYCLECFG */
202
+ if (wr_mask) {
203
+ wr_mask &= ~MCYCLECFG_BIT_MINH;
204
+ env->mcyclecfg = (new_val & wr_mask) | (env->mcyclecfg & ~wr_mask);
205
+ } else {
206
+ *val = env->mcyclecfg &= ~MHPMEVENTH_BIT_MINH;
207
+ }
208
+ break;
209
+ case 2: /* INSTRETCFG */
210
+ if (wr_mask) {
211
+ wr_mask &= ~MINSTRETCFG_BIT_MINH;
212
+ env->minstretcfg = (new_val & wr_mask) |
213
+ (env->minstretcfg & ~wr_mask);
214
+ } else {
215
+ *val = env->minstretcfg &= ~MHPMEVENTH_BIT_MINH;
216
+ }
217
+ break;
218
+ default:
219
+ return -EINVAL;
220
+ }
221
+ return 0;
222
+}
223
+
224
+static int rmw_cd_ctr_cfgh(CPURISCVState *env, int cfg_index, target_ulong *val,
225
+ target_ulong new_val, target_ulong wr_mask)
226
+{
227
+
228
+ if (riscv_cpu_mxl(env) != MXL_RV32) {
229
+ return RISCV_EXCP_ILLEGAL_INST;
230
+ }
231
+
232
+ switch (cfg_index) {
233
+ case 0: /* CYCLECFGH */
234
+ if (wr_mask) {
235
+ wr_mask &= ~MCYCLECFGH_BIT_MINH;
236
+ env->mcyclecfgh = (new_val & wr_mask) |
237
+ (env->mcyclecfgh & ~wr_mask);
238
+ } else {
239
+ *val = env->mcyclecfgh;
240
+ }
241
+ break;
242
+ case 2: /* INSTRETCFGH */
243
+ if (wr_mask) {
244
+ wr_mask &= ~MINSTRETCFGH_BIT_MINH;
245
+ env->minstretcfgh = (new_val & wr_mask) |
246
+ (env->minstretcfgh & ~wr_mask);
247
+ } else {
248
+ *val = env->minstretcfgh;
249
+ }
250
+ break;
251
+ default:
252
+ return -EINVAL;
253
+ }
254
+ return 0;
255
+}
256
+
257
+
258
static RISCVException read_scountovf(CPURISCVState *env, int csrno,
259
target_ulong *val)
260
{
261
@@ -XXX,XX +XXX,XX @@ static RISCVException read_scountovf(CPURISCVState *env, int csrno,
262
target_ulong *mhpm_evt_val;
263
uint64_t of_bit_mask;
264
265
+ /* Virtualize scountovf for counter delegation */
266
+ if (riscv_cpu_cfg(env)->ext_sscofpmf &&
267
+ riscv_cpu_cfg(env)->ext_ssccfg &&
268
+ get_field(env->menvcfg, MENVCFG_CDE) &&
269
+ env->virt_enabled) {
270
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
271
+ }
272
+
273
if (riscv_cpu_mxl(env) == MXL_RV32) {
274
mhpm_evt_val = env->mhpmeventh_val;
275
of_bit_mask = MHPMEVENTH_BIT_OF;
276
@@ -XXX,XX +XXX,XX @@ static int rmw_xireg_cd(CPURISCVState *env, int csrno,
277
target_ulong isel, target_ulong *val,
278
target_ulong new_val, target_ulong wr_mask)
279
{
280
- if (!riscv_cpu_cfg(env)->ext_smcdeleg) {
281
- return RISCV_EXCP_ILLEGAL_INST;
282
+ int ret = -EINVAL;
283
+ int ctr_index = isel - ISELECT_CD_FIRST;
284
+ int isel_hpm_start = ISELECT_CD_FIRST + 3;
285
+
286
+ if (!riscv_cpu_cfg(env)->ext_smcdeleg || !riscv_cpu_cfg(env)->ext_ssccfg) {
287
+ ret = RISCV_EXCP_ILLEGAL_INST;
288
+ goto done;
28
}
289
}
29
+ if (riscv_has_ext(env, RVV)) {
290
- /* TODO: Implement the functionality later */
30
+ mask |= MSTATUS_VS;
291
- return RISCV_EXCP_NONE;
31
+ }
292
+
32
293
+ /* Invalid siselect value for reserved */
33
if (xl != MXL_RV32 || env->debugger) {
294
+ if (ctr_index == 1) {
34
if (riscv_has_ext(env, RVH)) {
295
+ goto done;
296
+ }
297
+
298
+ /* sireg4 and sireg5 provides access RV32 only CSRs */
299
+ if (((csrno == CSR_SIREG5) || (csrno == CSR_SIREG4)) &&
300
+ (riscv_cpu_mxl(env) != MXL_RV32)) {
301
+ ret = RISCV_EXCP_ILLEGAL_INST;
302
+ goto done;
303
+ }
304
+
305
+ /* Check Sscofpmf dependancy */
306
+ if (!riscv_cpu_cfg(env)->ext_sscofpmf && csrno == CSR_SIREG5 &&
307
+ (isel_hpm_start <= isel && isel <= ISELECT_CD_LAST)) {
308
+ goto done;
309
+ }
310
+
311
+ /* Check smcntrpmf dependancy */
312
+ if (!riscv_cpu_cfg(env)->ext_smcntrpmf &&
313
+ (csrno == CSR_SIREG2 || csrno == CSR_SIREG5) &&
314
+ (ISELECT_CD_FIRST <= isel && isel < isel_hpm_start)) {
315
+ goto done;
316
+ }
317
+
318
+ if (!get_field(env->mcounteren, BIT(ctr_index)) ||
319
+ !get_field(env->menvcfg, MENVCFG_CDE)) {
320
+ goto done;
321
+ }
322
+
323
+ switch (csrno) {
324
+ case CSR_SIREG:
325
+ ret = rmw_cd_mhpmcounter(env, ctr_index, val, new_val, wr_mask);
326
+ break;
327
+ case CSR_SIREG4:
328
+ ret = rmw_cd_mhpmcounterh(env, ctr_index, val, new_val, wr_mask);
329
+ break;
330
+ case CSR_SIREG2:
331
+ if (ctr_index <= 2) {
332
+ ret = rmw_cd_ctr_cfg(env, ctr_index, val, new_val, wr_mask);
333
+ } else {
334
+ ret = rmw_cd_mhpmevent(env, ctr_index, val, new_val, wr_mask);
335
+ }
336
+ break;
337
+ case CSR_SIREG5:
338
+ if (ctr_index <= 2) {
339
+ ret = rmw_cd_ctr_cfgh(env, ctr_index, val, new_val, wr_mask);
340
+ } else {
341
+ ret = rmw_cd_mhpmeventh(env, ctr_index, val, new_val, wr_mask);
342
+ }
343
+ break;
344
+ default:
345
+ goto done;
346
+ }
347
+
348
+done:
349
+ return ret;
350
}
351
352
/*
353
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mcountinhibit(CPURISCVState *env, int csrno,
354
return RISCV_EXCP_NONE;
355
}
356
357
+static RISCVException read_scountinhibit(CPURISCVState *env, int csrno,
358
+ target_ulong *val)
359
+{
360
+ /* S-mode can only access the bits delegated by M-mode */
361
+ *val = env->mcountinhibit & env->mcounteren;
362
+ return RISCV_EXCP_NONE;
363
+}
364
+
365
+static RISCVException write_scountinhibit(CPURISCVState *env, int csrno,
366
+ target_ulong val)
367
+{
368
+ write_mcountinhibit(env, csrno, val & env->mcounteren);
369
+ return RISCV_EXCP_NONE;
370
+}
371
+
372
static RISCVException read_mcounteren(CPURISCVState *env, int csrno,
373
target_ulong *val)
374
{
375
@@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
376
target_ulong val)
377
{
378
const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
379
- uint64_t mask = MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE | MENVCFG_CBZE;
380
+ uint64_t mask = MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE |
381
+ MENVCFG_CBZE | MENVCFG_CDE;
382
383
if (riscv_cpu_mxl(env) == MXL_RV64) {
384
mask |= (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) |
385
(cfg->ext_sstc ? MENVCFG_STCE : 0) |
386
+ (cfg->ext_smcdeleg ? MENVCFG_CDE : 0) |
387
(cfg->ext_svadu ? MENVCFG_ADUE : 0);
388
389
if (env_archcpu(env)->cfg.ext_zicfilp) {
390
@@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno,
391
const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
392
uint64_t mask = (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) |
393
(cfg->ext_sstc ? MENVCFG_STCE : 0) |
394
- (cfg->ext_svadu ? MENVCFG_ADUE : 0);
395
+ (cfg->ext_svadu ? MENVCFG_ADUE : 0) |
396
+ (cfg->ext_smcdeleg ? MENVCFG_CDE : 0);
397
uint64_t valh = (uint64_t)val << 32;
398
399
env->menvcfg = (env->menvcfg & ~mask) | (valh & mask);
400
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
401
[CSR_MNSTATUS] = { "mnstatus", rnmi, read_mnstatus, write_mnstatus,
402
.min_priv_ver = PRIV_VERSION_1_12_0 },
403
404
+ /* Supervisor Counter Delegation */
405
+ [CSR_SCOUNTINHIBIT] = {"scountinhibit", scountinhibit_pred,
406
+ read_scountinhibit, write_scountinhibit,
407
+ .min_priv_ver = PRIV_VERSION_1_12_0 },
408
+
409
/* Supervisor Trap Setup */
410
[CSR_SSTATUS] = { "sstatus", smode, read_sstatus, write_sstatus,
411
NULL, read_sstatus_i128 },
35
--
412
--
36
2.43.0
413
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Atish Patra <atishp@rivosinc.com>
2
2
3
Previous patches added several g_hash_table_insert() patterns. Add two
3
The dependant ISA features are enabled at the end of cpu_realize
4
helpers, one for each user hash, to make the code cleaner.
4
in finalize_features. Thus, PMU init should be invoked after that
5
only. Move the init invocation to riscv_tcg_cpu_finalize_features.
5
6
6
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-ID: <20231218125334.37184-15-dbarboza@ventanamicro.com>
8
Signed-off-by: Atish Patra <atishp@rivosinc.com>
9
Message-ID: <20250110-counter_delegation-v5-9-e83d797ae294@rivosinc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
11
---
12
target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++++------------
12
target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++--------------
13
1 file changed, 16 insertions(+), 12 deletions(-)
13
1 file changed, 14 insertions(+), 14 deletions(-)
14
14
15
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
15
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
16
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/tcg/tcg-cpu.c
17
--- a/target/riscv/tcg/tcg-cpu.c
18
+++ b/target/riscv/tcg/tcg-cpu.c
18
+++ b/target/riscv/tcg/tcg-cpu.c
19
@@ -XXX,XX +XXX,XX @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
19
@@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
20
GUINT_TO_POINTER(ext_offset));
20
error_propagate(errp, local_err);
21
}
22
23
+static void cpu_cfg_ext_add_user_opt(uint32_t ext_offset, bool value)
24
+{
25
+ g_hash_table_insert(multi_ext_user_opts, GUINT_TO_POINTER(ext_offset),
26
+ (gpointer)value);
27
+}
28
+
29
+static void cpu_misa_ext_add_user_opt(uint32_t bit, bool value)
30
+{
31
+ g_hash_table_insert(misa_ext_user_opts, GUINT_TO_POINTER(bit),
32
+ (gpointer)value);
33
+}
34
+
35
static void riscv_cpu_write_misa_bit(RISCVCPU *cpu, uint32_t bit,
36
bool enabled)
37
{
38
@@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
39
return;
21
return;
40
}
22
}
41
23
+#ifndef CONFIG_USER_ONLY
42
- g_hash_table_insert(misa_ext_user_opts,
24
+ if (cpu->cfg.pmu_mask) {
43
- GUINT_TO_POINTER(misa_bit),
25
+ riscv_pmu_init(cpu, &local_err);
44
- (gpointer)value);
26
+ if (local_err != NULL) {
45
+ cpu_misa_ext_add_user_opt(misa_bit, value);
27
+ error_propagate(errp, local_err);
46
28
+ return;
47
prev_val = env->misa_ext & misa_bit;
29
+ }
48
30
+
49
@@ -XXX,XX +XXX,XX @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
31
+ if (cpu->cfg.ext_sscofpmf) {
50
continue;
32
+ cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
51
}
33
+ riscv_pmu_timer_cb, cpu);
52
34
+ }
53
- g_hash_table_insert(misa_ext_user_opts,
35
+ }
54
- GUINT_TO_POINTER(bit),
36
+#endif
55
- (gpointer)value);
37
}
56
+ cpu_misa_ext_add_user_opt(bit, profile->enabled);
38
57
riscv_cpu_write_misa_bit(cpu, bit, profile->enabled);
39
void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu)
40
@@ -XXX,XX +XXX,XX @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp)
41
42
#ifndef CONFIG_USER_ONLY
43
CPURISCVState *env = &cpu->env;
44
- Error *local_err = NULL;
45
46
tcg_cflags_set(CPU(cs), CF_PCREL);
47
48
@@ -XXX,XX +XXX,XX @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp)
49
riscv_timer_init(cpu);
58
}
50
}
59
51
60
@@ -XXX,XX +XXX,XX @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
52
- if (cpu->cfg.pmu_mask) {
61
cpu_bump_multi_ext_priv_ver(&cpu->env, ext_offset);
53
- riscv_pmu_init(cpu, &local_err);
62
}
54
- if (local_err != NULL) {
63
55
- error_propagate(errp, local_err);
64
- g_hash_table_insert(multi_ext_user_opts,
56
- return false;
65
- GUINT_TO_POINTER(ext_offset),
57
- }
66
- (gpointer)profile->enabled);
58
-
67
+ cpu_cfg_ext_add_user_opt(ext_offset, profile->enabled);
59
- if (cpu->cfg.ext_sscofpmf) {
68
isa_ext_update_enabled(cpu, ext_offset, profile->enabled);
60
- cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
69
}
61
- riscv_pmu_timer_cb, cpu);
70
}
62
- }
71
@@ -XXX,XX +XXX,XX @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
63
- }
72
multi_ext_cfg->name, lower);
64
-
73
}
65
/* With H-Ext, VSSIP, VSTIP, VSEIP and SGEIP are hardwired to one. */
74
66
if (riscv_has_ext(env, RVH)) {
75
- g_hash_table_insert(multi_ext_user_opts,
67
env->mideleg = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP | MIP_SGEIP;
76
- GUINT_TO_POINTER(multi_ext_cfg->offset),
77
- (gpointer)value);
78
+ cpu_cfg_ext_add_user_opt(multi_ext_cfg->offset, value);
79
80
prev_val = isa_ext_is_enabled(cpu, multi_ext_cfg->offset);
81
82
--
68
--
83
2.43.0
69
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Atish Patra <atishp@rivosinc.com>
2
2
3
The RVA22S64 profile consists of the following:
3
The counter delegation/configuration extensions depend on the following
4
extensions.
4
5
5
- all mandatory extensions of RVA22U64;
6
1. Smcdeleg - To enable counter delegation from M to S
6
- priv spec v1.12.0;
7
2. S[m|s]csrind - To enable indirect access CSRs
7
- satp mode sv39;
8
- Ssccptr, a cache related named feature that we're assuming always
9
enable since we don't implement a cache;
10
- Other named features already implemented: Sstvecd, Sstvala,
11
Sscounterenw;
12
- the new Svade named feature that was recently added.
13
8
14
Most of the work is already done, so this patch is enough to implement
9
Add an implied rule so that these extensions are enabled by default
15
the profile.
10
if the sscfg extension is enabled.
16
11
17
After this patch, the 'rva22s64' user flag alone can be used with the
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
18
rva64i CPU to boot Linux:
13
Acked-by: Alistair Francis <alistair.francis@wdc.com>
19
14
Signed-off-by: Atish Patra <atishp@rivosinc.com>
20
-cpu rv64i,rva22s64=true
15
Message-ID: <20250110-counter_delegation-v5-10-e83d797ae294@rivosinc.com>
21
22
This is the /proc/cpuinfo with this profile enabled:
23
24
# cat /proc/cpuinfo
25
processor    : 0
26
hart        : 0
27
isa        : rv64imafdc_zicbom_zicbop_zicboz_zicntr_zicsr_zifencei_zihintpause_zihpm_zfhmin_zca_zcd_zba_zbb_zbs_zkt_svinval_svpbmt
28
mmu        : sv39
29
30
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
31
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
32
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
33
Message-ID: <20231218125334.37184-26-dbarboza@ventanamicro.com>
34
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
35
---
17
---
36
target/riscv/cpu.c | 32 ++++++++++++++++++++++++++++++++
18
target/riscv/cpu.c | 12 +++++++++++-
37
1 file changed, 32 insertions(+)
19
1 file changed, 11 insertions(+), 1 deletion(-)
38
20
39
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
21
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
40
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/cpu.c
23
--- a/target/riscv/cpu.c
42
+++ b/target/riscv/cpu.c
24
+++ b/target/riscv/cpu.c
43
@@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA22U64 = {
25
@@ -XXX,XX +XXX,XX @@ static RISCVCPUImpliedExtsRule ZVKSG_IMPLIED = {
44
}
26
},
45
};
27
};
46
28
47
+/*
29
+static RISCVCPUImpliedExtsRule SSCFG_IMPLIED = {
48
+ * As with RVA22U64, RVA22S64 also defines 'named features'.
30
+ .ext = CPU_CFG_OFFSET(ext_ssccfg),
49
+ *
31
+ .implied_multi_exts = {
50
+ * Cache related features that we consider enabled since we don't
32
+ CPU_CFG_OFFSET(ext_smcsrind), CPU_CFG_OFFSET(ext_sscsrind),
51
+ * implement cache: Ssccptr
33
+ CPU_CFG_OFFSET(ext_smcdeleg),
52
+ *
53
+ * Other named features that we already implement: Sstvecd, Sstvala,
54
+ * Sscounterenw
55
+ *
56
+ * Named features that we need to enable: svade
57
+ *
58
+ * The remaining features/extensions comes from RVA22U64.
59
+ */
60
+static RISCVCPUProfile RVA22S64 = {
61
+ .parent = &RVA22U64,
62
+ .name = "rva22s64",
63
+ .misa_ext = RVS,
64
+ .priv_spec = PRIV_VERSION_1_12_0,
65
+ .satp_mode = VM_1_10_SV39,
66
+ .ext_offsets = {
67
+ /* rva22s64 exts */
68
+ CPU_CFG_OFFSET(ext_zifencei), CPU_CFG_OFFSET(ext_svpbmt),
69
+ CPU_CFG_OFFSET(ext_svinval),
70
+
34
+
71
+ /* rva22s64 named features */
35
+ RISCV_IMPLIED_EXTS_RULE_END
72
+ CPU_CFG_OFFSET(svade),
36
+ },
73
+
74
+ RISCV_PROFILE_EXT_LIST_END
75
+ }
76
+};
37
+};
77
+
38
+
78
RISCVCPUProfile *riscv_profiles[] = {
39
RISCVCPUImpliedExtsRule *riscv_misa_ext_implied_rules[] = {
79
&RVA22U64,
40
&RVA_IMPLIED, &RVD_IMPLIED, &RVF_IMPLIED,
80
+ &RVA22S64,
41
&RVM_IMPLIED, &RVV_IMPLIED, NULL
81
NULL,
42
@@ -XXX,XX +XXX,XX @@ RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[] = {
43
&ZVE64X_IMPLIED, &ZVFBFMIN_IMPLIED, &ZVFBFWMA_IMPLIED,
44
&ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVKN_IMPLIED,
45
&ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED,
46
- &ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED,
47
+ &ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED, &SSCFG_IMPLIED,
48
NULL
82
};
49
};
83
50
84
--
51
--
85
2.43.0
52
2.48.1
diff view generated by jsdifflib
1
From: Alistair Francis <alistair23@gmail.com>
1
From: Atish Patra <atishp@rivosinc.com>
2
2
3
Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor is
3
Add configuration options so that they can be enabled/disabld from
4
enabled. We currently only set them on accesses to mideleg, but they
4
qemu commandline.
5
aren't correctly set on reset. Let's ensure they are always the correct
6
value.
7
5
8
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1617
6
Acked-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Message-ID: <20240108001328.280222-4-alistair.francis@wdc.com>
8
Signed-off-by: Atish Patra <atishp@rivosinc.com>
9
Message-ID: <20250110-counter_delegation-v5-11-e83d797ae294@rivosinc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
11
---
14
target/riscv/cpu.c | 8 ++++++++
12
target/riscv/cpu.c | 4 ++++
15
1 file changed, 8 insertions(+)
13
1 file changed, 4 insertions(+)
16
14
17
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
18
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/cpu.c
17
--- a/target/riscv/cpu.c
20
+++ b/target/riscv/cpu.c
18
+++ b/target/riscv/cpu.c
21
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj)
19
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
22
/* mmte is supposed to have pm.current hardwired to 1 */
20
/* Defaults for standard extensions */
23
env->mmte |= (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT);
21
MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false),
24
22
MULTI_EXT_CFG_BOOL("smcntrpmf", ext_smcntrpmf, false),
25
+ /*
23
+ MULTI_EXT_CFG_BOOL("smcsrind", ext_smcsrind, false),
26
+ * Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor
24
+ MULTI_EXT_CFG_BOOL("smcdeleg", ext_smcdeleg, false),
27
+ * extension is enabled.
25
+ MULTI_EXT_CFG_BOOL("sscsrind", ext_sscsrind, false),
28
+ */
26
+ MULTI_EXT_CFG_BOOL("ssccfg", ext_ssccfg, false),
29
+ if (riscv_has_ext(env, RVH)) {
27
MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true),
30
+ env->mideleg |= HS_MODE_INTERRUPTS;
28
MULTI_EXT_CFG_BOOL("zicfilp", ext_zicfilp, false),
31
+ }
29
MULTI_EXT_CFG_BOOL("zicfiss", ext_zicfiss, false),
32
+
33
/*
34
* Clear mseccfg and unlock all the PMP entries upon reset.
35
* This is allowed as per the priv and smepmp specifications
36
--
30
--
37
2.43.0
31
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
Create a RISCV_CONFIG_REG() macro, similar to what other regs use, to
3
With the current implementation, if we had the following scenario:
4
hide away some of the boilerplate.
4
- Set bit x in menvcfg
5
- Set bit x in henvcfg
6
- Clear bit x in menvcfg
7
then, the internal variable env->henvcfg would still contain bit x due
8
to both a wrong menvcfg mask used in write_henvcfg() as well as a
9
missing update of henvcfg upon menvcfg update.
10
This can lead to some wrong interpretation of the context. In order to
11
update henvcfg upon menvcfg writing, call write_henvcfg() after writing
12
menvcfg. Clearing henvcfg upon writing the new value is also needed in
13
write_henvcfg() as well as clearing henvcfg upper part when writing it
14
with write_henvcfgh().
5
15
6
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
16
Signed-off-by: Clément Léger <cleger@rivosinc.com>
7
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
17
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Message-ID: <20231208183835.2411523-5-dbarboza@ventanamicro.com>
18
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
19
Message-ID: <20250110125441.3208676-2-cleger@rivosinc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
21
---
11
target/riscv/kvm/kvm-cpu.c | 25 +++++++++++--------------
22
target/riscv/csr.c | 10 ++++++++--
12
1 file changed, 11 insertions(+), 14 deletions(-)
23
1 file changed, 8 insertions(+), 2 deletions(-)
13
24
14
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
25
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
15
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/kvm/kvm-cpu.c
27
--- a/target/riscv/csr.c
17
+++ b/target/riscv/kvm/kvm-cpu.c
28
+++ b/target/riscv/csr.c
18
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id_u64(uint64_t type, uint64_t idx)
29
@@ -XXX,XX +XXX,XX @@ static RISCVException read_menvcfg(CPURISCVState *env, int csrno,
19
#define RISCV_CSR_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CSR, \
30
return RISCV_EXCP_NONE;
20
KVM_REG_RISCV_CSR_REG(name))
31
}
21
32
22
+#define RISCV_CONFIG_REG(env, name) \
33
+static RISCVException write_henvcfg(CPURISCVState *env, int csrno,
23
+ kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, \
34
+ target_ulong val);
24
+ KVM_REG_RISCV_CONFIG_REG(name))
35
static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
25
+
36
target_ulong val)
26
#define RISCV_TIMER_REG(name) kvm_riscv_reg_id_u64(KVM_REG_RISCV_TIMER, \
37
{
27
KVM_REG_RISCV_TIMER_REG(name))
38
@@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
28
39
}
29
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_machine_ids(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
30
struct kvm_one_reg reg;
31
int ret;
32
33
- reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
34
- KVM_REG_RISCV_CONFIG_REG(mvendorid));
35
+ reg.id = RISCV_CONFIG_REG(env, mvendorid);
36
reg.addr = (uint64_t)&cpu->cfg.mvendorid;
37
ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
38
if (ret != 0) {
39
error_report("Unable to retrieve mvendorid from host, error %d", ret);
40
}
40
}
41
41
env->menvcfg = (env->menvcfg & ~mask) | (val & mask);
42
- reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
42
+ write_henvcfg(env, CSR_HENVCFG, env->henvcfg);
43
- KVM_REG_RISCV_CONFIG_REG(marchid));
43
44
+ reg.id = RISCV_CONFIG_REG(env, marchid);
44
return RISCV_EXCP_NONE;
45
reg.addr = (uint64_t)&cpu->cfg.marchid;
45
}
46
ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
46
@@ -XXX,XX +XXX,XX @@ static RISCVException read_menvcfgh(CPURISCVState *env, int csrno,
47
if (ret != 0) {
47
return RISCV_EXCP_NONE;
48
error_report("Unable to retrieve marchid from host, error %d", ret);
48
}
49
50
+static RISCVException write_henvcfgh(CPURISCVState *env, int csrno,
51
+ target_ulong val);
52
static RISCVException write_menvcfgh(CPURISCVState *env, int csrno,
53
target_ulong val)
54
{
55
@@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno,
56
uint64_t valh = (uint64_t)val << 32;
57
58
env->menvcfg = (env->menvcfg & ~mask) | (valh & mask);
59
+ write_henvcfgh(env, CSR_HENVCFGH, env->henvcfg >> 32);
60
61
return RISCV_EXCP_NONE;
62
}
63
@@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno,
64
}
49
}
65
}
50
66
51
- reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
67
- env->henvcfg = (env->henvcfg & ~mask) | (val & mask);
52
- KVM_REG_RISCV_CONFIG_REG(mimpid));
68
+ env->henvcfg = val & mask;
53
+ reg.id = RISCV_CONFIG_REG(env, mimpid);
69
54
reg.addr = (uint64_t)&cpu->cfg.mimpid;
70
return RISCV_EXCP_NONE;
55
ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
71
}
56
if (ret != 0) {
72
@@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfgh(CPURISCVState *env, int csrno,
57
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_misa_ext_mask(RISCVCPU *cpu,
58
struct kvm_one_reg reg;
59
int ret;
60
61
- reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
62
- KVM_REG_RISCV_CONFIG_REG(isa));
63
+ reg.id = RISCV_CONFIG_REG(env, isa);
64
reg.addr = (uint64_t)&env->misa_ext_mask;
65
ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
66
67
@@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs)
68
uint64_t id;
69
int ret;
70
71
- id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
72
- KVM_REG_RISCV_CONFIG_REG(mvendorid));
73
+ id = RISCV_CONFIG_REG(env, mvendorid);
74
/*
75
* cfg.mvendorid is an uint32 but a target_ulong will
76
* be written. Assign it to a target_ulong var to avoid
77
@@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs)
78
return ret;
73
return ret;
79
}
74
}
80
75
81
- id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
76
- env->henvcfg = (env->henvcfg & ~mask) | (valh & mask);
82
- KVM_REG_RISCV_CONFIG_REG(marchid));
77
+ env->henvcfg = (env->henvcfg & 0xFFFFFFFF) | (valh & mask);
83
+ id = RISCV_CONFIG_REG(env, marchid);
78
return RISCV_EXCP_NONE;
84
ret = kvm_set_one_reg(cs, id, &cpu->cfg.marchid);
79
}
85
if (ret != 0) {
80
86
return ret;
87
}
88
89
- id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
90
- KVM_REG_RISCV_CONFIG_REG(mimpid));
91
+ id = RISCV_CONFIG_REG(env, mimpid);
92
ret = kvm_set_one_reg(cs, id, &cpu->cfg.mimpid);
93
94
return ret;
95
--
81
--
96
2.43.0
82
2.48.1
83
84
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
zic64b is defined in the RVA22U64 profile [1] as a named feature for
3
Add ext_ssdbltrp in RISCVCPUConfig and implement MSTATUS.SDT,
4
"Cache blocks must be 64 bytes in size, naturally aligned in the address
4
{H|M}ENVCFG.DTE and modify the availability of MTVAL2 based on the
5
space". It's a fantasy name for 64 bytes cache blocks. The RVA22U64
5
presence of the Ssdbltrp ISA extension.
6
profile mandates this feature, meaning that applications using this
6
7
profile expects 64 bytes cache blocks.
7
Signed-off-by: Clément Léger <cleger@rivosinc.com>
8
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
To make the upcoming RVA22U64 implementation complete, we'll zic64b as
10
a 'named feature', not a regular extension. This means that:
11
12
- it won't be exposed to users;
13
- it won't be written in riscv,isa.
14
15
This will be extended to other named extensions in the future, so we're
16
creating some common boilerplate for them as well.
17
18
zic64b is default to 'true' since we're already using 64 bytes blocks.
19
If any cache block size (cbo{m,p,z}_blocksize) is changed to something
20
different than 64, zic64b is set to 'false'.
21
22
Our profile implementation will then be able to check the current state
23
of zic64b and take the appropriate action (e.g. throw a warning).
24
25
[1] https://github.com/riscv/riscv-profiles/releases/download/v1.0/profiles.pdf
26
27
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
28
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
29
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
30
Message-ID: <20231218125334.37184-7-dbarboza@ventanamicro.com>
10
Message-ID: <20250110125441.3208676-3-cleger@rivosinc.com>
31
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
32
---
12
---
33
target/riscv/cpu.h | 1 +
13
target/riscv/cpu.h | 1 +
34
target/riscv/cpu_cfg.h | 1 +
14
target/riscv/cpu_bits.h | 6 ++++
35
target/riscv/cpu.c | 6 ++++++
15
target/riscv/cpu_cfg.h | 1 +
36
target/riscv/tcg/tcg-cpu.c | 26 ++++++++++++++++++++++++++
16
target/riscv/cpu_helper.c | 17 ++++++++++
37
4 files changed, 34 insertions(+)
17
target/riscv/csr.c | 71 ++++++++++++++++++++++++++++++++-------
18
5 files changed, 84 insertions(+), 12 deletions(-)
38
19
39
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
20
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
40
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/cpu.h
22
--- a/target/riscv/cpu.h
42
+++ b/target/riscv/cpu.h
23
+++ b/target/riscv/cpu.h
43
@@ -XXX,XX +XXX,XX @@ typedef struct RISCVCPUMultiExtConfig {
24
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable);
44
extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[];
25
int riscv_env_mmu_index(CPURISCVState *env, bool ifetch);
45
extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];
26
bool cpu_get_fcfien(CPURISCVState *env);
46
extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[];
27
bool cpu_get_bcfien(CPURISCVState *env);
47
+extern const RISCVCPUMultiExtConfig riscv_cpu_named_features[];
28
+bool riscv_env_smode_dbltrp_enabled(CPURISCVState *env, bool virt);
48
extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[];
29
G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
49
extern Property riscv_cpu_options[];
30
MMUAccessType access_type,
50
31
int mmu_idx, uintptr_t retaddr);
32
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
33
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/cpu_bits.h
35
+++ b/target/riscv/cpu_bits.h
36
@@ -XXX,XX +XXX,XX @@
37
#define MSTATUS_TW 0x00200000 /* since: priv-1.10 */
38
#define MSTATUS_TSR 0x00400000 /* since: priv-1.10 */
39
#define MSTATUS_SPELP 0x00800000 /* zicfilp */
40
+#define MSTATUS_SDT 0x01000000
41
#define MSTATUS_MPELP 0x020000000000 /* zicfilp */
42
#define MSTATUS_GVA 0x4000000000ULL
43
#define MSTATUS_MPV 0x8000000000ULL
44
@@ -XXX,XX +XXX,XX @@ typedef enum {
45
#define SSTATUS_SUM 0x00040000 /* since: priv-1.10 */
46
#define SSTATUS_MXR 0x00080000
47
#define SSTATUS_SPELP MSTATUS_SPELP /* zicfilp */
48
+#define SSTATUS_SDT MSTATUS_SDT
49
50
#define SSTATUS64_UXL 0x0000000300000000ULL
51
52
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
53
#define MENVCFG_CBCFE BIT(6)
54
#define MENVCFG_CBZE BIT(7)
55
#define MENVCFG_PMM (3ULL << 32)
56
+#define MENVCFG_DTE (1ULL << 59)
57
#define MENVCFG_CDE (1ULL << 60)
58
#define MENVCFG_ADUE (1ULL << 61)
59
#define MENVCFG_PBMTE (1ULL << 62)
60
#define MENVCFG_STCE (1ULL << 63)
61
62
/* For RV32 */
63
+#define MENVCFGH_DTE BIT(27)
64
#define MENVCFGH_ADUE BIT(29)
65
#define MENVCFGH_PBMTE BIT(30)
66
#define MENVCFGH_STCE BIT(31)
67
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
68
#define HENVCFG_CBCFE MENVCFG_CBCFE
69
#define HENVCFG_CBZE MENVCFG_CBZE
70
#define HENVCFG_PMM MENVCFG_PMM
71
+#define HENVCFG_DTE MENVCFG_DTE
72
#define HENVCFG_ADUE MENVCFG_ADUE
73
#define HENVCFG_PBMTE MENVCFG_PBMTE
74
#define HENVCFG_STCE MENVCFG_STCE
75
76
/* For RV32 */
77
+#define HENVCFGH_DTE MENVCFGH_DTE
78
#define HENVCFGH_ADUE MENVCFGH_ADUE
79
#define HENVCFGH_PBMTE MENVCFGH_PBMTE
80
#define HENVCFGH_STCE MENVCFGH_STCE
51
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
81
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
52
index XXXXXXX..XXXXXXX 100644
82
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/cpu_cfg.h
83
--- a/target/riscv/cpu_cfg.h
54
+++ b/target/riscv/cpu_cfg.h
84
+++ b/target/riscv/cpu_cfg.h
55
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
85
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
56
bool ext_smepmp;
86
bool ext_smcntrpmf;
57
bool rvv_ta_all_1s;
87
bool ext_smcsrind;
58
bool rvv_ma_all_1s;
88
bool ext_sscsrind;
59
+ bool zic64b;
89
+ bool ext_ssdbltrp;
60
90
bool ext_svadu;
61
uint32_t mvendorid;
91
bool ext_svinval;
62
uint64_t marchid;
92
bool ext_svnapot;
63
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
93
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
64
index XXXXXXX..XXXXXXX 100644
94
index XXXXXXX..XXXXXXX 100644
65
--- a/target/riscv/cpu.c
95
--- a/target/riscv/cpu_helper.c
66
+++ b/target/riscv/cpu.c
96
+++ b/target/riscv/cpu_helper.c
67
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
97
@@ -XXX,XX +XXX,XX @@ bool cpu_get_bcfien(CPURISCVState *env)
68
DEFINE_PROP_END_OF_LIST(),
98
}
69
};
99
}
70
100
71
+const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = {
101
+bool riscv_env_smode_dbltrp_enabled(CPURISCVState *env, bool virt)
72
+ MULTI_EXT_CFG_BOOL("zic64b", zic64b, true),
73
+
74
+ DEFINE_PROP_END_OF_LIST(),
75
+};
76
+
77
/* Deprecated entries marked for future removal */
78
const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = {
79
MULTI_EXT_CFG_BOOL("Zifencei", ext_zifencei, true),
80
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
81
index XXXXXXX..XXXXXXX 100644
82
--- a/target/riscv/tcg/tcg-cpu.c
83
+++ b/target/riscv/tcg/tcg-cpu.c
84
@@ -XXX,XX +XXX,XX @@ static int cpu_cfg_ext_get_min_version(uint32_t ext_offset)
85
g_assert_not_reached();
86
}
87
88
+static bool cpu_cfg_offset_is_named_feat(uint32_t ext_offset)
89
+{
102
+{
90
+ const RISCVCPUMultiExtConfig *feat;
103
+#ifdef CONFIG_USER_ONLY
91
+
104
+ return false;
92
+ for (feat = riscv_cpu_named_features; feat->name != NULL; feat++) {
105
+#else
93
+ if (feat->offset == ext_offset) {
106
+ if (virt) {
94
+ return true;
107
+ return (env->henvcfg & HENVCFG_DTE) != 0;
108
+ } else {
109
+ return (env->menvcfg & MENVCFG_DTE) != 0;
110
+ }
111
+#endif
112
+}
113
+
114
void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
115
uint64_t *cs_base, uint32_t *pflags)
116
{
117
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
118
119
g_assert(riscv_has_ext(env, RVH));
120
121
+ if (riscv_env_smode_dbltrp_enabled(env, current_virt)) {
122
+ mstatus_mask |= MSTATUS_SDT;
123
+ }
124
+
125
if (current_virt) {
126
/* Current V=1 and we are about to change to V=0 */
127
env->vsstatus = env->mstatus & mstatus_mask;
128
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
129
index XXXXXXX..XXXXXXX 100644
130
--- a/target/riscv/csr.c
131
+++ b/target/riscv/csr.c
132
@@ -XXX,XX +XXX,XX @@ static RISCVException aia_hmode32(CPURISCVState *env, int csrno)
133
return hmode32(env, csrno);
134
}
135
136
+static RISCVException dbltrp_hmode(CPURISCVState *env, int csrno)
137
+{
138
+ if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
139
+ return RISCV_EXCP_NONE;
140
+ }
141
+
142
+ return hmode(env, csrno);
143
+}
144
+
145
static RISCVException pmp(CPURISCVState *env, int csrno)
146
{
147
if (riscv_cpu_cfg(env)->pmp) {
148
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
149
mask |= MSTATUS_VS;
150
}
151
152
+ if (riscv_env_smode_dbltrp_enabled(env, env->virt_enabled)) {
153
+ mask |= MSTATUS_SDT;
154
+ if ((val & MSTATUS_SDT) != 0) {
155
+ val &= ~MSTATUS_SIE;
95
+ }
156
+ }
96
+ }
157
+ }
97
+
158
+
98
+ return false;
159
if (xl != MXL_RV32 || env->debugger) {
99
+}
160
if (riscv_has_ext(env, RVH)) {
100
+
161
mask |= MSTATUS_MPV | MSTATUS_GVA;
101
static void cpu_bump_multi_ext_priv_ver(CPURISCVState *env,
162
@@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
102
uint32_t ext_offset)
163
mask |= (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) |
164
(cfg->ext_sstc ? MENVCFG_STCE : 0) |
165
(cfg->ext_smcdeleg ? MENVCFG_CDE : 0) |
166
- (cfg->ext_svadu ? MENVCFG_ADUE : 0);
167
+ (cfg->ext_svadu ? MENVCFG_ADUE : 0) |
168
+ (cfg->ext_ssdbltrp ? MENVCFG_DTE : 0);
169
170
if (env_archcpu(env)->cfg.ext_zicfilp) {
171
mask |= MENVCFG_LPE;
172
@@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
173
if (env_archcpu(env)->cfg.ext_smnpm &&
174
get_field(val, MENVCFG_PMM) != PMM_FIELD_RESERVED) {
175
mask |= MENVCFG_PMM;
176
+    }
177
+
178
+ if ((val & MENVCFG_DTE) == 0) {
179
+ env->mstatus &= ~MSTATUS_SDT;
180
}
181
}
182
env->menvcfg = (env->menvcfg & ~mask) | (val & mask);
183
@@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno,
184
uint64_t mask = (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) |
185
(cfg->ext_sstc ? MENVCFG_STCE : 0) |
186
(cfg->ext_svadu ? MENVCFG_ADUE : 0) |
187
- (cfg->ext_smcdeleg ? MENVCFG_CDE : 0);
188
+ (cfg->ext_smcdeleg ? MENVCFG_CDE : 0) |
189
+ (cfg->ext_ssdbltrp ? MENVCFG_DTE : 0);
190
uint64_t valh = (uint64_t)val << 32;
191
192
+ if ((valh & MENVCFG_DTE) == 0) {
193
+ env->mstatus &= ~MSTATUS_SDT;
194
+ }
195
+
196
env->menvcfg = (env->menvcfg & ~mask) | (valh & mask);
197
write_henvcfgh(env, CSR_HENVCFGH, env->henvcfg >> 32);
198
199
@@ -XXX,XX +XXX,XX @@ static RISCVException read_henvcfg(CPURISCVState *env, int csrno,
200
* henvcfg.pbmte is read_only 0 when menvcfg.pbmte = 0
201
* henvcfg.stce is read_only 0 when menvcfg.stce = 0
202
* henvcfg.adue is read_only 0 when menvcfg.adue = 0
203
+ * henvcfg.dte is read_only 0 when menvcfg.dte = 0
204
*/
205
- *val = env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE) |
206
- env->menvcfg);
207
+ *val = env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE |
208
+ HENVCFG_DTE) | env->menvcfg);
209
return RISCV_EXCP_NONE;
210
}
211
212
@@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno,
213
}
214
215
if (riscv_cpu_mxl(env) == MXL_RV64) {
216
- mask |= env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE);
217
+ mask |= env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE |
218
+ HENVCFG_DTE);
219
220
if (env_archcpu(env)->cfg.ext_zicfilp) {
221
mask |= HENVCFG_LPE;
222
@@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno,
223
}
224
225
env->henvcfg = val & mask;
226
+ if ((env->henvcfg & HENVCFG_DTE) == 0) {
227
+ env->vsstatus &= ~MSTATUS_SDT;
228
+ }
229
230
return RISCV_EXCP_NONE;
231
}
232
@@ -XXX,XX +XXX,XX @@ static RISCVException read_henvcfgh(CPURISCVState *env, int csrno,
233
return ret;
234
}
235
236
- *val = (env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE) |
237
- env->menvcfg)) >> 32;
238
+ *val = (env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE |
239
+ HENVCFG_DTE) | env->menvcfg)) >> 32;
240
return RISCV_EXCP_NONE;
241
}
242
243
@@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfgh(CPURISCVState *env, int csrno,
244
target_ulong val)
103
{
245
{
104
@@ -XXX,XX +XXX,XX @@ static void cpu_bump_multi_ext_priv_ver(CPURISCVState *env,
246
uint64_t mask = env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE |
105
return;
247
- HENVCFG_ADUE);
106
}
248
+ HENVCFG_ADUE | HENVCFG_DTE);
107
249
uint64_t valh = (uint64_t)val << 32;
108
+ if (cpu_cfg_offset_is_named_feat(ext_offset)) {
250
RISCVException ret;
109
+ return;
251
110
+ }
252
@@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfgh(CPURISCVState *env, int csrno,
111
+
253
if (ret != RISCV_EXCP_NONE) {
112
ext_priv_ver = cpu_cfg_ext_get_min_version(ext_offset);
254
return ret;
113
255
}
114
if (env->priv_ver < ext_priv_ver) {
256
-
115
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu)
257
env->henvcfg = (env->henvcfg & 0xFFFFFFFF) | (valh & mask);
116
}
258
+ if ((env->henvcfg & HENVCFG_DTE) == 0) {
117
}
259
+ env->vsstatus &= ~MSTATUS_SDT;
118
260
+ }
119
+static void riscv_cpu_update_named_features(RISCVCPU *cpu)
261
return RISCV_EXCP_NONE;
120
+{
262
}
121
+ cpu->cfg.zic64b = cpu->cfg.cbom_blocksize == 64 &&
263
122
+ cpu->cfg.cbop_blocksize == 64 &&
264
@@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus_i128(CPURISCVState *env, int csrno,
123
+ cpu->cfg.cboz_blocksize == 64;
265
if (env->xl != MXL_RV32 || env->debugger) {
124
+}
266
mask |= SSTATUS64_UXL;
125
+
267
}
126
/*
268
+ if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
127
* Check consistency between chosen extensions while setting
269
+ mask |= SSTATUS_SDT;
128
* cpu->cfg accordingly.
270
+ }
129
@@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
271
130
return;
272
if (env_archcpu(env)->cfg.ext_zicfilp) {
131
}
273
mask |= SSTATUS_SPELP;
132
274
@@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno,
133
+ riscv_cpu_update_named_features(cpu);
275
if (env_archcpu(env)->cfg.ext_zicfilp) {
134
+
276
mask |= SSTATUS_SPELP;
135
if (cpu->cfg.ext_smepmp && !cpu->cfg.pmp) {
277
}
136
/*
278
-
137
* Enhanced PMP should only be available
279
+ if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
280
+ mask |= SSTATUS_SDT;
281
+ }
282
/* TODO: Use SXL not MXL. */
283
*val = add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask);
284
return RISCV_EXCP_NONE;
285
@@ -XXX,XX +XXX,XX @@ static RISCVException write_sstatus(CPURISCVState *env, int csrno,
286
if (env_archcpu(env)->cfg.ext_zicfilp) {
287
mask |= SSTATUS_SPELP;
288
}
289
-
290
+ if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
291
+ mask |= SSTATUS_SDT;
292
+ }
293
target_ulong newval = (env->mstatus & ~mask) | (val & mask);
294
return write_mstatus(env, CSR_MSTATUS, newval);
295
}
296
@@ -XXX,XX +XXX,XX @@ static RISCVException write_vsstatus(CPURISCVState *env, int csrno,
297
if ((val & VSSTATUS64_UXL) == 0) {
298
mask &= ~VSSTATUS64_UXL;
299
}
300
+ if ((env->henvcfg & HENVCFG_DTE)) {
301
+ if ((val & SSTATUS_SDT) != 0) {
302
+ val &= ~SSTATUS_SIE;
303
+ }
304
+ } else {
305
+ val &= ~SSTATUS_SDT;
306
+ }
307
env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val;
308
return RISCV_EXCP_NONE;
309
}
310
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
311
[CSR_VSATP] = { "vsatp", hmode, read_vsatp, write_vsatp,
312
.min_priv_ver = PRIV_VERSION_1_12_0 },
313
314
- [CSR_MTVAL2] = { "mtval2", hmode, read_mtval2, write_mtval2,
315
+ [CSR_MTVAL2] = { "mtval2", dbltrp_hmode, read_mtval2, write_mtval2,
316
.min_priv_ver = PRIV_VERSION_1_12_0 },
317
[CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst,
318
.min_priv_ver = PRIV_VERSION_1_12_0 },
138
--
319
--
139
2.43.0
320
2.48.1
321
322
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
Linux RISC-V vector documentation (Document/arch/riscv/vector.rst)
3
When the Ssdbltrp extension is enabled, SSTATUS.SDT field is cleared
4
mandates a prctl() in order to allow an userspace thread to use the
4
when executing sret. When executing mret/mnret, SSTATUS.SDT is cleared
5
Vector extension from the host.
5
when returning to U, VS or VU and VSSTATUS.SDT is cleared when returning
6
to VU from HS.
6
7
7
This is something to be done in realize() time, after init(), when we
8
Signed-off-by: Clément Léger <cleger@rivosinc.com>
8
already decided whether we're using RVV or not. We don't have a
9
realize() callback for KVM yet, so add kvm_cpu_realize() and enable RVV
10
for the thread via PR_RISCV_V_SET_CONTROL.
11
12
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Message-ID: <20231218204321.75757-4-dbarboza@ventanamicro.com>
10
Message-ID: <20250110125441.3208676-4-cleger@rivosinc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
12
---
17
target/riscv/kvm/kvm-cpu.c | 29 +++++++++++++++++++++++++++++
13
target/riscv/op_helper.c | 35 ++++++++++++++++++++++++++++++++++-
18
1 file changed, 29 insertions(+)
14
1 file changed, 34 insertions(+), 1 deletion(-)
19
15
20
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
16
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
21
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/kvm/kvm-cpu.c
18
--- a/target/riscv/op_helper.c
23
+++ b/target/riscv/kvm/kvm-cpu.c
19
+++ b/target/riscv/op_helper.c
24
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ target_ulong helper_sret(CPURISCVState *env)
25
21
get_field(mstatus, MSTATUS_SPIE));
26
#include "qemu/osdep.h"
22
mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
27
#include <sys/ioctl.h>
23
mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
28
+#include <sys/prctl.h>
29
30
#include <linux/kvm.h>
31
32
@@ -XXX,XX +XXX,XX @@
33
#include "sysemu/runstate.h"
34
#include "hw/riscv/numa.h"
35
36
+#define PR_RISCV_V_SET_CONTROL 69
37
+#define PR_RISCV_V_VSTATE_CTRL_ON 2
38
+
24
+
39
void riscv_kvm_aplic_request(void *opaque, int irq, int level)
25
+ if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
40
{
26
+ if (riscv_has_ext(env, RVH)) {
41
kvm_set_irq(kvm_state, irq, !!level);
27
+ target_ulong prev_vu = get_field(env->hstatus, HSTATUS_SPV) &&
42
@@ -XXX,XX +XXX,XX @@ static void kvm_cpu_instance_init(CPUState *cs)
28
+ prev_priv == PRV_U;
29
+ /* Returning to VU from HS, vsstatus.sdt = 0 */
30
+ if (!env->virt_enabled && prev_vu) {
31
+ env->vsstatus = set_field(env->vsstatus, MSTATUS_SDT, 0);
32
+ }
33
+ }
34
+ mstatus = set_field(mstatus, MSTATUS_SDT, 0);
35
+ }
36
if (env->priv_ver >= PRIV_VERSION_1_12_0) {
37
mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
38
}
39
@@ -XXX,XX +XXX,XX @@ target_ulong helper_sret(CPURISCVState *env)
40
target_ulong hstatus = env->hstatus;
41
42
prev_virt = get_field(hstatus, HSTATUS_SPV);
43
-
44
hstatus = set_field(hstatus, HSTATUS_SPV, 0);
45
46
env->hstatus = hstatus;
47
@@ -XXX,XX +XXX,XX @@ static void check_ret_from_m_mode(CPURISCVState *env, target_ulong retpc,
48
riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
43
}
49
}
44
}
50
}
45
51
+static target_ulong ssdbltrp_mxret(CPURISCVState *env, target_ulong mstatus,
46
+/*
52
+ target_ulong prev_priv,
47
+ * We'll get here via the following path:
53
+ target_ulong prev_virt)
48
+ *
49
+ * riscv_cpu_realize()
50
+ * -> cpu_exec_realizefn()
51
+ * -> kvm_cpu_realize() (via accel_cpu_common_realize())
52
+ */
53
+static bool kvm_cpu_realize(CPUState *cs, Error **errp)
54
+{
54
+{
55
+ RISCVCPU *cpu = RISCV_CPU(cs);
55
+ /* If returning to U, VS or VU, sstatus.sdt = 0 */
56
+ int ret;
56
+ if (prev_priv == PRV_U || (prev_virt &&
57
+
57
+ (prev_priv == PRV_S || prev_priv == PRV_U))) {
58
+ if (riscv_has_ext(&cpu->env, RVV)) {
58
+ mstatus = set_field(mstatus, MSTATUS_SDT, 0);
59
+ ret = prctl(PR_RISCV_V_SET_CONTROL, PR_RISCV_V_VSTATE_CTRL_ON);
59
+ /* If returning to VU, vsstatus.sdt = 0 */
60
+ if (ret) {
60
+ if (prev_virt && prev_priv == PRV_U) {
61
+ error_setg(errp, "Error in prctl PR_RISCV_V_SET_CONTROL, code: %s",
61
+ env->vsstatus = set_field(env->vsstatus, MSTATUS_SDT, 0);
62
+ strerrorname_np(errno));
63
+ return false;
64
+ }
62
+ }
65
+ }
63
+ }
66
+
64
+
67
+ return true;
65
+ return mstatus;
68
+}
66
+}
69
+
67
70
static void kvm_cpu_accel_class_init(ObjectClass *oc, void *data)
68
target_ulong helper_mret(CPURISCVState *env)
71
{
69
{
72
AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
70
@@ -XXX,XX +XXX,XX @@ target_ulong helper_mret(CPURISCVState *env)
73
71
mstatus = set_field(mstatus, MSTATUS_MPP,
74
acc->cpu_instance_init = kvm_cpu_instance_init;
72
riscv_has_ext(env, RVU) ? PRV_U : PRV_M);
75
+ acc->cpu_target_realize = kvm_cpu_realize;
73
mstatus = set_field(mstatus, MSTATUS_MPV, 0);
76
}
74
+ if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
77
75
+ mstatus = ssdbltrp_mxret(env, mstatus, prev_priv, prev_virt);
78
static const TypeInfo kvm_cpu_accel_type_info = {
76
+ }
77
if ((env->priv_ver >= PRIV_VERSION_1_12_0) && (prev_priv != PRV_M)) {
78
mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
79
}
80
@@ -XXX,XX +XXX,XX @@ target_ulong helper_mnret(CPURISCVState *env)
81
if (prev_priv < PRV_M) {
82
env->mstatus = set_field(env->mstatus, MSTATUS_MPRV, false);
83
}
84
+ if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
85
+ env->mstatus = ssdbltrp_mxret(env, env->mstatus, prev_priv, prev_virt);
86
+ }
87
88
if (riscv_has_ext(env, RVH) && prev_virt) {
89
riscv_cpu_swap_hypervisor_regs(env);
79
--
90
--
80
2.43.0
91
2.48.1
92
93
diff view generated by jsdifflib
1
From: Sunil V L <sunilvl@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
Add IMSIC structure in MADT when IMSIC is configured.
3
When the Ssdbltrp ISA extension is enabled, if a trap happens in S-mode
4
while SSTATUS.SDT isn't cleared, generate a double trap exception to
5
M-mode.
4
6
5
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
7
Signed-off-by: Clément Léger <cleger@rivosinc.com>
6
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
9
Message-ID: <20250110125441.3208676-5-cleger@rivosinc.com>
8
Acked-by: Alistair Francis <alistair.francis@wdc.com>
9
Acked-by: Michael S. Tsirkin <mst@redhat.com>
10
Message-ID: <20231218150247.466427-7-sunilvl@ventanamicro.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
11
---
13
hw/riscv/virt-acpi-build.c | 35 +++++++++++++++++++++++++++++++++++
12
target/riscv/cpu_bits.h | 1 +
14
1 file changed, 35 insertions(+)
13
target/riscv/cpu.c | 2 +-
14
target/riscv/cpu_helper.c | 42 ++++++++++++++++++++++++++++++++++-----
15
3 files changed, 39 insertions(+), 6 deletions(-)
15
16
16
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
17
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
17
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/riscv/virt-acpi-build.c
19
--- a/target/riscv/cpu_bits.h
19
+++ b/hw/riscv/virt-acpi-build.c
20
+++ b/target/riscv/cpu_bits.h
20
@@ -XXX,XX +XXX,XX @@ static void build_madt(GArray *table_data,
21
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
21
MachineClass *mc = MACHINE_GET_CLASS(s);
22
RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
22
MachineState *ms = MACHINE(s);
23
RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
23
const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(ms);
24
RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
24
+ uint8_t group_index_bits = imsic_num_bits(riscv_socket_count(ms));
25
+ RISCV_EXCP_DOUBLE_TRAP = 0x10,
25
+ uint8_t guest_index_bits = imsic_num_bits(s->aia_guests + 1);
26
RISCV_EXCP_SW_CHECK = 0x12, /* since: priv-1.13.0 */
26
+ uint16_t imsic_max_hart_per_socket = 0;
27
RISCV_EXCP_HW_ERR = 0x13, /* since: priv-1.13.0 */
27
+ uint8_t hart_index_bits;
28
RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
28
+ uint8_t socket;
29
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
29
+
30
index XXXXXXX..XXXXXXX 100644
30
+ for (socket = 0; socket < riscv_socket_count(ms); socket++) {
31
--- a/target/riscv/cpu.c
31
+ if (imsic_max_hart_per_socket < s->soc[socket].num_harts) {
32
+++ b/target/riscv/cpu.c
32
+ imsic_max_hart_per_socket = s->soc[socket].num_harts;
33
@@ -XXX,XX +XXX,XX @@ static const char * const riscv_excp_names[] = {
34
"load_page_fault",
35
"reserved",
36
"store_page_fault",
37
- "reserved",
38
+ "double_trap",
39
"reserved",
40
"reserved",
41
"reserved",
42
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
43
index XXXXXXX..XXXXXXX 100644
44
--- a/target/riscv/cpu_helper.c
45
+++ b/target/riscv/cpu_helper.c
46
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
47
bool virt = env->virt_enabled;
48
bool write_gva = false;
49
bool always_storeamo = (env->excp_uw2 & RISCV_UW2_ALWAYS_STORE_AMO);
50
+ bool vsmode_exc;
51
uint64_t s;
52
int mode;
53
54
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
55
!(env->mip & (1ULL << cause));
56
bool vs_injected = env->hvip & (1ULL << cause) & env->hvien &&
57
!(env->mip & (1ULL << cause));
58
+ bool smode_double_trap = false;
59
+ uint64_t hdeleg = async ? env->hideleg : env->hedeleg;
60
target_ulong tval = 0;
61
target_ulong tinst = 0;
62
target_ulong htval = 0;
63
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
64
mode = env->priv <= PRV_S && cause < 64 &&
65
(((deleg >> cause) & 1) || s_injected || vs_injected) ? PRV_S : PRV_M;
66
67
+ vsmode_exc = env->virt_enabled && (((hdeleg >> cause) & 1) || vs_injected);
68
+ /*
69
+ * Check double trap condition only if already in S-mode and targeting
70
+ * S-mode
71
+ */
72
+ if (cpu->cfg.ext_ssdbltrp && env->priv == PRV_S && mode == PRV_S) {
73
+ bool dte = (env->menvcfg & MENVCFG_DTE) != 0;
74
+ bool sdt = (env->mstatus & MSTATUS_SDT) != 0;
75
+ /* In VS or HS */
76
+ if (riscv_has_ext(env, RVH)) {
77
+ if (vsmode_exc) {
78
+ /* VS -> VS, use henvcfg instead of menvcfg*/
79
+ dte = (env->henvcfg & HENVCFG_DTE) != 0;
80
+ } else if (env->virt_enabled) {
81
+ /* VS -> HS, use mstatus_hs */
82
+ sdt = (env->mstatus_hs & MSTATUS_SDT) != 0;
83
+ }
84
+ }
85
+ smode_double_trap = dte && sdt;
86
+ if (smode_double_trap) {
87
+ mode = PRV_M;
33
+ }
88
+ }
34
+ }
89
+ }
35
+
90
+
36
+ hart_index_bits = imsic_num_bits(imsic_max_hart_per_socket);
91
if (mode == PRV_S) {
37
92
/* handle the trap in S-mode */
38
AcpiTable table = { .sig = "APIC", .rev = 6, .oem_id = s->oem_id,
93
/* save elp status */
39
.oem_table_id = s->oem_table_id };
94
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
40
@@ -XXX,XX +XXX,XX @@ static void build_madt(GArray *table_data,
95
}
41
riscv_acpi_madt_add_rintc(i, arch_ids, table_data, s);
96
42
}
97
if (riscv_has_ext(env, RVH)) {
43
98
- uint64_t hdeleg = async ? env->hideleg : env->hedeleg;
44
+ /* IMSIC */
99
-
45
+ if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) {
100
- if (env->virt_enabled &&
46
+ /* IMSIC */
101
- (((hdeleg >> cause) & 1) || vs_injected)) {
47
+ build_append_int_noprefix(table_data, 0x19, 1); /* Type */
102
+ if (vsmode_exc) {
48
+ build_append_int_noprefix(table_data, 16, 1); /* Length */
103
/* Trap to VS mode */
49
+ build_append_int_noprefix(table_data, 1, 1); /* Version */
104
/*
50
+ build_append_int_noprefix(table_data, 0, 1); /* Reserved */
105
* See if we need to adjust cause. Yes if its VS mode interrupt
51
+ build_append_int_noprefix(table_data, 0, 4); /* Flags */
106
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
52
+ /* Number of supervisor mode Interrupt Identities */
107
s = set_field(s, MSTATUS_SPIE, get_field(s, MSTATUS_SIE));
53
+ build_append_int_noprefix(table_data, VIRT_IRQCHIP_NUM_MSIS, 2);
108
s = set_field(s, MSTATUS_SPP, env->priv);
54
+ /* Number of guest mode Interrupt Identities */
109
s = set_field(s, MSTATUS_SIE, 0);
55
+ build_append_int_noprefix(table_data, VIRT_IRQCHIP_NUM_MSIS, 2);
110
+ if (riscv_env_smode_dbltrp_enabled(env, virt)) {
56
+ /* Guest Index Bits */
111
+ s = set_field(s, MSTATUS_SDT, 1);
57
+ build_append_int_noprefix(table_data, guest_index_bits, 1);
112
+ }
58
+ /* Hart Index Bits */
113
env->mstatus = s;
59
+ build_append_int_noprefix(table_data, hart_index_bits, 1);
114
sxlen = 16 << riscv_cpu_sxl(env);
60
+ /* Group Index Bits */
115
env->scause = cause | ((target_ulong)async << (sxlen - 1));
61
+ build_append_int_noprefix(table_data, group_index_bits, 1);
116
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
62
+ /* Group Index Shift */
117
s = set_field(s, MSTATUS_MIE, 0);
63
+ build_append_int_noprefix(table_data, IMSIC_MMIO_GROUP_MIN_SHIFT, 1);
118
env->mstatus = s;
64
+ }
119
env->mcause = cause | ((target_ulong)async << (mxlen - 1));
65
+
120
+ if (smode_double_trap) {
66
acpi_table_end(linker, &table);
121
+ env->mtval2 = env->mcause;
67
}
122
+ env->mcause = RISCV_EXCP_DOUBLE_TRAP;
68
123
+ } else {
124
+ env->mtval2 = mtval2;
125
+ }
126
env->mepc = env->pc;
127
env->mtval = tval;
128
- env->mtval2 = mtval2;
129
env->mtinst = tinst;
130
131
/*
69
--
132
--
70
2.43.0
133
2.48.1
134
135
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
mvendorid is an uint32 property, mimpid/marchid are uint64 properties.
3
Add the switch to enable the Ssdbltrp ISA extension.
4
But their getters are returning bools. The reason this went under the
5
radar for this long is because we have no code using the getters.
6
4
7
The problem can be seem via the 'qom-get' API though. Launching QEMU
5
Signed-off-by: Clément Léger <cleger@rivosinc.com>
8
with the 'veyron-v1' CPU, a model with:
9
10
VEYRON_V1_MVENDORID: 0x61f (1567)
11
VEYRON_V1_MIMPID: 0x111 (273)
12
VEYRON_V1_MARCHID: 0x8000000000010000 (9223372036854841344)
13
14
This is what the API returns when retrieving these properties:
15
16
(qemu) qom-get /machine/soc0/harts[0] mvendorid
17
true
18
(qemu) qom-get /machine/soc0/harts[0] mimpid
19
true
20
(qemu) qom-get /machine/soc0/harts[0] marchid
21
true
22
23
After this patch:
24
25
(qemu) qom-get /machine/soc0/harts[0] mvendorid
26
1567
27
(qemu) qom-get /machine/soc0/harts[0] mimpid
28
273
29
(qemu) qom-get /machine/soc0/harts[0] marchid
30
9223372036854841344
31
32
Fixes: 1e34150045 ("target/riscv/cpu.c: restrict 'mvendorid' value")
33
Fixes: a1863ad368 ("target/riscv/cpu.c: restrict 'mimpid' value")
34
Fixes: d6a427e2c0 ("target/riscv/cpu.c: restrict 'marchid' value")
35
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
36
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
37
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
Message-ID: <20250110125441.3208676-6-cleger@rivosinc.com>
38
Message-ID: <20231211170732.2541368-1-dbarboza@ventanamicro.com>
39
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
40
---
9
---
41
target/riscv/cpu.c | 12 ++++++------
10
target/riscv/cpu.c | 2 ++
42
1 file changed, 6 insertions(+), 6 deletions(-)
11
1 file changed, 2 insertions(+)
43
12
44
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
45
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
46
--- a/target/riscv/cpu.c
15
--- a/target/riscv/cpu.c
47
+++ b/target/riscv/cpu.c
16
+++ b/target/riscv/cpu.c
48
@@ -XXX,XX +XXX,XX @@ static void cpu_set_mvendorid(Object *obj, Visitor *v, const char *name,
17
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
49
static void cpu_get_mvendorid(Object *obj, Visitor *v, const char *name,
18
ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf),
50
void *opaque, Error **errp)
19
ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12),
51
{
20
ISA_EXT_DATA_ENTRY(sscsrind, PRIV_VERSION_1_12_0, ext_sscsrind),
52
- bool value = RISCV_CPU(obj)->cfg.mvendorid;
21
+ ISA_EXT_DATA_ENTRY(ssdbltrp, PRIV_VERSION_1_13_0, ext_ssdbltrp),
53
+ uint32_t value = RISCV_CPU(obj)->cfg.mvendorid;
22
ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm),
54
23
ISA_EXT_DATA_ENTRY(ssstateen, PRIV_VERSION_1_12_0, ext_ssstateen),
55
- visit_type_bool(v, name, &value, errp);
24
ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc),
56
+ visit_type_uint32(v, name, &value, errp);
25
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
57
}
26
MULTI_EXT_CFG_BOOL("smnpm", ext_smnpm, false),
58
27
MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false),
59
static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name,
28
MULTI_EXT_CFG_BOOL("ssaia", ext_ssaia, false),
60
@@ -XXX,XX +XXX,XX @@ static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name,
29
+ MULTI_EXT_CFG_BOOL("ssdbltrp", ext_ssdbltrp, false),
61
static void cpu_get_mimpid(Object *obj, Visitor *v, const char *name,
30
MULTI_EXT_CFG_BOOL("svade", ext_svade, false),
62
void *opaque, Error **errp)
31
MULTI_EXT_CFG_BOOL("svadu", ext_svadu, true),
63
{
32
MULTI_EXT_CFG_BOOL("svinval", ext_svinval, false),
64
- bool value = RISCV_CPU(obj)->cfg.mimpid;
65
+ uint64_t value = RISCV_CPU(obj)->cfg.mimpid;
66
67
- visit_type_bool(v, name, &value, errp);
68
+ visit_type_uint64(v, name, &value, errp);
69
}
70
71
static void cpu_set_marchid(Object *obj, Visitor *v, const char *name,
72
@@ -XXX,XX +XXX,XX @@ static void cpu_set_marchid(Object *obj, Visitor *v, const char *name,
73
static void cpu_get_marchid(Object *obj, Visitor *v, const char *name,
74
void *opaque, Error **errp)
75
{
76
- bool value = RISCV_CPU(obj)->cfg.marchid;
77
+ uint64_t value = RISCV_CPU(obj)->cfg.marchid;
78
79
- visit_type_bool(v, name, &value, errp);
80
+ visit_type_uint64(v, name, &value, errp);
81
}
82
83
static void riscv_cpu_class_init(ObjectClass *c, void *data)
84
--
33
--
85
2.43.0
34
2.48.1
86
35
87
36
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
KVM_REG_RISCV_FP_D regs are always u64 size. Using kvm_riscv_reg_id() in
4
RISCV_FP_D_REG() ends up encoding the wrong size if we're running with
5
TARGET_RISCV32.
6
7
Create a new helper that returns a KVM ID with u64 size and use it with
8
RISCV_FP_D_REG().
9
10
Reported-by: Andrew Jones <ajones@ventanamicro.com>
11
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
12
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
13
Message-ID: <20231208183835.2411523-3-dbarboza@ventanamicro.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
16
target/riscv/kvm/kvm-cpu.c | 11 ++++++++---
17
1 file changed, 8 insertions(+), 3 deletions(-)
18
19
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/kvm/kvm-cpu.c
22
+++ b/target/riscv/kvm/kvm-cpu.c
23
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id_u32(uint64_t type, uint64_t idx)
24
return KVM_REG_RISCV | KVM_REG_SIZE_U32 | type | idx;
25
}
26
27
+static uint64_t kvm_riscv_reg_id_u64(uint64_t type, uint64_t idx)
28
+{
29
+ return KVM_REG_RISCV | KVM_REG_SIZE_U64 | type | idx;
30
+}
31
+
32
#define RISCV_CORE_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CORE, \
33
KVM_REG_RISCV_CORE_REG(name))
34
35
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id_u32(uint64_t type, uint64_t idx)
36
37
#define RISCV_FP_F_REG(idx) kvm_riscv_reg_id_u32(KVM_REG_RISCV_FP_F, idx)
38
39
-#define RISCV_FP_D_REG(env, idx) kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_D, idx)
40
+#define RISCV_FP_D_REG(idx) kvm_riscv_reg_id_u64(KVM_REG_RISCV_FP_D, idx)
41
42
#define KVM_RISCV_GET_CSR(cs, env, csr, reg) \
43
do { \
44
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_get_regs_fp(CPUState *cs)
45
if (riscv_has_ext(env, RVD)) {
46
uint64_t reg;
47
for (i = 0; i < 32; i++) {
48
- ret = kvm_get_one_reg(cs, RISCV_FP_D_REG(env, i), &reg);
49
+ ret = kvm_get_one_reg(cs, RISCV_FP_D_REG(i), &reg);
50
if (ret) {
51
return ret;
52
}
53
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_put_regs_fp(CPUState *cs)
54
uint64_t reg;
55
for (i = 0; i < 32; i++) {
56
reg = env->fpr[i];
57
- ret = kvm_set_one_reg(cs, RISCV_FP_D_REG(env, i), &reg);
58
+ ret = kvm_set_one_reg(cs, RISCV_FP_D_REG(i), &reg);
59
if (ret) {
60
return ret;
61
}
62
--
63
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
KVM_REG_RISCV_TIMER regs are always u64 according to the KVM API, but at
4
this moment we'll return u32 regs if we're running a RISCV32 target.
5
6
Use the kvm_riscv_reg_id_u64() helper in RISCV_TIMER_REG() to fix it.
7
8
Reported-by: Andrew Jones <ajones@ventanamicro.com>
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
11
Message-ID: <20231208183835.2411523-4-dbarboza@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/kvm/kvm-cpu.c | 26 +++++++++++++-------------
15
1 file changed, 13 insertions(+), 13 deletions(-)
16
17
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/kvm/kvm-cpu.c
20
+++ b/target/riscv/kvm/kvm-cpu.c
21
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id_u64(uint64_t type, uint64_t idx)
22
#define RISCV_CSR_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CSR, \
23
KVM_REG_RISCV_CSR_REG(name))
24
25
-#define RISCV_TIMER_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_TIMER, \
26
+#define RISCV_TIMER_REG(name) kvm_riscv_reg_id_u64(KVM_REG_RISCV_TIMER, \
27
KVM_REG_RISCV_TIMER_REG(name))
28
29
#define RISCV_FP_F_REG(idx) kvm_riscv_reg_id_u32(KVM_REG_RISCV_FP_F, idx)
30
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id_u64(uint64_t type, uint64_t idx)
31
} \
32
} while (0)
33
34
-#define KVM_RISCV_GET_TIMER(cs, env, name, reg) \
35
+#define KVM_RISCV_GET_TIMER(cs, name, reg) \
36
do { \
37
- int ret = kvm_get_one_reg(cs, RISCV_TIMER_REG(env, name), &reg); \
38
+ int ret = kvm_get_one_reg(cs, RISCV_TIMER_REG(name), &reg); \
39
if (ret) { \
40
abort(); \
41
} \
42
} while (0)
43
44
-#define KVM_RISCV_SET_TIMER(cs, env, name, reg) \
45
+#define KVM_RISCV_SET_TIMER(cs, name, reg) \
46
do { \
47
- int ret = kvm_set_one_reg(cs, RISCV_TIMER_REG(env, name), &reg); \
48
+ int ret = kvm_set_one_reg(cs, RISCV_TIMER_REG(name), &reg); \
49
if (ret) { \
50
abort(); \
51
} \
52
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_get_regs_timer(CPUState *cs)
53
return;
54
}
55
56
- KVM_RISCV_GET_TIMER(cs, env, time, env->kvm_timer_time);
57
- KVM_RISCV_GET_TIMER(cs, env, compare, env->kvm_timer_compare);
58
- KVM_RISCV_GET_TIMER(cs, env, state, env->kvm_timer_state);
59
- KVM_RISCV_GET_TIMER(cs, env, frequency, env->kvm_timer_frequency);
60
+ KVM_RISCV_GET_TIMER(cs, time, env->kvm_timer_time);
61
+ KVM_RISCV_GET_TIMER(cs, compare, env->kvm_timer_compare);
62
+ KVM_RISCV_GET_TIMER(cs, state, env->kvm_timer_state);
63
+ KVM_RISCV_GET_TIMER(cs, frequency, env->kvm_timer_frequency);
64
65
env->kvm_timer_dirty = true;
66
}
67
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_put_regs_timer(CPUState *cs)
68
return;
69
}
70
71
- KVM_RISCV_SET_TIMER(cs, env, time, env->kvm_timer_time);
72
- KVM_RISCV_SET_TIMER(cs, env, compare, env->kvm_timer_compare);
73
+ KVM_RISCV_SET_TIMER(cs, time, env->kvm_timer_time);
74
+ KVM_RISCV_SET_TIMER(cs, compare, env->kvm_timer_compare);
75
76
/*
77
* To set register of RISCV_TIMER_REG(state) will occur a error from KVM
78
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_put_regs_timer(CPUState *cs)
79
* TODO If KVM changes, adapt here.
80
*/
81
if (env->kvm_timer_state) {
82
- KVM_RISCV_SET_TIMER(cs, env, state, env->kvm_timer_state);
83
+ KVM_RISCV_SET_TIMER(cs, state, env->kvm_timer_state);
84
}
85
86
/*
87
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_put_regs_timer(CPUState *cs)
88
* during the migration.
89
*/
90
if (migration_is_running(migrate_get_current()->state)) {
91
- KVM_RISCV_GET_TIMER(cs, env, frequency, reg);
92
+ KVM_RISCV_GET_TIMER(cs, frequency, reg);
93
if (reg != env->kvm_timer_frequency) {
94
error_report("Dst Hosts timer frequency != Src Hosts");
95
}
96
--
97
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
kvm_riscv_reg_id() returns an id encoded with an ulong size, i.e. an u32
4
size when running TARGET_RISCV32 and u64 when running TARGET_RISCV64.
5
6
Rename it to kvm_riscv_reg_id_ulong() to enhance code readability. It'll
7
be in line with the existing kvm_riscv_reg_id_<size>() helpers.
8
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
11
Message-ID: <20231208183835.2411523-6-dbarboza@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/kvm/kvm-cpu.c | 40 ++++++++++++++++++++------------------
15
1 file changed, 21 insertions(+), 19 deletions(-)
16
17
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/kvm/kvm-cpu.c
20
+++ b/target/riscv/kvm/kvm-cpu.c
21
@@ -XXX,XX +XXX,XX @@ void riscv_kvm_aplic_request(void *opaque, int irq, int level)
22
23
static bool cap_has_mp_state;
24
25
-static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type,
26
+static uint64_t kvm_riscv_reg_id_ulong(CPURISCVState *env, uint64_t type,
27
uint64_t idx)
28
{
29
uint64_t id = KVM_REG_RISCV | type | idx;
30
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id_u64(uint64_t type, uint64_t idx)
31
return KVM_REG_RISCV | KVM_REG_SIZE_U64 | type | idx;
32
}
33
34
-#define RISCV_CORE_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CORE, \
35
- KVM_REG_RISCV_CORE_REG(name))
36
+#define RISCV_CORE_REG(env, name) \
37
+ kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CORE, \
38
+ KVM_REG_RISCV_CORE_REG(name))
39
40
-#define RISCV_CSR_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CSR, \
41
- KVM_REG_RISCV_CSR_REG(name))
42
+#define RISCV_CSR_REG(env, name) \
43
+ kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CSR, \
44
+ KVM_REG_RISCV_CSR_REG(name))
45
46
#define RISCV_CONFIG_REG(env, name) \
47
- kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, \
48
- KVM_REG_RISCV_CONFIG_REG(name))
49
+ kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CONFIG, \
50
+ KVM_REG_RISCV_CONFIG_REG(name))
51
52
#define RISCV_TIMER_REG(name) kvm_riscv_reg_id_u64(KVM_REG_RISCV_TIMER, \
53
KVM_REG_RISCV_TIMER_REG(name))
54
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_misa_ext(RISCVCPU *cpu, CPUState *cs)
55
56
/* If we're here we're going to disable the MISA bit */
57
reg = 0;
58
- id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT,
59
- misa_cfg->kvm_reg_id);
60
+ id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_ISA_EXT,
61
+ misa_cfg->kvm_reg_id);
62
ret = kvm_set_one_reg(cs, id, &reg);
63
if (ret != 0) {
64
/*
65
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
66
continue;
67
}
68
69
- id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT,
70
- multi_ext_cfg->kvm_reg_id);
71
+ id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_ISA_EXT,
72
+ multi_ext_cfg->kvm_reg_id);
73
reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
74
ret = kvm_set_one_reg(cs, id, &reg);
75
if (ret != 0) {
76
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_get_regs_core(CPUState *cs)
77
env->pc = reg;
78
79
for (i = 1; i < 32; i++) {
80
- uint64_t id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CORE, i);
81
+ uint64_t id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CORE, i);
82
ret = kvm_get_one_reg(cs, id, &reg);
83
if (ret) {
84
return ret;
85
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_put_regs_core(CPUState *cs)
86
}
87
88
for (i = 1; i < 32; i++) {
89
- uint64_t id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CORE, i);
90
+ uint64_t id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CORE, i);
91
reg = env->gpr[i];
92
ret = kvm_set_one_reg(cs, id, &reg);
93
if (ret) {
94
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_read_cbomz_blksize(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
95
struct kvm_one_reg reg;
96
int ret;
97
98
- reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
99
- cbomz_cfg->kvm_reg_id);
100
+ reg.id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CONFIG,
101
+ cbomz_cfg->kvm_reg_id);
102
reg.addr = (uint64_t)kvmconfig_get_cfg_addr(cpu, cbomz_cfg);
103
ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
104
if (ret != 0) {
105
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_read_multiext_legacy(RISCVCPU *cpu,
106
KVMCPUConfig *multi_ext_cfg = &kvm_multi_ext_cfgs[i];
107
struct kvm_one_reg reg;
108
109
- reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT,
110
- multi_ext_cfg->kvm_reg_id);
111
+ reg.id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_ISA_EXT,
112
+ multi_ext_cfg->kvm_reg_id);
113
reg.addr = (uint64_t)&val;
114
ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
115
if (ret != 0) {
116
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
117
118
for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) {
119
multi_ext_cfg = &kvm_multi_ext_cfgs[i];
120
- reg_id = kvm_riscv_reg_id(&cpu->env, KVM_REG_RISCV_ISA_EXT,
121
- multi_ext_cfg->kvm_reg_id);
122
+ reg_id = kvm_riscv_reg_id_ulong(&cpu->env, KVM_REG_RISCV_ISA_EXT,
123
+ multi_ext_cfg->kvm_reg_id);
124
reg_search = bsearch(&reg_id, reglist->reg, reglist->n,
125
sizeof(uint64_t), uint64_cmp);
126
if (!reg_search) {
127
--
128
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Sunil V L <sunilvl@ventanamicro.com>
2
1
3
RISC-V also needs to create the virtio in DSDT in the same way as ARM.
4
So, instead of duplicating the code, move this function to the device
5
specific file which is common across architectures.
6
7
Suggested-by: Igor Mammedov <imammedo@redhat.com>
8
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
11
Acked-by: Michael S. Tsirkin <mst@redhat.com>
12
Message-ID: <20231218150247.466427-3-sunilvl@ventanamicro.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
15
include/hw/virtio/virtio-acpi.h | 16 ++++++++++++++++
16
hw/arm/virt-acpi-build.c | 32 ++++----------------------------
17
hw/virtio/virtio-acpi.c | 33 +++++++++++++++++++++++++++++++++
18
hw/virtio/meson.build | 1 +
19
4 files changed, 54 insertions(+), 28 deletions(-)
20
create mode 100644 include/hw/virtio/virtio-acpi.h
21
create mode 100644 hw/virtio/virtio-acpi.c
22
23
diff --git a/include/hw/virtio/virtio-acpi.h b/include/hw/virtio/virtio-acpi.h
24
new file mode 100644
25
index XXXXXXX..XXXXXXX
26
--- /dev/null
27
+++ b/include/hw/virtio/virtio-acpi.h
28
@@ -XXX,XX +XXX,XX @@
29
+/* SPDX-License-Identifier: GPL-2.0+ */
30
+/*
31
+ * ACPI support for virtio
32
+ */
33
+
34
+#ifndef VIRTIO_ACPI_H
35
+#define VIRTIO_ACPI_H
36
+
37
+#include "qemu/osdep.h"
38
+#include "exec/hwaddr.h"
39
+
40
+void virtio_acpi_dsdt_add(Aml *scope, const hwaddr virtio_mmio_base,
41
+ const hwaddr virtio_mmio_size, uint32_t mmio_irq,
42
+ long int start_index, int num);
43
+
44
+#endif
45
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/hw/arm/virt-acpi-build.c
48
+++ b/hw/arm/virt-acpi-build.c
49
@@ -XXX,XX +XXX,XX @@
50
#include "migration/vmstate.h"
51
#include "hw/acpi/ghes.h"
52
#include "hw/acpi/viot.h"
53
+#include "hw/virtio/virtio-acpi.h"
54
55
#define ARM_SPI_BASE 32
56
57
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_flash(Aml *scope, const MemMapEntry *flash_memmap)
58
aml_append(scope, dev);
59
}
60
61
-static void acpi_dsdt_add_virtio(Aml *scope,
62
- const MemMapEntry *virtio_mmio_memmap,
63
- uint32_t mmio_irq, int num)
64
-{
65
- hwaddr base = virtio_mmio_memmap->base;
66
- hwaddr size = virtio_mmio_memmap->size;
67
- int i;
68
-
69
- for (i = 0; i < num; i++) {
70
- uint32_t irq = mmio_irq + i;
71
- Aml *dev = aml_device("VR%02u", i);
72
- aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0005")));
73
- aml_append(dev, aml_name_decl("_UID", aml_int(i)));
74
- aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
75
-
76
- Aml *crs = aml_resource_template();
77
- aml_append(crs, aml_memory32_fixed(base, size, AML_READ_WRITE));
78
- aml_append(crs,
79
- aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
80
- AML_EXCLUSIVE, &irq, 1));
81
- aml_append(dev, aml_name_decl("_CRS", crs));
82
- aml_append(scope, dev);
83
- base += size;
84
- }
85
-}
86
-
87
static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap,
88
uint32_t irq, VirtMachineState *vms)
89
{
90
@@ -XXX,XX +XXX,XX @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
91
acpi_dsdt_add_flash(scope, &memmap[VIRT_FLASH]);
92
}
93
fw_cfg_acpi_dsdt_add(scope, &memmap[VIRT_FW_CFG]);
94
- acpi_dsdt_add_virtio(scope, &memmap[VIRT_MMIO],
95
- (irqmap[VIRT_MMIO] + ARM_SPI_BASE), NUM_VIRTIO_TRANSPORTS);
96
+ virtio_acpi_dsdt_add(scope, memmap[VIRT_MMIO].base, memmap[VIRT_MMIO].size,
97
+ (irqmap[VIRT_MMIO] + ARM_SPI_BASE),
98
+ 0, NUM_VIRTIO_TRANSPORTS);
99
acpi_dsdt_add_pci(scope, memmap, irqmap[VIRT_PCIE] + ARM_SPI_BASE, vms);
100
if (vms->acpi_dev) {
101
build_ged_aml(scope, "\\_SB."GED_DEVICE,
102
diff --git a/hw/virtio/virtio-acpi.c b/hw/virtio/virtio-acpi.c
103
new file mode 100644
104
index XXXXXXX..XXXXXXX
105
--- /dev/null
106
+++ b/hw/virtio/virtio-acpi.c
107
@@ -XXX,XX +XXX,XX @@
108
+// SPDX-License-Identifier: GPL-2.0+
109
+/*
110
+ * virtio ACPI Support
111
+ *
112
+ */
113
+
114
+#include "hw/virtio/virtio-acpi.h"
115
+#include "hw/acpi/aml-build.h"
116
+
117
+void virtio_acpi_dsdt_add(Aml *scope, const hwaddr base, const hwaddr size,
118
+ uint32_t mmio_irq, long int start_index, int num)
119
+{
120
+ hwaddr virtio_base = base;
121
+ uint32_t irq = mmio_irq;
122
+ long int i;
123
+
124
+ for (i = start_index; i < start_index + num; i++) {
125
+ Aml *dev = aml_device("VR%02u", (unsigned)i);
126
+ aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0005")));
127
+ aml_append(dev, aml_name_decl("_UID", aml_int(i)));
128
+ aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
129
+
130
+ Aml *crs = aml_resource_template();
131
+ aml_append(crs, aml_memory32_fixed(virtio_base, size, AML_READ_WRITE));
132
+ aml_append(crs,
133
+ aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
134
+ AML_EXCLUSIVE, &irq, 1));
135
+ aml_append(dev, aml_name_decl("_CRS", crs));
136
+ aml_append(scope, dev);
137
+ virtio_base += size;
138
+ irq++;
139
+ }
140
+}
141
diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
142
index XXXXXXX..XXXXXXX 100644
143
--- a/hw/virtio/meson.build
144
+++ b/hw/virtio/meson.build
145
@@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_VIRTIO', if_false: files('virtio-stub.c'))
146
system_ss.add(files('virtio-hmp-cmds.c'))
147
148
specific_ss.add_all(when: 'CONFIG_VIRTIO', if_true: specific_virtio_ss)
149
+system_ss.add(when: 'CONFIG_ACPI', if_true: files('virtio-acpi.c'))
150
--
151
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Sunil V L <sunilvl@ventanamicro.com>
2
1
3
With common function to add virtio in DSDT created now, update microvm
4
code also to use it instead of duplicate code.
5
6
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
7
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
8
Acked-by: Alistair Francis <alistair.francis@wdc.com>
9
Acked-by: Michael S. Tsirkin <mst@redhat.com>
10
Message-ID: <20231218150247.466427-4-sunilvl@ventanamicro.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
hw/i386/acpi-microvm.c | 15 ++-------------
14
1 file changed, 2 insertions(+), 13 deletions(-)
15
16
diff --git a/hw/i386/acpi-microvm.c b/hw/i386/acpi-microvm.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/i386/acpi-microvm.c
19
+++ b/hw/i386/acpi-microvm.c
20
@@ -XXX,XX +XXX,XX @@
21
#include "hw/pci/pci.h"
22
#include "hw/pci/pcie_host.h"
23
#include "hw/usb/xhci.h"
24
+#include "hw/virtio/virtio-acpi.h"
25
#include "hw/virtio/virtio-mmio.h"
26
#include "hw/input/i8042.h"
27
28
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_virtio(Aml *scope,
29
uint32_t irq = mms->virtio_irq_base + index;
30
hwaddr base = VIRTIO_MMIO_BASE + index * 512;
31
hwaddr size = 512;
32
-
33
- Aml *dev = aml_device("VR%02u", (unsigned)index);
34
- aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0005")));
35
- aml_append(dev, aml_name_decl("_UID", aml_int(index)));
36
- aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
37
-
38
- Aml *crs = aml_resource_template();
39
- aml_append(crs, aml_memory32_fixed(base, size, AML_READ_WRITE));
40
- aml_append(crs,
41
- aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
42
- AML_EXCLUSIVE, &irq, 1));
43
- aml_append(dev, aml_name_decl("_CRS", crs));
44
- aml_append(scope, dev);
45
+ virtio_acpi_dsdt_add(scope, base, size, irq, index, 1);
46
}
47
}
48
}
49
--
50
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Sunil V L <sunilvl@ventanamicro.com>
2
1
3
Some macros and static function related to IMSIC are defined in virt.c.
4
They are required in virt-acpi-build.c. So, make them public.
5
6
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
10
Acked-by: Michael S. Tsirkin <mst@redhat.com>
11
Message-ID: <20231218150247.466427-5-sunilvl@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
include/hw/riscv/virt.h | 25 +++++++++++++++++++++++++
15
hw/riscv/virt.c | 25 +------------------------
16
2 files changed, 26 insertions(+), 24 deletions(-)
17
18
diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h
19
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/riscv/virt.h
21
+++ b/include/hw/riscv/virt.h
22
@@ -XXX,XX +XXX,XX @@
23
#include "hw/riscv/riscv_hart.h"
24
#include "hw/sysbus.h"
25
#include "hw/block/flash.h"
26
+#include "hw/intc/riscv_imsic.h"
27
28
#define VIRT_CPUS_MAX_BITS 9
29
#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS)
30
@@ -XXX,XX +XXX,XX @@ enum {
31
32
bool virt_is_acpi_enabled(RISCVVirtState *s);
33
void virt_acpi_setup(RISCVVirtState *vms);
34
+uint32_t imsic_num_bits(uint32_t count);
35
+
36
+/*
37
+ * The virt machine physical address space used by some of the devices
38
+ * namely ACLINT, PLIC, APLIC, and IMSIC depend on number of Sockets,
39
+ * number of CPUs, and number of IMSIC guest files.
40
+ *
41
+ * Various limits defined by VIRT_SOCKETS_MAX_BITS, VIRT_CPUS_MAX_BITS,
42
+ * and VIRT_IRQCHIP_MAX_GUESTS_BITS are tuned for maximum utilization
43
+ * of virt machine physical address space.
44
+ */
45
+
46
+#define VIRT_IMSIC_GROUP_MAX_SIZE (1U << IMSIC_MMIO_GROUP_MIN_SHIFT)
47
+#if VIRT_IMSIC_GROUP_MAX_SIZE < \
48
+ IMSIC_GROUP_SIZE(VIRT_CPUS_MAX_BITS, VIRT_IRQCHIP_MAX_GUESTS_BITS)
49
+#error "Can't accomodate single IMSIC group in address space"
50
+#endif
51
+
52
+#define VIRT_IMSIC_MAX_SIZE (VIRT_SOCKETS_MAX * \
53
+ VIRT_IMSIC_GROUP_MAX_SIZE)
54
+#if 0x4000000 < VIRT_IMSIC_MAX_SIZE
55
+#error "Can't accomodate all IMSIC groups in address space"
56
+#endif
57
+
58
#endif
59
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
60
index XXXXXXX..XXXXXXX 100644
61
--- a/hw/riscv/virt.c
62
+++ b/hw/riscv/virt.c
63
@@ -XXX,XX +XXX,XX @@
64
#include "kvm/kvm_riscv.h"
65
#include "hw/intc/riscv_aclint.h"
66
#include "hw/intc/riscv_aplic.h"
67
-#include "hw/intc/riscv_imsic.h"
68
#include "hw/intc/sifive_plic.h"
69
#include "hw/misc/sifive_test.h"
70
#include "hw/platform-bus.h"
71
@@ -XXX,XX +XXX,XX @@
72
#include "hw/acpi/aml-build.h"
73
#include "qapi/qapi-visit-common.h"
74
75
-/*
76
- * The virt machine physical address space used by some of the devices
77
- * namely ACLINT, PLIC, APLIC, and IMSIC depend on number of Sockets,
78
- * number of CPUs, and number of IMSIC guest files.
79
- *
80
- * Various limits defined by VIRT_SOCKETS_MAX_BITS, VIRT_CPUS_MAX_BITS,
81
- * and VIRT_IRQCHIP_MAX_GUESTS_BITS are tuned for maximum utilization
82
- * of virt machine physical address space.
83
- */
84
-
85
-#define VIRT_IMSIC_GROUP_MAX_SIZE (1U << IMSIC_MMIO_GROUP_MIN_SHIFT)
86
-#if VIRT_IMSIC_GROUP_MAX_SIZE < \
87
- IMSIC_GROUP_SIZE(VIRT_CPUS_MAX_BITS, VIRT_IRQCHIP_MAX_GUESTS_BITS)
88
-#error "Can't accommodate single IMSIC group in address space"
89
-#endif
90
-
91
-#define VIRT_IMSIC_MAX_SIZE (VIRT_SOCKETS_MAX * \
92
- VIRT_IMSIC_GROUP_MAX_SIZE)
93
-#if 0x4000000 < VIRT_IMSIC_MAX_SIZE
94
-#error "Can't accommodate all IMSIC groups in address space"
95
-#endif
96
-
97
/* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */
98
static bool virt_use_kvm_aia(RISCVVirtState *s)
99
{
100
@@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_plic(RISCVVirtState *s,
101
g_free(plic_cells);
102
}
103
104
-static uint32_t imsic_num_bits(uint32_t count)
105
+uint32_t imsic_num_bits(uint32_t count)
106
{
107
uint32_t ret = 0;
108
109
--
110
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Sunil V L <sunilvl@ventanamicro.com>
2
1
3
Update the RINTC structure in MADT with AIA related fields.
4
5
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
6
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Acked-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
9
Acked-by: Michael S. Tsirkin <mst@redhat.com>
10
Message-ID: <20231218150247.466427-6-sunilvl@ventanamicro.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
hw/riscv/virt-acpi-build.c | 43 ++++++++++++++++++++++++++++++++++----
14
1 file changed, 39 insertions(+), 4 deletions(-)
15
16
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/riscv/virt-acpi-build.c
19
+++ b/hw/riscv/virt-acpi-build.c
20
@@ -XXX,XX +XXX,XX @@
21
#include "hw/intc/riscv_aclint.h"
22
23
#define ACPI_BUILD_TABLE_SIZE 0x20000
24
+#define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
25
26
typedef struct AcpiBuildState {
27
/* Copy of table in RAM (for patching) */
28
@@ -XXX,XX +XXX,XX @@ static void acpi_align_size(GArray *blob, unsigned align)
29
30
static void riscv_acpi_madt_add_rintc(uint32_t uid,
31
const CPUArchIdList *arch_ids,
32
- GArray *entry)
33
+ GArray *entry,
34
+ RISCVVirtState *s)
35
{
36
+ uint8_t guest_index_bits = imsic_num_bits(s->aia_guests + 1);
37
uint64_t hart_id = arch_ids->cpus[uid].arch_id;
38
+ uint32_t imsic_size, local_cpu_id, socket_id;
39
+ uint64_t imsic_socket_addr, imsic_addr;
40
+ MachineState *ms = MACHINE(s);
41
42
+ socket_id = arch_ids->cpus[uid].props.node_id;
43
+ local_cpu_id = (arch_ids->cpus[uid].arch_id -
44
+ riscv_socket_first_hartid(ms, socket_id)) %
45
+ riscv_socket_hart_count(ms, socket_id);
46
+ imsic_socket_addr = s->memmap[VIRT_IMSIC_S].base +
47
+ (socket_id * VIRT_IMSIC_GROUP_MAX_SIZE);
48
+ imsic_size = IMSIC_HART_SIZE(guest_index_bits);
49
+ imsic_addr = imsic_socket_addr + local_cpu_id * imsic_size;
50
build_append_int_noprefix(entry, 0x18, 1); /* Type */
51
- build_append_int_noprefix(entry, 20, 1); /* Length */
52
+ build_append_int_noprefix(entry, 36, 1); /* Length */
53
build_append_int_noprefix(entry, 1, 1); /* Version */
54
build_append_int_noprefix(entry, 0, 1); /* Reserved */
55
build_append_int_noprefix(entry, 0x1, 4); /* Flags */
56
build_append_int_noprefix(entry, hart_id, 8); /* Hart ID */
57
build_append_int_noprefix(entry, uid, 4); /* ACPI Processor UID */
58
+ /* External Interrupt Controller ID */
59
+ if (s->aia_type == VIRT_AIA_TYPE_APLIC) {
60
+ build_append_int_noprefix(entry,
61
+ ACPI_BUILD_INTC_ID(
62
+ arch_ids->cpus[uid].props.node_id,
63
+ local_cpu_id),
64
+ 4);
65
+ } else {
66
+ build_append_int_noprefix(entry, 0, 4);
67
+ }
68
+
69
+ if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) {
70
+ /* IMSIC Base address */
71
+ build_append_int_noprefix(entry, imsic_addr, 8);
72
+ /* IMSIC Size */
73
+ build_append_int_noprefix(entry, imsic_size, 4);
74
+ } else {
75
+ build_append_int_noprefix(entry, 0, 8);
76
+ build_append_int_noprefix(entry, 0, 4);
77
+ }
78
}
79
80
static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s)
81
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s)
82
aml_int(arch_ids->cpus[i].arch_id)));
83
84
/* build _MAT object */
85
- riscv_acpi_madt_add_rintc(i, arch_ids, madt_buf);
86
+ riscv_acpi_madt_add_rintc(i, arch_ids, madt_buf, s);
87
aml_append(dev, aml_name_decl("_MAT",
88
aml_buffer(madt_buf->len,
89
(uint8_t *)madt_buf->data)));
90
@@ -XXX,XX +XXX,XX @@ static void build_dsdt(GArray *table_data,
91
* 5.2.12 Multiple APIC Description Table (MADT)
92
* REF: https://github.com/riscv-non-isa/riscv-acpi/issues/15
93
* https://drive.google.com/file/d/1R6k4MshhN3WTT-hwqAquu5nX6xSEqK2l/view
94
+ * https://drive.google.com/file/d/1oMGPyOD58JaPgMl1pKasT-VKsIKia7zR/view
95
*/
96
static void build_madt(GArray *table_data,
97
BIOSLinker *linker,
98
@@ -XXX,XX +XXX,XX @@ static void build_madt(GArray *table_data,
99
100
/* RISC-V Local INTC structures per HART */
101
for (int i = 0; i < arch_ids->len; i++) {
102
- riscv_acpi_madt_add_rintc(i, arch_ids, table_data);
103
+ riscv_acpi_madt_add_rintc(i, arch_ids, table_data, s);
104
}
105
106
acpi_table_end(linker, &table);
107
--
108
2.43.0
diff view generated by jsdifflib
1
From: Sunil V L <sunilvl@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
MMU type information is available via MMU node in RHCT. Add this node in
3
Add `ext_smdbltrp`in RISCVCPUConfig and implement MSTATUS.MDT behavior.
4
RHCT.
4
Also set MDT to 1 at reset according to the specification.
5
5
6
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
6
Signed-off-by: Clément Léger <cleger@rivosinc.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
8
Message-ID: <20250110125441.3208676-7-cleger@rivosinc.com>
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
10
Acked-by: Michael S. Tsirkin <mst@redhat.com>
11
Message-ID: <20231218150247.466427-10-sunilvl@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
10
---
14
hw/riscv/virt-acpi-build.c | 36 +++++++++++++++++++++++++++++++++++-
11
target/riscv/cpu_bits.h | 1 +
15
1 file changed, 35 insertions(+), 1 deletion(-)
12
target/riscv/cpu_cfg.h | 1 +
13
target/riscv/cpu.c | 3 +++
14
target/riscv/csr.c | 13 +++++++++++++
15
4 files changed, 18 insertions(+)
16
16
17
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
17
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
18
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/riscv/virt-acpi-build.c
19
--- a/target/riscv/cpu_bits.h
20
+++ b/hw/riscv/virt-acpi-build.c
20
+++ b/target/riscv/cpu_bits.h
21
@@ -XXX,XX +XXX,XX @@ static void build_rhct(GArray *table_data,
21
@@ -XXX,XX +XXX,XX @@
22
size_t len, aligned_len;
22
#define MSTATUS_MPELP 0x020000000000 /* zicfilp */
23
uint32_t isa_offset, num_rhct_nodes, cmo_offset = 0;
23
#define MSTATUS_GVA 0x4000000000ULL
24
RISCVCPU *cpu = &s->soc[0].harts[0];
24
#define MSTATUS_MPV 0x8000000000ULL
25
+ uint32_t mmu_offset = 0;
25
+#define MSTATUS_MDT 0x40000000000ULL /* Smdbltrp extension */
26
+ uint8_t satp_mode_max;
26
27
char *isa;
27
#define MSTATUS64_UXL 0x0000000300000000ULL
28
28
#define MSTATUS64_SXL 0x0000000C00000000ULL
29
AcpiTable table = { .sig = "RHCT", .rev = 1, .oem_id = s->oem_id,
29
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
30
@@ -XXX,XX +XXX,XX @@ static void build_rhct(GArray *table_data,
30
index XXXXXXX..XXXXXXX 100644
31
num_rhct_nodes++;
31
--- a/target/riscv/cpu_cfg.h
32
+++ b/target/riscv/cpu_cfg.h
33
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
34
bool ext_smcsrind;
35
bool ext_sscsrind;
36
bool ext_ssdbltrp;
37
+ bool ext_smdbltrp;
38
bool ext_svadu;
39
bool ext_svinval;
40
bool ext_svnapot;
41
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/target/riscv/cpu.c
44
+++ b/target/riscv/cpu.c
45
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type)
46
env->mstatus_hs = set_field(env->mstatus_hs,
47
MSTATUS64_UXL, env->misa_mxl);
48
}
49
+ if (riscv_cpu_cfg(env)->ext_smdbltrp) {
50
+ env->mstatus = set_field(env->mstatus, MSTATUS_MDT, 1);
51
+ }
32
}
52
}
33
53
env->mcause = 0;
34
+ if (cpu->cfg.satp_mode.supported != 0) {
54
env->miclaim = MIP_SGEIP;
35
+ num_rhct_nodes++;
55
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
36
+ }
56
index XXXXXXX..XXXXXXX 100644
37
+
57
--- a/target/riscv/csr.c
38
/* Number of RHCT nodes*/
58
+++ b/target/riscv/csr.c
39
build_append_int_noprefix(table_data, num_rhct_nodes, 4);
59
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
40
41
@@ -XXX,XX +XXX,XX @@ static void build_rhct(GArray *table_data,
42
}
60
}
43
}
61
}
44
62
45
+ /* MMU node structure */
63
+ if (riscv_cpu_cfg(env)->ext_smdbltrp) {
46
+ if (cpu->cfg.satp_mode.supported != 0) {
64
+ mask |= MSTATUS_MDT;
47
+ satp_mode_max = satp_mode_max_from_map(cpu->cfg.satp_mode.map);
65
+ if ((val & MSTATUS_MDT) != 0) {
48
+ mmu_offset = table_data->len - table.table_offset;
66
+ val &= ~MSTATUS_MIE;
49
+ build_append_int_noprefix(table_data, 2, 2); /* Type */
50
+ build_append_int_noprefix(table_data, 8, 2); /* Length */
51
+ build_append_int_noprefix(table_data, 0x1, 2); /* Revision */
52
+ build_append_int_noprefix(table_data, 0, 1); /* Reserved */
53
+ /* MMU Type */
54
+ if (satp_mode_max == VM_1_10_SV57) {
55
+ build_append_int_noprefix(table_data, 2, 1); /* Sv57 */
56
+ } else if (satp_mode_max == VM_1_10_SV48) {
57
+ build_append_int_noprefix(table_data, 1, 1); /* Sv48 */
58
+ } else if (satp_mode_max == VM_1_10_SV39) {
59
+ build_append_int_noprefix(table_data, 0, 1); /* Sv39 */
60
+ } else {
61
+ assert(1);
62
+ }
67
+ }
63
+ }
68
+ }
64
+
69
+
65
/* Hart Info Node */
70
if (xl != MXL_RV32 || env->debugger) {
66
for (int i = 0; i < arch_ids->len; i++) {
71
if (riscv_has_ext(env, RVH)) {
67
len = 16;
72
mask |= MSTATUS_MPV | MSTATUS_GVA;
68
@@ -XXX,XX +XXX,XX @@ static void build_rhct(GArray *table_data,
73
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno,
69
num_offsets++;
74
uint64_t valh = (uint64_t)val << 32;
70
}
75
uint64_t mask = riscv_has_ext(env, RVH) ? MSTATUS_MPV | MSTATUS_GVA : 0;
71
76
72
+ if (mmu_offset) {
77
+ if (riscv_cpu_cfg(env)->ext_smdbltrp) {
73
+ len += 4;
78
+ mask |= MSTATUS_MDT;
74
+ num_offsets++;
79
+ if ((valh & MSTATUS_MDT) != 0) {
80
+ mask |= MSTATUS_MIE;
75
+ }
81
+ }
76
+
82
+ }
77
build_append_int_noprefix(table_data, len, 2);
83
env->mstatus = (env->mstatus & ~mask) | (valh & mask);
78
build_append_int_noprefix(table_data, 0x1, 2); /* Revision */
84
79
/* Number of offsets */
85
return RISCV_EXCP_NONE;
80
build_append_int_noprefix(table_data, num_offsets, 2);
81
build_append_int_noprefix(table_data, i, 4); /* ACPI Processor UID */
82
-
83
/* Offsets */
84
build_append_int_noprefix(table_data, isa_offset, 4);
85
if (cmo_offset) {
86
build_append_int_noprefix(table_data, cmo_offset, 4);
87
}
88
+
89
+ if (mmu_offset) {
90
+ build_append_int_noprefix(table_data, mmu_offset, 4);
91
+ }
92
}
93
94
acpi_table_end(linker, &table);
95
--
86
--
96
2.43.0
87
2.48.1
88
89
diff view generated by jsdifflib
1
From: Sunil V L <sunilvl@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
When CMO related extensions like Zicboz, Zicbom and Zicbop are enabled, the
3
When the Ssdbltrp extension is enabled, SSTATUS.MDT field is cleared
4
block size for those extensions need to be communicated via CMO node in
4
when executing sret if executed in M-mode. When executing mret/mnret,
5
RHCT. Add CMO node in RHCT if any of those CMO extensions are detected.
5
SSTATUS.MDT is cleared.
6
6
7
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
7
Signed-off-by: Clément Léger <cleger@rivosinc.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
9
Message-ID: <20250110125441.3208676-8-cleger@rivosinc.com>
10
Acked-by: Alistair Francis <alistair.francis@wdc.com>
11
Acked-by: Michael S. Tsirkin <mst@redhat.com>
12
Message-ID: <20231218150247.466427-9-sunilvl@ventanamicro.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
11
---
15
hw/riscv/virt-acpi-build.c | 64 +++++++++++++++++++++++++++++++++-----
12
target/riscv/op_helper.c | 12 ++++++++++++
16
1 file changed, 56 insertions(+), 8 deletions(-)
13
1 file changed, 12 insertions(+)
17
14
18
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
15
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
19
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/riscv/virt-acpi-build.c
17
--- a/target/riscv/op_helper.c
21
+++ b/hw/riscv/virt-acpi-build.c
18
+++ b/target/riscv/op_helper.c
22
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s)
19
@@ -XXX,XX +XXX,XX @@ target_ulong helper_sret(CPURISCVState *env)
23
* 5.2.36 RISC-V Hart Capabilities Table (RHCT)
20
}
24
* REF: https://github.com/riscv-non-isa/riscv-acpi/issues/16
21
mstatus = set_field(mstatus, MSTATUS_SDT, 0);
25
* https://drive.google.com/file/d/1nP3nFiH4jkPMp6COOxP6123DCZKR-tia/view
22
}
26
+ * https://drive.google.com/file/d/1sKbOa8m1UZw1JkquZYe3F1zQBN1xXsaf/view
23
+ if (riscv_cpu_cfg(env)->ext_smdbltrp && env->priv >= PRV_M) {
27
*/
24
+ mstatus = set_field(mstatus, MSTATUS_MDT, 0);
28
static void build_rhct(GArray *table_data,
29
BIOSLinker *linker,
30
@@ -XXX,XX +XXX,XX @@ static void build_rhct(GArray *table_data,
31
MachineState *ms = MACHINE(s);
32
const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(ms);
33
size_t len, aligned_len;
34
- uint32_t isa_offset, num_rhct_nodes;
35
- RISCVCPU *cpu;
36
+ uint32_t isa_offset, num_rhct_nodes, cmo_offset = 0;
37
+ RISCVCPU *cpu = &s->soc[0].harts[0];
38
char *isa;
39
40
AcpiTable table = { .sig = "RHCT", .rev = 1, .oem_id = s->oem_id,
41
@@ -XXX,XX +XXX,XX @@ static void build_rhct(GArray *table_data,
42
43
/* ISA + N hart info */
44
num_rhct_nodes = 1 + ms->smp.cpus;
45
+ if (cpu->cfg.ext_zicbom || cpu->cfg.ext_zicboz) {
46
+ num_rhct_nodes++;
47
+ }
25
+ }
48
26
if (env->priv_ver >= PRIV_VERSION_1_12_0) {
49
/* Number of RHCT nodes*/
27
mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
50
build_append_int_noprefix(table_data, num_rhct_nodes, 4);
51
@@ -XXX,XX +XXX,XX @@ static void build_rhct(GArray *table_data,
52
isa_offset = table_data->len - table.table_offset;
53
build_append_int_noprefix(table_data, 0, 2); /* Type 0 */
54
55
- cpu = &s->soc[0].harts[0];
56
isa = riscv_isa_string(cpu);
57
len = 8 + strlen(isa) + 1;
58
aligned_len = (len % 2) ? (len + 1) : len;
59
@@ -XXX,XX +XXX,XX @@ static void build_rhct(GArray *table_data,
60
build_append_int_noprefix(table_data, 0x0, 1); /* Optional Padding */
61
}
28
}
62
29
@@ -XXX,XX +XXX,XX @@ target_ulong helper_mret(CPURISCVState *env)
63
+ /* CMO node */
30
if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
64
+ if (cpu->cfg.ext_zicbom || cpu->cfg.ext_zicboz) {
31
mstatus = ssdbltrp_mxret(env, mstatus, prev_priv, prev_virt);
65
+ cmo_offset = table_data->len - table.table_offset;
32
}
66
+ build_append_int_noprefix(table_data, 1, 2); /* Type */
33
+ if (riscv_cpu_cfg(env)->ext_smdbltrp) {
67
+ build_append_int_noprefix(table_data, 10, 2); /* Length */
34
+ mstatus = set_field(mstatus, MSTATUS_MDT, 0);
68
+ build_append_int_noprefix(table_data, 0x1, 2); /* Revision */
35
+ }
69
+ build_append_int_noprefix(table_data, 0, 1); /* Reserved */
36
if ((env->priv_ver >= PRIV_VERSION_1_12_0) && (prev_priv != PRV_M)) {
70
+
37
mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
71
+ /* CBOM block size */
38
}
72
+ if (cpu->cfg.cbom_blocksize) {
39
@@ -XXX,XX +XXX,XX @@ target_ulong helper_mnret(CPURISCVState *env)
73
+ build_append_int_noprefix(table_data,
40
env->mstatus = ssdbltrp_mxret(env, env->mstatus, prev_priv, prev_virt);
74
+ __builtin_ctz(cpu->cfg.cbom_blocksize),
41
}
75
+ 1);
42
76
+ } else {
43
+ if (riscv_cpu_cfg(env)->ext_smdbltrp) {
77
+ build_append_int_noprefix(table_data, 0, 1);
44
+ if (prev_priv < PRV_M) {
78
+ }
45
+ env->mstatus = set_field(env->mstatus, MSTATUS_MDT, 0);
79
+
80
+ /* CBOP block size */
81
+ build_append_int_noprefix(table_data, 0, 1);
82
+
83
+ /* CBOZ block size */
84
+ if (cpu->cfg.cboz_blocksize) {
85
+ build_append_int_noprefix(table_data,
86
+ __builtin_ctz(cpu->cfg.cboz_blocksize),
87
+ 1);
88
+ } else {
89
+ build_append_int_noprefix(table_data, 0, 1);
90
+ }
46
+ }
91
+ }
47
+ }
92
+
48
+
93
/* Hart Info Node */
49
if (riscv_has_ext(env, RVH) && prev_virt) {
94
for (int i = 0; i < arch_ids->len; i++) {
50
riscv_cpu_swap_hypervisor_regs(env);
95
+ len = 16;
96
+ int num_offsets = 1;
97
build_append_int_noprefix(table_data, 0xFFFF, 2); /* Type */
98
- build_append_int_noprefix(table_data, 16, 2); /* Length */
99
- build_append_int_noprefix(table_data, 0x1, 2); /* Revision */
100
- build_append_int_noprefix(table_data, 1, 2); /* Number of offsets */
101
- build_append_int_noprefix(table_data, i, 4); /* ACPI Processor UID */
102
- build_append_int_noprefix(table_data, isa_offset, 4); /* Offsets[0] */
103
+
104
+ /* Length */
105
+ if (cmo_offset) {
106
+ len += 4;
107
+ num_offsets++;
108
+ }
109
+
110
+ build_append_int_noprefix(table_data, len, 2);
111
+ build_append_int_noprefix(table_data, 0x1, 2); /* Revision */
112
+ /* Number of offsets */
113
+ build_append_int_noprefix(table_data, num_offsets, 2);
114
+ build_append_int_noprefix(table_data, i, 4); /* ACPI Processor UID */
115
+
116
+ /* Offsets */
117
+ build_append_int_noprefix(table_data, isa_offset, 4);
118
+ if (cmo_offset) {
119
+ build_append_int_noprefix(table_data, cmo_offset, 4);
120
+ }
121
}
51
}
122
123
acpi_table_end(linker, &table);
124
--
52
--
125
2.43.0
53
2.48.1
54
55
diff view generated by jsdifflib
Deleted patch
1
From: Sunil V L <sunilvl@ventanamicro.com>
2
1
3
Add PLIC structures for each socket in the MADT when system is
4
configured with PLIC as the external interrupt controller.
5
6
Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
7
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
10
Acked-by: Alistair Francis <alistair.francis@wdc.com>
11
Acked-by: Michael S. Tsirkin <mst@redhat.com>
12
Message-ID: <20231218150247.466427-14-sunilvl@ventanamicro.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
15
hw/riscv/virt-acpi-build.c | 29 +++++++++++++++++++++++++++++
16
1 file changed, 29 insertions(+)
17
18
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/riscv/virt-acpi-build.c
21
+++ b/hw/riscv/virt-acpi-build.c
22
@@ -XXX,XX +XXX,XX @@ static void riscv_acpi_madt_add_rintc(uint32_t uid,
23
arch_ids->cpus[uid].props.node_id,
24
local_cpu_id),
25
4);
26
+ } else if (s->aia_type == VIRT_AIA_TYPE_NONE) {
27
+ build_append_int_noprefix(entry,
28
+ ACPI_BUILD_INTC_ID(
29
+ arch_ids->cpus[uid].props.node_id,
30
+ 2 * local_cpu_id + 1),
31
+ 4);
32
} else {
33
build_append_int_noprefix(entry, 0, 4);
34
}
35
@@ -XXX,XX +XXX,XX @@ static void build_madt(GArray *table_data,
36
build_append_int_noprefix(table_data,
37
s->memmap[VIRT_APLIC_S].size, 4);
38
}
39
+ } else {
40
+ /* PLICs */
41
+ for (socket = 0; socket < riscv_socket_count(ms); socket++) {
42
+ aplic_addr = s->memmap[VIRT_PLIC].base +
43
+ s->memmap[VIRT_PLIC].size * socket;
44
+ gsi_base = VIRT_IRQCHIP_NUM_SOURCES * socket;
45
+ build_append_int_noprefix(table_data, 0x1B, 1); /* Type */
46
+ build_append_int_noprefix(table_data, 36, 1); /* Length */
47
+ build_append_int_noprefix(table_data, 1, 1); /* Version */
48
+ build_append_int_noprefix(table_data, socket, 1); /* PLIC ID */
49
+ build_append_int_noprefix(table_data, 0, 8); /* Hardware ID */
50
+ /* Total External Interrupt Sources Supported */
51
+ build_append_int_noprefix(table_data,
52
+ VIRT_IRQCHIP_NUM_SOURCES - 1, 2);
53
+ build_append_int_noprefix(table_data, 0, 2); /* Max Priority */
54
+ build_append_int_noprefix(table_data, 0, 4); /* Flags */
55
+ /* PLIC Size */
56
+ build_append_int_noprefix(table_data, s->memmap[VIRT_PLIC].size, 4);
57
+ /* PLIC Address */
58
+ build_append_int_noprefix(table_data, aplic_addr, 8);
59
+ /* Global System Interrupt Vector Base */
60
+ build_append_int_noprefix(table_data, gsi_base, 4);
61
+ }
62
}
63
64
acpi_table_end(linker, &table);
65
--
66
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Rob Bradford <rbradford@rivosinc.com>
2
1
3
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
4
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
6
Message-ID: <20231207153842.32401-3-rbradford@rivosinc.com>
7
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
---
9
disas/riscv.c | 9 +++++++++
10
1 file changed, 9 insertions(+)
11
12
diff --git a/disas/riscv.c b/disas/riscv.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/disas/riscv.c
15
+++ b/disas/riscv.c
16
@@ -XXX,XX +XXX,XX @@ typedef enum {
17
rv_op_vwsll_vv = 872,
18
rv_op_vwsll_vx = 873,
19
rv_op_vwsll_vi = 874,
20
+ rv_op_amocas_w = 875,
21
+ rv_op_amocas_d = 876,
22
+ rv_op_amocas_q = 877,
23
} rv_op;
24
25
/* register names */
26
@@ -XXX,XX +XXX,XX @@ const rv_opcode_data rvi_opcode_data[] = {
27
{ "vwsll.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm, NULL, 0, 0, 0 },
28
{ "vwsll.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm, NULL, 0, 0, 0 },
29
{ "vwsll.vi", rv_codec_v_i, rv_fmt_vd_vs2_uimm_vm, NULL, 0, 0, 0 },
30
+ { "amocas.w", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 },
31
+ { "amocas.d", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 },
32
+ { "amocas.q", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 },
33
};
34
35
/* CSR names */
36
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
37
case 34: op = rv_op_amoxor_w; break;
38
case 35: op = rv_op_amoxor_d; break;
39
case 36: op = rv_op_amoxor_q; break;
40
+ case 42: op = rv_op_amocas_w; break;
41
+ case 43: op = rv_op_amocas_d; break;
42
+ case 44: op = rv_op_amocas_q; break;
43
case 66: op = rv_op_amoor_w; break;
44
case 67: op = rv_op_amoor_d; break;
45
case 68: op = rv_op_amoor_q; break;
46
--
47
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2
1
3
Since QEMU v8.0.0 the RISC-V virt machine has a switch to disable ACPI
4
table generation. Add it to the documentation.
5
6
Fixes: 168b8c29cedb ("hw/riscv/virt: Add a switch to disable ACPI")
7
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-ID: <20231220193436.25909-1-heinrich.schuchardt@canonical.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
docs/system/riscv/virt.rst | 5 +++++
15
1 file changed, 5 insertions(+)
16
17
diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst
18
index XXXXXXX..XXXXXXX 100644
19
--- a/docs/system/riscv/virt.rst
20
+++ b/docs/system/riscv/virt.rst
21
@@ -XXX,XX +XXX,XX @@ The following machine-specific options are supported:
22
SiFive CLINT. When not specified, this option is assumed to be "off".
23
This option is restricted to the TCG accelerator.
24
25
+- acpi=[on|off|auto]
26
+
27
+ When this option is "on" (which is the default), ACPI tables are generated and
28
+ exposed as firmware tables etc/acpi/rsdp and etc/acpi/tables.
29
+
30
- aia=[none|aplic|aplic-imsic]
31
32
This option allows selecting interrupt controller defined by the AIA
33
--
34
2.43.0
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
RVG behaves like a profile: a single flag enables a set of bits. Right
3
When the Smsdbltrp ISA extension is enabled, if a trap happens while
4
now we're considering user choice when handling RVG and zicsr/zifencei
4
MSTATUS.MDT is already set, it will trigger an abort or an NMI is the
5
and ignoring user choice on MISA bits.
5
Smrnmi extension is available.
6
6
7
We'll add user warnings for profiles when the user disables its
7
Signed-off-by: Clément Léger <cleger@rivosinc.com>
8
mandatory extensions in the next patch. We'll do the same thing with RVG
9
now to keep consistency between RVG and profile handling.
10
11
First and foremost, create a new RVG only helper to avoid clogging
12
riscv_cpu_validate_set_extensions(). We do not want to annoy users with
13
RVG warnings like we did in the past (see 9b9741c38f), thus we'll only
14
warn if RVG was user set and the user disabled a RVG extension in the
15
command line.
16
17
For every RVG MISA bit (IMAFD), zicsr and zifencei, the logic then
18
becomes:
19
20
- if enabled, do nothing;
21
- if disabled and not user set, enable it;
22
- if disabled and user set, throw a warning that it's a RVG mandatory
23
extension.
24
25
This same logic will be used for profiles in the next patch.
26
27
Note that this is a behavior change, where we would error out if the
28
user disabled either zicsr or zifencei. As long as users are explicitly
29
disabling things in the command line we'll let them have a go at it, at
30
least in this step. We'll error out later in the validation if needed.
31
32
Other notable changes from the previous RVG code:
33
34
- use riscv_cpu_write_misa_bit() instead of manually updating both
35
env->misa_ext and env->misa_ext_mask;
36
37
- set zicsr and zifencei directly. We're already checking if they
38
were user set and priv version will never fail for these
39
extensions, making cpu_cfg_ext_auto_update() redundant.
40
41
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
42
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
43
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
44
Message-ID: <20231218125334.37184-16-dbarboza@ventanamicro.com>
9
Message-ID: <20250110125441.3208676-9-cleger@rivosinc.com>
45
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
46
---
11
---
47
target/riscv/tcg/tcg-cpu.c | 73 +++++++++++++++++++++++++-------------
12
target/riscv/cpu_helper.c | 57 ++++++++++++++++++++++++++++-----------
48
1 file changed, 48 insertions(+), 25 deletions(-)
13
1 file changed, 41 insertions(+), 16 deletions(-)
49
14
50
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
51
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
52
--- a/target/riscv/tcg/tcg-cpu.c
17
--- a/target/riscv/cpu_helper.c
53
+++ b/target/riscv/tcg/tcg-cpu.c
18
+++ b/target/riscv/cpu_helper.c
54
@@ -XXX,XX +XXX,XX @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
19
@@ -XXX,XX +XXX,XX @@ static target_ulong promote_load_fault(target_ulong orig_cause)
55
GUINT_TO_POINTER(ext_offset));
20
/* if no promotion, return original cause */
21
return orig_cause;
56
}
22
}
57
23
+
58
+static bool cpu_misa_ext_is_user_set(uint32_t misa_bit)
24
+static void riscv_do_nmi(CPURISCVState *env, target_ulong cause, bool virt)
59
+{
25
+{
60
+ return g_hash_table_contains(misa_ext_user_opts,
26
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_NMIE, false);
61
+ GUINT_TO_POINTER(misa_bit));
27
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPV, virt);
62
+}
28
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPP, env->priv);
29
+ env->mncause = cause;
30
+ env->mnepc = env->pc;
31
+ env->pc = env->rnmi_irqvec;
63
+
32
+
64
static void cpu_cfg_ext_add_user_opt(uint32_t ext_offset, bool value)
33
+ if (cpu_get_fcfien(env)) {
65
{
34
+ env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPELP, env->elp);
66
g_hash_table_insert(multi_ext_user_opts, GUINT_TO_POINTER(ext_offset),
67
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_update_named_features(RISCVCPU *cpu)
68
cpu->cfg.cboz_blocksize == 64;
69
}
70
71
+static void riscv_cpu_validate_g(RISCVCPU *cpu)
72
+{
73
+ const char *warn_msg = "RVG mandates disabled extension %s";
74
+ uint32_t g_misa_bits[] = {RVI, RVM, RVA, RVF, RVD};
75
+ bool send_warn = cpu_misa_ext_is_user_set(RVG);
76
+
77
+ for (int i = 0; i < ARRAY_SIZE(g_misa_bits); i++) {
78
+ uint32_t bit = g_misa_bits[i];
79
+
80
+ if (riscv_has_ext(&cpu->env, bit)) {
81
+ continue;
82
+ }
83
+
84
+ if (!cpu_misa_ext_is_user_set(bit)) {
85
+ riscv_cpu_write_misa_bit(cpu, bit, true);
86
+ continue;
87
+ }
88
+
89
+ if (send_warn) {
90
+ warn_report(warn_msg, riscv_get_misa_ext_name(bit));
91
+ }
92
+ }
35
+ }
93
+
36
+
94
+ if (!cpu->cfg.ext_zicsr) {
37
+ /* Trapping to M mode, virt is disabled */
95
+ if (!cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_zicsr))) {
38
+ riscv_cpu_set_mode(env, PRV_M, false);
96
+ cpu->cfg.ext_zicsr = true;
97
+ } else if (send_warn) {
98
+ warn_report(warn_msg, "zicsr");
99
+ }
100
+ }
101
+
102
+ if (!cpu->cfg.ext_zifencei) {
103
+ if (!cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_zifencei))) {
104
+ cpu->cfg.ext_zifencei = true;
105
+ } else if (send_warn) {
106
+ warn_report(warn_msg, "zifencei");
107
+ }
108
+ }
109
+}
39
+}
110
+
40
+
111
/*
41
/*
112
* Check consistency between chosen extensions while setting
42
* Handle Traps
113
* cpu->cfg accordingly.
43
*
114
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
44
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
115
CPURISCVState *env = &cpu->env;
45
bool nnmi_excep = false;
116
Error *local_err = NULL;
46
117
47
if (cpu->cfg.ext_smrnmi && env->rnmip && async) {
118
- /* Do some ISA extension error checking */
48
- env->mnstatus = set_field(env->mnstatus, MNSTATUS_NMIE, false);
119
- if (riscv_has_ext(env, RVG) &&
49
- env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPV,
120
- !(riscv_has_ext(env, RVI) && riscv_has_ext(env, RVM) &&
50
- env->virt_enabled);
121
- riscv_has_ext(env, RVA) && riscv_has_ext(env, RVF) &&
51
- env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPP,
122
- riscv_has_ext(env, RVD) &&
52
- env->priv);
123
- cpu->cfg.ext_zicsr && cpu->cfg.ext_zifencei)) {
53
- env->mncause = cause | ((target_ulong)1U << (mxlen - 1));
54
- env->mnepc = env->pc;
55
- env->pc = env->rnmi_irqvec;
124
-
56
-
125
- if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_zicsr)) &&
57
- if (cpu_get_fcfien(env)) {
126
- !cpu->cfg.ext_zicsr) {
58
- env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPELP, env->elp);
127
- error_setg(errp, "RVG requires Zicsr but user set Zicsr to false");
128
- return;
129
- }
59
- }
130
-
60
-
131
- if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_zifencei)) &&
61
- /* Trapping to M mode, virt is disabled */
132
- !cpu->cfg.ext_zifencei) {
62
- riscv_cpu_set_mode(env, PRV_M, false);
133
- error_setg(errp, "RVG requires Zifencei but user set "
134
- "Zifencei to false");
135
- return;
136
- }
137
-
63
-
138
- cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zicsr), true);
64
+ riscv_do_nmi(env, cause | ((target_ulong)1U << (mxlen - 1)),
139
- cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zifencei), true);
65
+ env->virt_enabled);
140
-
66
return;
141
- env->misa_ext |= RVI | RVM | RVA | RVF | RVD;
142
- env->misa_ext_mask |= RVI | RVM | RVA | RVF | RVD;
143
+ if (riscv_has_ext(env, RVG)) {
144
+ riscv_cpu_validate_g(cpu);
145
}
67
}
146
68
147
if (riscv_has_ext(env, RVI) && riscv_has_ext(env, RVE)) {
69
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
70
/* Trapping to M mode, virt is disabled */
71
virt = false;
72
}
73
+ /*
74
+ * If the hart encounters an exception while executing in M-mode,
75
+ * with the mnstatus.NMIE bit clear, the program counter is set to
76
+ * the RNMI exception trap handler address.
77
+ */
78
+ nnmi_excep = cpu->cfg.ext_smrnmi &&
79
+ !get_field(env->mnstatus, MNSTATUS_NMIE) &&
80
+ !async;
81
82
s = env->mstatus;
83
s = set_field(s, MSTATUS_MPIE, get_field(s, MSTATUS_MIE));
84
s = set_field(s, MSTATUS_MPP, env->priv);
85
s = set_field(s, MSTATUS_MIE, 0);
86
+ if (cpu->cfg.ext_smdbltrp) {
87
+ if (env->mstatus & MSTATUS_MDT) {
88
+ assert(env->priv == PRV_M);
89
+ if (!cpu->cfg.ext_smrnmi || nnmi_excep) {
90
+ cpu_abort(CPU(cpu), "M-mode double trap\n");
91
+ } else {
92
+ riscv_do_nmi(env, cause, false);
93
+ return;
94
+ }
95
+ }
96
+
97
+ s = set_field(s, MSTATUS_MDT, 1);
98
+ }
99
env->mstatus = s;
100
env->mcause = cause | ((target_ulong)async << (mxlen - 1));
101
if (smode_double_trap) {
148
--
102
--
149
2.43.0
103
2.48.1
104
105
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
Certain S-mode profiles, like RVA22S64 and RVA23S64, mandate all the
3
Add the switch to enable the Smdbltrp ISA extension and disable it for
4
mandatory extensions of their respective U-mode profiles. RVA22S64
4
the max cpu. Indeed, OpenSBI when Smdbltrp is present, M-mode double
5
includes all mandatory extensions of RVA22U64, and the same happens with
5
trap is enabled by default and MSTATUS.MDT needs to be cleared to avoid
6
RVA23 profiles.
6
taking a double trap. OpenSBI does not currently support it so disable
7
it for the max cpu to avoid breaking regression tests.
7
8
8
Add a 'parent' field to allow profiles to enable other profiles. This
9
Signed-off-by: Clément Léger <cleger@rivosinc.com>
9
will allow us to describe S-mode profiles by specifying their parent
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
U-mode profile, then adding just the S-mode specific extensions.
11
Message-ID: <20250116131539.2475785-1-cleger@rivosinc.com>
11
12
We're naming the field 'parent' to consider the possibility of other
13
uses (e.g. a s-mode profile including a previous s-mode profile) in the
14
future.
15
16
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
17
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
18
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
19
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Message-ID: <20231218125334.37184-25-dbarboza@ventanamicro.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
---
13
---
23
target/riscv/cpu.h | 1 +
14
target/riscv/cpu.c | 2 ++
24
target/riscv/cpu.c | 1 +
15
target/riscv/tcg/tcg-cpu.c | 10 ++++++++++
25
target/riscv/tcg/tcg-cpu.c | 14 +++++++++++++-
16
2 files changed, 12 insertions(+)
26
3 files changed, 15 insertions(+), 1 deletion(-)
27
17
28
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/riscv/cpu.h
31
+++ b/target/riscv/cpu.h
32
@@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit);
33
#define CPU_CFG_OFFSET(_prop) offsetof(struct RISCVCPUConfig, _prop)
34
35
typedef struct riscv_cpu_profile {
36
+ struct riscv_cpu_profile *parent;
37
const char *name;
38
uint32_t misa_ext;
39
bool enabled;
40
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
18
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
41
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
42
--- a/target/riscv/cpu.c
20
--- a/target/riscv/cpu.c
43
+++ b/target/riscv/cpu.c
21
+++ b/target/riscv/cpu.c
44
@@ -XXX,XX +XXX,XX @@ Property riscv_cpu_options[] = {
22
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
45
* having a cfg offset) at this moment.
23
ISA_EXT_DATA_ENTRY(smcdeleg, PRIV_VERSION_1_13_0, ext_smcdeleg),
46
*/
24
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
47
static RISCVCPUProfile RVA22U64 = {
25
ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind),
48
+ .parent = NULL,
26
+ ISA_EXT_DATA_ENTRY(smdbltrp, PRIV_VERSION_1_13_0, ext_smdbltrp),
49
.name = "rva22u64",
27
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
50
.misa_ext = RVI | RVM | RVA | RVF | RVD | RVC | RVU,
28
ISA_EXT_DATA_ENTRY(smrnmi, PRIV_VERSION_1_12_0, ext_smrnmi),
51
.priv_spec = RISCV_PROFILE_ATTR_UNUSED,
29
ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm),
30
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
31
MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false),
32
33
MULTI_EXT_CFG_BOOL("smaia", ext_smaia, false),
34
+ MULTI_EXT_CFG_BOOL("smdbltrp", ext_smdbltrp, false),
35
MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false),
36
MULTI_EXT_CFG_BOOL("smrnmi", ext_smrnmi, false),
37
MULTI_EXT_CFG_BOOL("smmpm", ext_smmpm, false),
52
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
38
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
53
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
54
--- a/target/riscv/tcg/tcg-cpu.c
40
--- a/target/riscv/tcg/tcg-cpu.c
55
+++ b/target/riscv/tcg/tcg-cpu.c
41
+++ b/target/riscv/tcg/tcg-cpu.c
56
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_profile(RISCVCPU *cpu,
42
@@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj)
57
CPURISCVState *env = &cpu->env;
43
isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_smrnmi), false);
58
const char *warn_msg = "Profile %s mandates disabled extension %s";
44
qemu_log("Smrnmi is disabled in the 'max' type CPU\n");
59
bool send_warn = profile->user_set && profile->enabled;
60
- bool profile_impl = true;
61
+ bool parent_enabled, profile_impl = true;
62
int i;
63
64
#ifndef CONFIG_USER_ONLY
65
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_profile(RISCVCPU *cpu,
66
}
45
}
67
68
profile->enabled = profile_impl;
69
+
46
+
70
+ if (profile->parent != NULL) {
47
+ /*
71
+ parent_enabled = object_property_get_bool(OBJECT(cpu),
48
+ * ext_smdbltrp requires the firmware to clear MSTATUS.MDT on startup to
72
+ profile->parent->name,
49
+ * avoid generating a double trap. OpenSBI does not currently support it,
73
+ NULL);
50
+ * disable it for now.
74
+ profile->enabled = profile->enabled && parent_enabled;
51
+ */
52
+ if (cpu->cfg.ext_smdbltrp) {
53
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_smdbltrp), false);
54
+ qemu_log("Smdbltrp is disabled in the 'max' type CPU\n");
75
+ }
55
+ }
76
}
56
}
77
57
78
static void riscv_cpu_validate_profiles(RISCVCPU *cpu)
58
static bool riscv_cpu_has_max_extensions(Object *cpu_obj)
79
@@ -XXX,XX +XXX,XX @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
80
profile->user_set = true;
81
profile->enabled = value;
82
83
+ if (profile->parent != NULL) {
84
+ object_property_set_bool(obj, profile->parent->name,
85
+ profile->enabled, NULL);
86
+ }
87
+
88
if (profile->enabled) {
89
cpu->env.priv_ver = profile->priv_spec;
90
}
91
--
59
--
92
2.43.0
60
2.48.1
61
62
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
Named features (zic64b the sole example at this moment) aren't expose to
3
This commit introduces a translation tag to avoid invalidating an entry
4
users, thus we need another way to expose them.
4
that should not be invalidated when IOMMU executes invalidation commands.
5
E.g. IOTINVAL.VMA with GV=0, AV=0, PSCV=1 invalidates both a mapping
6
of single stage translation and a mapping of nested translation with
7
the same PSCID, but only the former one should be invalidated.
5
8
6
Go through each named feature, get its boolean value, do the needed
9
Signed-off-by: Jason Chien <jason.chien@sifive.com>
7
conversions (bool to qbool, qbool to QObject) and add it to output dict.
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
11
Message-ID: <20241108110147.11178-1-jason.chien@sifive.com>
9
Another adjustment is needed: named features are evaluated during
10
finalize(), so riscv_cpu_finalize_features() needs to be mandatory
11
regardless of whether we have an input dict or not. Otherwise zic64b
12
will always return 'false', which is incorrect: the default values of
13
cache blocksizes ([cbom/cbop/cboz]_blocksize) are set to 64, satisfying
14
the conditions for zic64b.
15
16
Here's an API usage example after this patch:
17
18
$ ./build/qemu-system-riscv64 -S -M virt -display none
19
-qmp tcp:localhost:1234,server,wait=off
20
21
$ ./scripts/qmp/qmp-shell localhost:1234
22
Welcome to the QMP low-level shell!
23
Connected to QEMU 8.1.50
24
25
(QEMU) query-cpu-model-expansion type=full model={"name":"rv64"}
26
{"return": {"model":
27
{"name": "rv64", "props": {... "zic64b": true, ...}}}}
28
29
zic64b is set to 'true', as expected, since all cache sizes are 64
30
bytes by default.
31
32
If we change one of the cache blocksizes, zic64b is returned as 'false':
33
34
(QEMU) query-cpu-model-expansion type=full model={"name":"rv64","props":{"cbom_blocksize":128}}
35
{"return": {"model":
36
{"name": "rv64", "props": {... "zic64b": false, ...}}}}
37
38
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
39
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
40
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
41
Message-ID: <20231218125334.37184-8-dbarboza@ventanamicro.com>
42
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
43
---
13
---
44
target/riscv/riscv-qmp-cmds.c | 30 +++++++++++++++++++++++++-----
14
hw/riscv/riscv-iommu.c | 205 ++++++++++++++++++++++++++++++-----------
45
1 file changed, 25 insertions(+), 5 deletions(-)
15
1 file changed, 153 insertions(+), 52 deletions(-)
46
16
47
diff --git a/target/riscv/riscv-qmp-cmds.c b/target/riscv/riscv-qmp-cmds.c
17
diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
48
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
49
--- a/target/riscv/riscv-qmp-cmds.c
19
--- a/hw/riscv/riscv-iommu.c
50
+++ b/target/riscv/riscv-qmp-cmds.c
20
+++ b/hw/riscv/riscv-iommu.c
51
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUContext {
52
22
uint64_t msiptp; /* MSI redirection page table pointer */
53
#include "qapi/error.h"
23
};
54
#include "qapi/qapi-commands-machine-target.h"
24
55
+#include "qapi/qmp/qbool.h"
25
+typedef enum RISCVIOMMUTransTag {
56
#include "qapi/qmp/qdict.h"
26
+ RISCV_IOMMU_TRANS_TAG_BY, /* Bypass */
57
#include "qapi/qmp/qerror.h"
27
+ RISCV_IOMMU_TRANS_TAG_SS, /* Single Stage */
58
#include "qapi/qobject-input-visitor.h"
28
+ RISCV_IOMMU_TRANS_TAG_VG, /* G-stage only */
59
@@ -XXX,XX +XXX,XX @@ static void riscv_obj_add_multiext_props(Object *obj, QDict *qdict_out,
29
+ RISCV_IOMMU_TRANS_TAG_VN, /* Nested translation */
60
}
30
+} RISCVIOMMUTransTag;
61
}
31
+
62
32
/* Address translation cache entry */
63
+static void riscv_obj_add_named_feats_qdict(Object *obj, QDict *qdict_out)
33
struct RISCVIOMMUEntry {
34
+ RISCVIOMMUTransTag tag; /* Translation Tag */
35
uint64_t iova:44; /* IOVA Page Number */
36
uint64_t pscid:20; /* Process Soft-Context identifier */
37
uint64_t phys:44; /* Physical Page Number */
38
@@ -XXX,XX +XXX,XX @@ static gboolean riscv_iommu_iot_equal(gconstpointer v1, gconstpointer v2)
39
RISCVIOMMUEntry *t1 = (RISCVIOMMUEntry *) v1;
40
RISCVIOMMUEntry *t2 = (RISCVIOMMUEntry *) v2;
41
return t1->gscid == t2->gscid && t1->pscid == t2->pscid &&
42
- t1->iova == t2->iova;
43
+ t1->iova == t2->iova && t1->tag == t2->tag;
44
}
45
46
static guint riscv_iommu_iot_hash(gconstpointer v)
47
@@ -XXX,XX +XXX,XX @@ static guint riscv_iommu_iot_hash(gconstpointer v)
48
return (guint)t->iova;
49
}
50
51
-/* GV: 1 PSCV: 1 AV: 1 */
52
+/* GV: 0 AV: 0 PSCV: 0 GVMA: 0 */
53
+/* GV: 0 AV: 0 GVMA: 1 */
54
+static
55
+void riscv_iommu_iot_inval_all(gpointer key, gpointer value, gpointer data)
64
+{
56
+{
65
+ const RISCVCPUMultiExtConfig *named_cfg;
57
+ RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;
66
+ RISCVCPU *cpu = RISCV_CPU(obj);
58
+ RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data;
67
+ QObject *value;
59
+ if (iot->tag == arg->tag) {
68
+ bool flag_val;
60
+ iot->perm = IOMMU_NONE;
69
+
70
+ for (int i = 0; riscv_cpu_named_features[i].name != NULL; i++) {
71
+ named_cfg = &riscv_cpu_named_features[i];
72
+ flag_val = isa_ext_is_enabled(cpu, named_cfg->offset);
73
+ value = QOBJECT(qbool_from_bool(flag_val));
74
+
75
+ qdict_put_obj(qdict_out, named_cfg->name, value);
76
+ }
61
+ }
77
+}
62
+}
78
+
63
+
79
static void riscv_cpuobj_validate_qdict_in(Object *obj, QObject *props,
64
+/* GV: 0 AV: 0 PSCV: 1 GVMA: 0 */
80
const QDict *qdict_in,
65
+static
81
Error **errp)
66
+void riscv_iommu_iot_inval_pscid(gpointer key, gpointer value, gpointer data)
82
@@ -XXX,XX +XXX,XX @@ static void riscv_cpuobj_validate_qdict_in(Object *obj, QObject *props,
67
+{
83
goto err;
68
+ RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;
84
}
69
+ RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data;
85
70
+ if (iot->tag == arg->tag &&
86
- riscv_cpu_finalize_features(RISCV_CPU(obj), &local_err);
71
+ iot->pscid == arg->pscid) {
87
- if (local_err) {
72
+ iot->perm = IOMMU_NONE;
88
- goto err;
73
+ }
89
- }
74
+}
90
-
75
+
91
visit_end_struct(visitor, NULL);
76
+/* GV: 0 AV: 1 PSCV: 0 GVMA: 0 */
92
77
+static
93
err:
78
+void riscv_iommu_iot_inval_iova(gpointer key, gpointer value, gpointer data)
94
@@ -XXX,XX +XXX,XX @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
79
+{
80
+ RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;
81
+ RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data;
82
+ if (iot->tag == arg->tag &&
83
+ iot->iova == arg->iova) {
84
+ iot->perm = IOMMU_NONE;
85
+ }
86
+}
87
+
88
+/* GV: 0 AV: 1 PSCV: 1 GVMA: 0 */
89
static void riscv_iommu_iot_inval_pscid_iova(gpointer key, gpointer value,
90
gpointer data)
91
{
92
RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;
93
RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data;
94
- if (iot->gscid == arg->gscid &&
95
+ if (iot->tag == arg->tag &&
96
iot->pscid == arg->pscid &&
97
iot->iova == arg->iova) {
98
iot->perm = IOMMU_NONE;
99
}
100
}
101
102
-/* GV: 1 PSCV: 1 AV: 0 */
103
-static void riscv_iommu_iot_inval_pscid(gpointer key, gpointer value,
104
- gpointer data)
105
+/* GV: 1 AV: 0 PSCV: 0 GVMA: 0 */
106
+/* GV: 1 AV: 0 GVMA: 1 */
107
+static
108
+void riscv_iommu_iot_inval_gscid(gpointer key, gpointer value, gpointer data)
109
{
110
RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;
111
RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data;
112
- if (iot->gscid == arg->gscid &&
113
- iot->pscid == arg->pscid) {
114
+ if (iot->tag == arg->tag &&
115
+ iot->gscid == arg->gscid) {
116
iot->perm = IOMMU_NONE;
117
}
118
}
119
120
-/* GV: 1 GVMA: 1 */
121
-static void riscv_iommu_iot_inval_gscid_gpa(gpointer key, gpointer value,
122
- gpointer data)
123
+/* GV: 1 AV: 0 PSCV: 1 GVMA: 0 */
124
+static void riscv_iommu_iot_inval_gscid_pscid(gpointer key, gpointer value,
125
+ gpointer data)
126
{
127
RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;
128
RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data;
129
- if (iot->gscid == arg->gscid) {
130
- /* simplified cache, no GPA matching */
131
+ if (iot->tag == arg->tag &&
132
+ iot->gscid == arg->gscid &&
133
+ iot->pscid == arg->pscid) {
134
iot->perm = IOMMU_NONE;
135
}
136
}
137
138
-/* GV: 1 GVMA: 0 */
139
-static void riscv_iommu_iot_inval_gscid(gpointer key, gpointer value,
140
- gpointer data)
141
+/* GV: 1 AV: 1 PSCV: 0 GVMA: 0 */
142
+/* GV: 1 AV: 1 GVMA: 1 */
143
+static void riscv_iommu_iot_inval_gscid_iova(gpointer key, gpointer value,
144
+ gpointer data)
145
{
146
RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;
147
RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data;
148
- if (iot->gscid == arg->gscid) {
149
+ if (iot->tag == arg->tag &&
150
+ iot->gscid == arg->gscid &&
151
+ iot->iova == arg->iova) {
152
iot->perm = IOMMU_NONE;
153
}
154
}
155
156
-/* GV: 0 */
157
-static void riscv_iommu_iot_inval_all(gpointer key, gpointer value,
158
- gpointer data)
159
+/* GV: 1 AV: 1 PSCV: 1 GVMA: 0 */
160
+static void riscv_iommu_iot_inval_gscid_pscid_iova(gpointer key, gpointer value,
161
+ gpointer data)
162
{
163
RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;
164
- iot->perm = IOMMU_NONE;
165
+ RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data;
166
+ if (iot->tag == arg->tag &&
167
+ iot->gscid == arg->gscid &&
168
+ iot->pscid == arg->pscid &&
169
+ iot->iova == arg->iova) {
170
+ iot->perm = IOMMU_NONE;
171
+ }
172
}
173
174
/* caller should keep ref-count for iot_cache object */
175
static RISCVIOMMUEntry *riscv_iommu_iot_lookup(RISCVIOMMUContext *ctx,
176
- GHashTable *iot_cache, hwaddr iova)
177
+ GHashTable *iot_cache, hwaddr iova, RISCVIOMMUTransTag transtag)
178
{
179
RISCVIOMMUEntry key = {
180
+ .tag = transtag,
181
.gscid = get_field(ctx->gatp, RISCV_IOMMU_DC_IOHGATP_GSCID),
182
.pscid = get_field(ctx->ta, RISCV_IOMMU_DC_TA_PSCID),
183
.iova = PPN_DOWN(iova),
184
@@ -XXX,XX +XXX,XX @@ static void riscv_iommu_iot_update(RISCVIOMMUState *s,
185
}
186
187
static void riscv_iommu_iot_inval(RISCVIOMMUState *s, GHFunc func,
188
- uint32_t gscid, uint32_t pscid, hwaddr iova)
189
+ uint32_t gscid, uint32_t pscid, hwaddr iova, RISCVIOMMUTransTag transtag)
190
{
191
GHashTable *iot_cache;
192
RISCVIOMMUEntry key = {
193
+ .tag = transtag,
194
.gscid = gscid,
195
.pscid = pscid,
196
.iova = PPN_DOWN(iova),
197
@@ -XXX,XX +XXX,XX @@ static void riscv_iommu_iot_inval(RISCVIOMMUState *s, GHFunc func,
198
g_hash_table_unref(iot_cache);
199
}
200
201
+static RISCVIOMMUTransTag riscv_iommu_get_transtag(RISCVIOMMUContext *ctx)
202
+{
203
+ uint64_t satp = get_field(ctx->satp, RISCV_IOMMU_ATP_MODE_FIELD);
204
+ uint64_t gatp = get_field(ctx->gatp, RISCV_IOMMU_ATP_MODE_FIELD);
205
+
206
+ if (satp == RISCV_IOMMU_DC_FSC_MODE_BARE) {
207
+ return (gatp == RISCV_IOMMU_DC_IOHGATP_MODE_BARE) ?
208
+ RISCV_IOMMU_TRANS_TAG_BY : RISCV_IOMMU_TRANS_TAG_VG;
209
+ } else {
210
+ return (gatp == RISCV_IOMMU_DC_IOHGATP_MODE_BARE) ?
211
+ RISCV_IOMMU_TRANS_TAG_SS : RISCV_IOMMU_TRANS_TAG_VN;
212
+ }
213
+}
214
+
215
static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
216
IOMMUTLBEntry *iotlb, bool enable_cache)
217
{
218
+ RISCVIOMMUTransTag transtag = riscv_iommu_get_transtag(ctx);
219
RISCVIOMMUEntry *iot;
220
IOMMUAccessFlags perm;
221
bool enable_pid;
222
@@ -XXX,XX +XXX,XX @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
95
}
223
}
96
}
224
}
97
225
98
+ riscv_cpu_finalize_features(RISCV_CPU(obj), &local_err);
226
- iot = riscv_iommu_iot_lookup(ctx, iot_cache, iotlb->iova);
99
+ if (local_err) {
227
+ iot = riscv_iommu_iot_lookup(ctx, iot_cache, iotlb->iova, transtag);
100
+ error_propagate(errp, local_err);
228
perm = iot ? iot->perm : IOMMU_NONE;
101
+ object_unref(obj);
229
if (perm != IOMMU_NONE) {
102
+ return NULL;
230
iotlb->translated_addr = PPN_PHYS(iot->phys);
103
+ }
231
@@ -XXX,XX +XXX,XX @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
104
+
232
iot->gscid = get_field(ctx->gatp, RISCV_IOMMU_DC_IOHGATP_GSCID);
105
expansion_info = g_new0(CpuModelExpansionInfo, 1);
233
iot->pscid = get_field(ctx->ta, RISCV_IOMMU_DC_TA_PSCID);
106
expansion_info->model = g_malloc0(sizeof(*expansion_info->model));
234
iot->perm = iotlb->perm;
107
expansion_info->model->name = g_strdup(model->name);
235
+ iot->tag = transtag;
108
@@ -XXX,XX +XXX,XX @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
236
riscv_iommu_iot_update(s, iot_cache, iot);
109
riscv_obj_add_multiext_props(obj, qdict_out, riscv_cpu_extensions);
237
}
110
riscv_obj_add_multiext_props(obj, qdict_out, riscv_cpu_experimental_exts);
238
111
riscv_obj_add_multiext_props(obj, qdict_out, riscv_cpu_vendor_exts);
239
@@ -XXX,XX +XXX,XX @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUState *s)
112
+ riscv_obj_add_named_feats_qdict(obj, qdict_out);
240
113
241
case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IOTINVAL_FUNC_GVMA,
114
/* Add our CPU boolean options too */
242
RISCV_IOMMU_CMD_IOTINVAL_OPCODE):
115
riscv_obj_add_qdict_prop(obj, qdict_out, "mmu");
243
- if (cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_PSCV) {
244
+ {
245
+ bool gv = !!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_GV);
246
+ bool av = !!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_AV);
247
+ bool pscv = !!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_PSCV);
248
+ uint32_t gscid = get_field(cmd.dword0,
249
+ RISCV_IOMMU_CMD_IOTINVAL_GSCID);
250
+ uint32_t pscid = get_field(cmd.dword0,
251
+ RISCV_IOMMU_CMD_IOTINVAL_PSCID);
252
+ hwaddr iova = (cmd.dword1 << 2) & TARGET_PAGE_MASK;
253
+
254
+ if (pscv) {
255
/* illegal command arguments IOTINVAL.GVMA & PSCV == 1 */
256
goto cmd_ill;
257
- } else if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_GV)) {
258
- /* invalidate all cache mappings */
259
- func = riscv_iommu_iot_inval_all;
260
- } else if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_AV)) {
261
- /* invalidate cache matching GSCID */
262
- func = riscv_iommu_iot_inval_gscid;
263
- } else {
264
- /* invalidate cache matching GSCID and ADDR (GPA) */
265
- func = riscv_iommu_iot_inval_gscid_gpa;
266
}
267
- riscv_iommu_iot_inval(s, func,
268
- get_field(cmd.dword0, RISCV_IOMMU_CMD_IOTINVAL_GSCID), 0,
269
- cmd.dword1 << 2 & TARGET_PAGE_MASK);
270
+
271
+ func = riscv_iommu_iot_inval_all;
272
+
273
+ if (gv) {
274
+ func = (av) ? riscv_iommu_iot_inval_gscid_iova :
275
+ riscv_iommu_iot_inval_gscid;
276
+ }
277
+
278
+ riscv_iommu_iot_inval(
279
+ s, func, gscid, pscid, iova, RISCV_IOMMU_TRANS_TAG_VG);
280
+
281
+ riscv_iommu_iot_inval(
282
+ s, func, gscid, pscid, iova, RISCV_IOMMU_TRANS_TAG_VN);
283
break;
284
+ }
285
286
case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IOTINVAL_FUNC_VMA,
287
RISCV_IOMMU_CMD_IOTINVAL_OPCODE):
288
- if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_GV)) {
289
- /* invalidate all cache mappings, simplified model */
290
- func = riscv_iommu_iot_inval_all;
291
- } else if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_PSCV)) {
292
- /* invalidate cache matching GSCID, simplified model */
293
- func = riscv_iommu_iot_inval_gscid;
294
- } else if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_AV)) {
295
- /* invalidate cache matching GSCID and PSCID */
296
- func = riscv_iommu_iot_inval_pscid;
297
+ {
298
+ bool gv = !!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_GV);
299
+ bool av = !!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_AV);
300
+ bool pscv = !!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_PSCV);
301
+ uint32_t gscid = get_field(cmd.dword0,
302
+ RISCV_IOMMU_CMD_IOTINVAL_GSCID);
303
+ uint32_t pscid = get_field(cmd.dword0,
304
+ RISCV_IOMMU_CMD_IOTINVAL_PSCID);
305
+ hwaddr iova = (cmd.dword1 << 2) & TARGET_PAGE_MASK;
306
+ RISCVIOMMUTransTag transtag;
307
+
308
+ if (gv) {
309
+ transtag = RISCV_IOMMU_TRANS_TAG_VN;
310
+ if (pscv) {
311
+ func = (av) ? riscv_iommu_iot_inval_gscid_pscid_iova :
312
+ riscv_iommu_iot_inval_gscid_pscid;
313
+ } else {
314
+ func = (av) ? riscv_iommu_iot_inval_gscid_iova :
315
+ riscv_iommu_iot_inval_gscid;
316
+ }
317
} else {
318
- /* invalidate cache matching GSCID and PSCID and ADDR (IOVA) */
319
- func = riscv_iommu_iot_inval_pscid_iova;
320
+ transtag = RISCV_IOMMU_TRANS_TAG_SS;
321
+ if (pscv) {
322
+ func = (av) ? riscv_iommu_iot_inval_pscid_iova :
323
+ riscv_iommu_iot_inval_pscid;
324
+ } else {
325
+ func = (av) ? riscv_iommu_iot_inval_iova :
326
+ riscv_iommu_iot_inval_all;
327
+ }
328
}
329
- riscv_iommu_iot_inval(s, func,
330
- get_field(cmd.dword0, RISCV_IOMMU_CMD_IOTINVAL_GSCID),
331
- get_field(cmd.dword0, RISCV_IOMMU_CMD_IOTINVAL_PSCID),
332
- cmd.dword1 << 2 & TARGET_PAGE_MASK);
333
+
334
+ riscv_iommu_iot_inval(s, func, gscid, pscid, iova, transtag);
335
break;
336
+ }
337
338
case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IODIR_FUNC_INVAL_DDT,
339
RISCV_IOMMU_CMD_IODIR_OPCODE):
116
--
340
--
117
2.43.0
341
2.48.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Alexey Baturo <baturo.alexey@gmail.com>
2
2
3
The rva22U64 profile, described in:
3
The Zjpm v1.0 spec states there should be Supm and Sspm extensions that
4
are used in profile specification. Enabling Supm extension enables both
5
Ssnpm and Smnpm, while Sspm enables only Smnpm.
4
6
5
https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#rva22-profiles
7
Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
6
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Contains a set of CPU extensions aimed for 64-bit userspace
9
Message-ID: <20250113194410.1307494-1-baturo.alexey@gmail.com>
8
applications. Enabling this set to be enabled via a single user flag
9
makes it convenient to enable a predictable set of features for the CPU,
10
giving users more predicability when running/testing their workloads.
11
12
QEMU implements all possible extensions of this profile. All the so
13
called 'synthetic extensions' described in the profile that are cache
14
related are ignored/assumed enabled (Za64rs, Zic64b, Ziccif, Ziccrse,
15
Ziccamoa, Zicclsm) since we do not implement a cache model.
16
17
An abstraction called RISCVCPUProfile is created to store the profile.
18
'ext_offsets' contains mandatory extensions that QEMU supports. Same
19
thing with the 'misa_ext' mask. Optional extensions must be enabled
20
manually in the command line if desired.
21
22
The design here is to use the common target/riscv/cpu.c file to store
23
the profile declaration and export it to the accelerator files. Each
24
accelerator is then responsible to expose it (or not) to users and how
25
to enable the extensions.
26
27
Next patches will implement the profile for TCG and KVM.
28
29
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
30
Acked-by: Alistair Francis <alistair.francis@wdc.com>
31
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
32
Message-ID: <20231218125334.37184-9-dbarboza@ventanamicro.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
---
11
---
35
target/riscv/cpu.h | 12 ++++++++++++
12
target/riscv/cpu_cfg.h | 2 ++
36
target/riscv/cpu.c | 32 ++++++++++++++++++++++++++++++++
13
target/riscv/cpu.c | 23 +++++++++++++++++++++++
37
2 files changed, 44 insertions(+)
14
2 files changed, 25 insertions(+)
38
15
39
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
16
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
40
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/cpu.h
18
--- a/target/riscv/cpu_cfg.h
42
+++ b/target/riscv/cpu.h
19
+++ b/target/riscv/cpu_cfg.h
43
@@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit);
20
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
44
21
bool ext_ssnpm;
45
#define CPU_CFG_OFFSET(_prop) offsetof(struct RISCVCPUConfig, _prop)
22
bool ext_smnpm;
46
23
bool ext_smmpm;
47
+typedef struct riscv_cpu_profile {
24
+ bool ext_sspm;
48
+ const char *name;
25
+ bool ext_supm;
49
+ uint32_t misa_ext;
26
bool rvv_ta_all_1s;
50
+ bool enabled;
27
bool rvv_ma_all_1s;
51
+ bool user_set;
28
bool rvv_vl_half_avl;
52
+ const int32_t ext_offsets[];
53
+} RISCVCPUProfile;
54
+
55
+#define RISCV_PROFILE_EXT_LIST_END -1
56
+
57
+extern RISCVCPUProfile *riscv_profiles[];
58
+
59
/* Privileged specification version */
60
enum {
61
PRIV_VERSION_1_10_0 = 0,
62
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
29
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
63
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
64
--- a/target/riscv/cpu.c
31
--- a/target/riscv/cpu.c
65
+++ b/target/riscv/cpu.c
32
+++ b/target/riscv/cpu.c
66
@@ -XXX,XX +XXX,XX @@ Property riscv_cpu_options[] = {
33
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
67
DEFINE_PROP_END_OF_LIST(),
34
ISA_EXT_DATA_ENTRY(sscsrind, PRIV_VERSION_1_12_0, ext_sscsrind),
35
ISA_EXT_DATA_ENTRY(ssdbltrp, PRIV_VERSION_1_13_0, ext_ssdbltrp),
36
ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm),
37
+ ISA_EXT_DATA_ENTRY(sspm, PRIV_VERSION_1_13_0, ext_sspm),
38
ISA_EXT_DATA_ENTRY(ssstateen, PRIV_VERSION_1_12_0, ext_ssstateen),
39
ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc),
40
ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12),
41
ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12),
42
+ ISA_EXT_DATA_ENTRY(supm, PRIV_VERSION_1_13_0, ext_supm),
43
ISA_EXT_DATA_ENTRY(svade, PRIV_VERSION_1_11_0, ext_svade),
44
ISA_EXT_DATA_ENTRY(svadu, PRIV_VERSION_1_12_0, ext_svadu),
45
ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval),
46
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
47
MULTI_EXT_CFG_BOOL("zvfhmin", ext_zvfhmin, false),
48
MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true),
49
MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false),
50
+ MULTI_EXT_CFG_BOOL("sspm", ext_sspm, false),
51
+ MULTI_EXT_CFG_BOOL("supm", ext_supm, false),
52
53
MULTI_EXT_CFG_BOOL("smaia", ext_smaia, false),
54
MULTI_EXT_CFG_BOOL("smdbltrp", ext_smdbltrp, false),
55
@@ -XXX,XX +XXX,XX @@ static RISCVCPUImpliedExtsRule SSCFG_IMPLIED = {
56
},
68
};
57
};
69
58
70
+/*
59
+static RISCVCPUImpliedExtsRule SUPM_IMPLIED = {
71
+ * RVA22U64 defines some 'named features' or 'synthetic extensions'
60
+ .ext = CPU_CFG_OFFSET(ext_supm),
72
+ * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
61
+ .implied_multi_exts = {
73
+ * and Zicclsm. We do not implement caching in QEMU so we'll consider
62
+ CPU_CFG_OFFSET(ext_ssnpm), CPU_CFG_OFFSET(ext_smnpm),
74
+ * all these named features as always enabled.
75
+ *
76
+ * There's no riscv,isa update for them (nor for zic64b, despite it
77
+ * having a cfg offset) at this moment.
78
+ */
79
+static RISCVCPUProfile RVA22U64 = {
80
+ .name = "rva22u64",
81
+ .misa_ext = RVI | RVM | RVA | RVF | RVD | RVC | RVU,
82
+ .ext_offsets = {
83
+ CPU_CFG_OFFSET(ext_zicsr), CPU_CFG_OFFSET(ext_zihintpause),
84
+ CPU_CFG_OFFSET(ext_zba), CPU_CFG_OFFSET(ext_zbb),
85
+ CPU_CFG_OFFSET(ext_zbs), CPU_CFG_OFFSET(ext_zfhmin),
86
+ CPU_CFG_OFFSET(ext_zkt), CPU_CFG_OFFSET(ext_zicntr),
87
+ CPU_CFG_OFFSET(ext_zihpm), CPU_CFG_OFFSET(ext_zicbom),
88
+ CPU_CFG_OFFSET(ext_zicbop), CPU_CFG_OFFSET(ext_zicboz),
89
+
63
+
90
+ /* mandatory named features for this profile */
64
+ RISCV_IMPLIED_EXTS_RULE_END
91
+ CPU_CFG_OFFSET(zic64b),
65
+ },
92
+
93
+ RISCV_PROFILE_EXT_LIST_END
94
+ }
95
+};
66
+};
96
+
67
+
97
+RISCVCPUProfile *riscv_profiles[] = {
68
+static RISCVCPUImpliedExtsRule SSPM_IMPLIED = {
98
+ &RVA22U64,
69
+ .ext = CPU_CFG_OFFSET(ext_sspm),
99
+ NULL,
70
+ .implied_multi_exts = {
71
+ CPU_CFG_OFFSET(ext_smnpm),
72
+
73
+ RISCV_IMPLIED_EXTS_RULE_END
74
+ },
100
+};
75
+};
101
+
76
+
102
static Property riscv_cpu_properties[] = {
77
RISCVCPUImpliedExtsRule *riscv_misa_ext_implied_rules[] = {
103
DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
78
&RVA_IMPLIED, &RVD_IMPLIED, &RVF_IMPLIED,
79
&RVM_IMPLIED, &RVV_IMPLIED, NULL
80
@@ -XXX,XX +XXX,XX @@ RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[] = {
81
&ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVKN_IMPLIED,
82
&ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED,
83
&ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED, &SSCFG_IMPLIED,
84
+ &SUPM_IMPLIED, &SSPM_IMPLIED,
85
NULL
86
};
104
87
105
--
88
--
106
2.43.0
89
2.48.1
diff view generated by jsdifflib
Deleted patch
1
From: Yong-Xuan Wang <yongxuan.wang@sifive.com>
2
1
3
The emulated AIA within the Linux kernel restores the HART index
4
of the IMSICs according to the configured AIA settings. During
5
this process, the group setting is used only when the machine
6
partitions harts into groups. It's unnecessary to set the group
7
configuration if the machine has only one socket, as its address
8
space might not contain the group shift.
9
10
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
11
Reviewed-by: Jim Shu <jim.shu@sifive.com>
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Message-ID: <20231218090543.22353-2-yongxuan.wang@sifive.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
16
target/riscv/kvm/kvm-cpu.c | 31 +++++++++++++++++--------------
17
1 file changed, 17 insertions(+), 14 deletions(-)
18
19
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/kvm/kvm-cpu.c
22
+++ b/target/riscv/kvm/kvm-cpu.c
23
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
24
exit(1);
25
}
26
27
- socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
28
- ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
29
- KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS,
30
- &socket_bits, true, NULL);
31
- if (ret < 0) {
32
- error_report("KVM AIA: failed to set group_bits");
33
- exit(1);
34
- }
35
36
- ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
37
- KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT,
38
- &group_shift, true, NULL);
39
- if (ret < 0) {
40
- error_report("KVM AIA: failed to set group_shift");
41
- exit(1);
42
+ if (socket_count > 1) {
43
+ socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
44
+ ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
45
+ KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS,
46
+ &socket_bits, true, NULL);
47
+ if (ret < 0) {
48
+ error_report("KVM AIA: failed to set group_bits");
49
+ exit(1);
50
+ }
51
+
52
+ ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
53
+ KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT,
54
+ &group_shift, true, NULL);
55
+ if (ret < 0) {
56
+ error_report("KVM AIA: failed to set group_shift");
57
+ exit(1);
58
+ }
59
}
60
61
guest_bits = guest_num == 0 ? 0 :
62
--
63
2.43.0
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
We'll add a new RISC-V linux-header file, but first let's update all
4
headers.
5
6
Headers for 'asm-loongarch' were added in this update.
7
8
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-ID: <20231218204321.75757-2-dbarboza@ventanamicro.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
include/standard-headers/drm/drm_fourcc.h | 2 +
14
include/standard-headers/linux/pci_regs.h | 24 ++-
15
include/standard-headers/linux/vhost_types.h | 7 +
16
.../standard-headers/linux/virtio_config.h | 5 +
17
include/standard-headers/linux/virtio_pci.h | 11 ++
18
linux-headers/asm-arm64/kvm.h | 32 ++++
19
linux-headers/asm-generic/unistd.h | 14 +-
20
linux-headers/asm-loongarch/bitsperlong.h | 1 +
21
linux-headers/asm-loongarch/kvm.h | 108 +++++++++++
22
linux-headers/asm-loongarch/mman.h | 1 +
23
linux-headers/asm-loongarch/unistd.h | 5 +
24
linux-headers/asm-mips/unistd_n32.h | 4 +
25
linux-headers/asm-mips/unistd_n64.h | 4 +
26
linux-headers/asm-mips/unistd_o32.h | 4 +
27
linux-headers/asm-powerpc/unistd_32.h | 4 +
28
linux-headers/asm-powerpc/unistd_64.h | 4 +
29
linux-headers/asm-riscv/kvm.h | 12 ++
30
linux-headers/asm-s390/unistd_32.h | 4 +
31
linux-headers/asm-s390/unistd_64.h | 4 +
32
linux-headers/asm-x86/unistd_32.h | 4 +
33
linux-headers/asm-x86/unistd_64.h | 3 +
34
linux-headers/asm-x86/unistd_x32.h | 3 +
35
linux-headers/linux/iommufd.h | 180 +++++++++++++++++-
36
linux-headers/linux/kvm.h | 11 ++
37
linux-headers/linux/psp-sev.h | 1 +
38
linux-headers/linux/stddef.h | 9 +-
39
linux-headers/linux/userfaultfd.h | 9 +-
40
linux-headers/linux/vfio.h | 47 +++--
41
linux-headers/linux/vhost.h | 8 +
42
29 files changed, 498 insertions(+), 27 deletions(-)
43
create mode 100644 linux-headers/asm-loongarch/bitsperlong.h
44
create mode 100644 linux-headers/asm-loongarch/kvm.h
45
create mode 100644 linux-headers/asm-loongarch/mman.h
46
create mode 100644 linux-headers/asm-loongarch/unistd.h
47
48
diff --git a/include/standard-headers/drm/drm_fourcc.h b/include/standard-headers/drm/drm_fourcc.h
49
index XXXXXXX..XXXXXXX 100644
50
--- a/include/standard-headers/drm/drm_fourcc.h
51
+++ b/include/standard-headers/drm/drm_fourcc.h
52
@@ -XXX,XX +XXX,XX @@ extern "C" {
53
* index 1 = Cr:Cb plane, [39:0] Cr1:Cb1:Cr0:Cb0 little endian
54
*/
55
#define DRM_FORMAT_NV15        fourcc_code('N', 'V', '1', '5') /* 2x2 subsampled Cr:Cb plane */
56
+#define DRM_FORMAT_NV20        fourcc_code('N', 'V', '2', '0') /* 2x1 subsampled Cr:Cb plane */
57
+#define DRM_FORMAT_NV30        fourcc_code('N', 'V', '3', '0') /* non-subsampled Cr:Cb plane */
58
59
/*
60
* 2 plane YCbCr MSB aligned
61
diff --git a/include/standard-headers/linux/pci_regs.h b/include/standard-headers/linux/pci_regs.h
62
index XXXXXXX..XXXXXXX 100644
63
--- a/include/standard-headers/linux/pci_regs.h
64
+++ b/include/standard-headers/linux/pci_regs.h
65
@@ -XXX,XX +XXX,XX @@
66
#define PCI_HEADER_TYPE_NORMAL        0
67
#define PCI_HEADER_TYPE_BRIDGE        1
68
#define PCI_HEADER_TYPE_CARDBUS    2
69
+#define PCI_HEADER_TYPE_MFD        0x80    /* Multi-Function Device (possible) */
70
71
#define PCI_BIST        0x0f    /* 8 bits */
72
#define PCI_BIST_CODE_MASK    0x0f    /* Return result */
73
@@ -XXX,XX +XXX,XX @@
74
#define PCI_EXP_RTCAP        0x1e    /* Root Capabilities */
75
#define PCI_EXP_RTCAP_CRSVIS    0x0001    /* CRS Software Visibility capability */
76
#define PCI_EXP_RTSTA        0x20    /* Root Status */
77
+#define PCI_EXP_RTSTA_PME_RQ_ID 0x0000ffff /* PME Requester ID */
78
#define PCI_EXP_RTSTA_PME    0x00010000 /* PME status */
79
#define PCI_EXP_RTSTA_PENDING    0x00020000 /* PME pending */
80
/*
81
@@ -XXX,XX +XXX,XX @@
82
83
/* Process Address Space ID */
84
#define PCI_PASID_CAP        0x04 /* PASID feature register */
85
-#define PCI_PASID_CAP_EXEC    0x02    /* Exec permissions Supported */
86
-#define PCI_PASID_CAP_PRIV    0x04    /* Privilege Mode Supported */
87
+#define PCI_PASID_CAP_EXEC    0x0002    /* Exec permissions Supported */
88
+#define PCI_PASID_CAP_PRIV    0x0004    /* Privilege Mode Supported */
89
+#define PCI_PASID_CAP_WIDTH    0x1f00
90
#define PCI_PASID_CTRL        0x06 /* PASID control register */
91
-#define PCI_PASID_CTRL_ENABLE    0x01    /* Enable bit */
92
-#define PCI_PASID_CTRL_EXEC    0x02    /* Exec permissions Enable */
93
-#define PCI_PASID_CTRL_PRIV    0x04    /* Privilege Mode Enable */
94
+#define PCI_PASID_CTRL_ENABLE    0x0001    /* Enable bit */
95
+#define PCI_PASID_CTRL_EXEC    0x0002    /* Exec permissions Enable */
96
+#define PCI_PASID_CTRL_PRIV    0x0004    /* Privilege Mode Enable */
97
#define PCI_EXT_CAP_PASID_SIZEOF    8
98
99
/* Single Root I/O Virtualization */
100
@@ -XXX,XX +XXX,XX @@
101
#define PCI_LTR_VALUE_MASK    0x000003ff
102
#define PCI_LTR_SCALE_MASK    0x00001c00
103
#define PCI_LTR_SCALE_SHIFT    10
104
+#define PCI_LTR_NOSNOOP_VALUE    0x03ff0000 /* Max No-Snoop Latency Value */
105
+#define PCI_LTR_NOSNOOP_SCALE    0x1c000000 /* Scale for Max Value */
106
#define PCI_EXT_CAP_LTR_SIZEOF    8
107
108
/* Access Control Service */
109
@@ -XXX,XX +XXX,XX @@
110
#define PCI_EXP_DPC_STATUS        0x08    /* DPC Status */
111
#define PCI_EXP_DPC_STATUS_TRIGGER     0x0001 /* Trigger Status */
112
#define PCI_EXP_DPC_STATUS_TRIGGER_RSN     0x0006 /* Trigger Reason */
113
+#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_UNCOR 0x0000 /* Uncorrectable error */
114
+#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_NFE 0x0002 /* Rcvd ERR_NONFATAL */
115
+#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_FE 0x0004 /* Rcvd ERR_FATAL */
116
+#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_IN_EXT 0x0006 /* Reason in Trig Reason Extension field */
117
#define PCI_EXP_DPC_STATUS_INTERRUPT     0x0008 /* Interrupt Status */
118
#define PCI_EXP_DPC_RP_BUSY         0x0010 /* Root Port Busy */
119
#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_EXT 0x0060 /* Trig Reason Extension */
120
+#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_RP_PIO        0x0000    /* RP PIO error */
121
+#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_SW_TRIGGER    0x0020    /* DPC SW Trigger bit */
122
+#define PCI_EXP_DPC_RP_PIO_FEP         0x1f00 /* RP PIO First Err Ptr */
123
124
#define PCI_EXP_DPC_SOURCE_ID         0x0A    /* DPC Source Identifier */
125
126
@@ -XXX,XX +XXX,XX @@
127
#define PCI_L1SS_CTL1_LTR_L12_TH_VALUE    0x03ff0000 /* LTR_L1.2_THRESHOLD_Value */
128
#define PCI_L1SS_CTL1_LTR_L12_TH_SCALE    0xe0000000 /* LTR_L1.2_THRESHOLD_Scale */
129
#define PCI_L1SS_CTL2        0x0c    /* Control 2 Register */
130
+#define PCI_L1SS_CTL2_T_PWR_ON_SCALE    0x00000003 /* T_POWER_ON Scale */
131
+#define PCI_L1SS_CTL2_T_PWR_ON_VALUE    0x000000f8 /* T_POWER_ON Value */
132
133
/* Designated Vendor-Specific (DVSEC, PCI_EXT_CAP_ID_DVSEC) */
134
#define PCI_DVSEC_HEADER1        0x4 /* Designated Vendor-Specific Header1 */
135
diff --git a/include/standard-headers/linux/vhost_types.h b/include/standard-headers/linux/vhost_types.h
136
index XXXXXXX..XXXXXXX 100644
137
--- a/include/standard-headers/linux/vhost_types.h
138
+++ b/include/standard-headers/linux/vhost_types.h
139
@@ -XXX,XX +XXX,XX @@ struct vhost_vdpa_iova_range {
140
* DRIVER_OK
141
*/
142
#define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6
143
+/* Device may expose the virtqueue's descriptor area, driver area and
144
+ * device area to a different group for ASID binding than where its
145
+ * buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID.
146
+ */
147
+#define VHOST_BACKEND_F_DESC_ASID 0x7
148
+/* IOTLB don't flush memory mapping across device reset */
149
+#define VHOST_BACKEND_F_IOTLB_PERSIST 0x8
150
151
#endif
152
diff --git a/include/standard-headers/linux/virtio_config.h b/include/standard-headers/linux/virtio_config.h
153
index XXXXXXX..XXXXXXX 100644
154
--- a/include/standard-headers/linux/virtio_config.h
155
+++ b/include/standard-headers/linux/virtio_config.h
156
@@ -XXX,XX +XXX,XX @@
157
*/
158
#define VIRTIO_F_NOTIFICATION_DATA    38
159
160
+/* This feature indicates that the driver uses the data provided by the device
161
+ * as a virtqueue identifier in available buffer notifications.
162
+ */
163
+#define VIRTIO_F_NOTIF_CONFIG_DATA    39
164
+
165
/*
166
* This feature indicates that the driver can reset a queue individually.
167
*/
168
diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard-headers/linux/virtio_pci.h
169
index XXXXXXX..XXXXXXX 100644
170
--- a/include/standard-headers/linux/virtio_pci.h
171
+++ b/include/standard-headers/linux/virtio_pci.h
172
@@ -XXX,XX +XXX,XX @@ struct virtio_pci_common_cfg {
173
    uint32_t queue_used_hi;        /* read-write */
174
};
175
176
+/*
177
+ * Warning: do not use sizeof on this: use offsetofend for
178
+ * specific fields you need.
179
+ */
180
+struct virtio_pci_modern_common_cfg {
181
+    struct virtio_pci_common_cfg cfg;
182
+
183
+    uint16_t queue_notify_data;    /* read-write */
184
+    uint16_t queue_reset;        /* read-write */
185
+};
186
+
187
/* Fields in VIRTIO_PCI_CAP_PCI_CFG: */
188
struct virtio_pci_cfg_cap {
189
    struct virtio_pci_cap cap;
190
diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h
191
index XXXXXXX..XXXXXXX 100644
192
--- a/linux-headers/asm-arm64/kvm.h
193
+++ b/linux-headers/asm-arm64/kvm.h
194
@@ -XXX,XX +XXX,XX @@ struct kvm_smccc_filter {
195
#define KVM_HYPERCALL_EXIT_SMC        (1U << 0)
196
#define KVM_HYPERCALL_EXIT_16BIT    (1U << 1)
197
198
+/*
199
+ * Get feature ID registers userspace writable mask.
200
+ *
201
+ * From DDI0487J.a, D19.2.66 ("ID_AA64MMFR2_EL1, AArch64 Memory Model
202
+ * Feature Register 2"):
203
+ *
204
+ * "The Feature ID space is defined as the System register space in
205
+ * AArch64 with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7},
206
+ * op2=={0-7}."
207
+ *
208
+ * This covers all currently known R/O registers that indicate
209
+ * anything useful feature wise, including the ID registers.
210
+ *
211
+ * If we ever need to introduce a new range, it will be described as
212
+ * such in the range field.
213
+ */
214
+#define KVM_ARM_FEATURE_ID_RANGE_IDX(op0, op1, crn, crm, op2)        \
215
+    ({                                \
216
+        __u64 __op1 = (op1) & 3;                \
217
+        __op1 -= (__op1 == 3);                    \
218
+        (__op1 << 6 | ((crm) & 7) << 3 | (op2));        \
219
+    })
220
+
221
+#define KVM_ARM_FEATURE_ID_RANGE    0
222
+#define KVM_ARM_FEATURE_ID_RANGE_SIZE    (3 * 8 * 8)
223
+
224
+struct reg_mask_range {
225
+    __u64 addr;        /* Pointer to mask array */
226
+    __u32 range;        /* Requested range */
227
+    __u32 reserved[13];
228
+};
229
+
230
#endif
231
232
#endif /* __ARM_KVM_H__ */
233
diff --git a/linux-headers/asm-generic/unistd.h b/linux-headers/asm-generic/unistd.h
234
index XXXXXXX..XXXXXXX 100644
235
--- a/linux-headers/asm-generic/unistd.h
236
+++ b/linux-headers/asm-generic/unistd.h
237
@@ -XXX,XX +XXX,XX @@ __SYSCALL(__NR_fremovexattr, sys_fremovexattr)
238
#define __NR_getcwd 17
239
__SYSCALL(__NR_getcwd, sys_getcwd)
240
#define __NR_lookup_dcookie 18
241
-__SC_COMP(__NR_lookup_dcookie, sys_lookup_dcookie, compat_sys_lookup_dcookie)
242
+__SYSCALL(__NR_lookup_dcookie, sys_ni_syscall)
243
#define __NR_eventfd2 19
244
__SYSCALL(__NR_eventfd2, sys_eventfd2)
245
#define __NR_epoll_create1 20
246
@@ -XXX,XX +XXX,XX @@ __SYSCALL(__NR_process_mrelease, sys_process_mrelease)
247
__SYSCALL(__NR_futex_waitv, sys_futex_waitv)
248
#define __NR_set_mempolicy_home_node 450
249
__SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
250
-
251
#define __NR_cachestat 451
252
__SYSCALL(__NR_cachestat, sys_cachestat)
253
-
254
#define __NR_fchmodat2 452
255
__SYSCALL(__NR_fchmodat2, sys_fchmodat2)
256
+#define __NR_map_shadow_stack 453
257
+__SYSCALL(__NR_map_shadow_stack, sys_map_shadow_stack)
258
+#define __NR_futex_wake 454
259
+__SYSCALL(__NR_futex_wake, sys_futex_wake)
260
+#define __NR_futex_wait 455
261
+__SYSCALL(__NR_futex_wait, sys_futex_wait)
262
+#define __NR_futex_requeue 456
263
+__SYSCALL(__NR_futex_requeue, sys_futex_requeue)
264
265
#undef __NR_syscalls
266
-#define __NR_syscalls 453
267
+#define __NR_syscalls 457
268
269
/*
270
* 32 bit systems traditionally used different
271
diff --git a/linux-headers/asm-loongarch/bitsperlong.h b/linux-headers/asm-loongarch/bitsperlong.h
272
new file mode 100644
273
index XXXXXXX..XXXXXXX
274
--- /dev/null
275
+++ b/linux-headers/asm-loongarch/bitsperlong.h
276
@@ -0,0 +1 @@
277
+#include <asm-generic/bitsperlong.h>
278
diff --git a/linux-headers/asm-loongarch/kvm.h b/linux-headers/asm-loongarch/kvm.h
279
new file mode 100644
280
index XXXXXXX..XXXXXXX
281
--- /dev/null
282
+++ b/linux-headers/asm-loongarch/kvm.h
283
@@ -XXX,XX +XXX,XX @@
284
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
285
+/*
286
+ * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
287
+ */
288
+
289
+#ifndef __UAPI_ASM_LOONGARCH_KVM_H
290
+#define __UAPI_ASM_LOONGARCH_KVM_H
291
+
292
+#include <linux/types.h>
293
+
294
+/*
295
+ * KVM LoongArch specific structures and definitions.
296
+ *
297
+ * Some parts derived from the x86 version of this file.
298
+ */
299
+
300
+#define __KVM_HAVE_READONLY_MEM
301
+
302
+#define KVM_COALESCED_MMIO_PAGE_OFFSET    1
303
+#define KVM_DIRTY_LOG_PAGE_OFFSET    64
304
+
305
+/*
306
+ * for KVM_GET_REGS and KVM_SET_REGS
307
+ */
308
+struct kvm_regs {
309
+    /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
310
+    __u64 gpr[32];
311
+    __u64 pc;
312
+};
313
+
314
+/*
315
+ * for KVM_GET_FPU and KVM_SET_FPU
316
+ */
317
+struct kvm_fpu {
318
+    __u32 fcsr;
319
+    __u64 fcc; /* 8x8 */
320
+    struct kvm_fpureg {
321
+        __u64 val64[4];
322
+    } fpr[32];
323
+};
324
+
325
+/*
326
+ * For LoongArch, we use KVM_SET_ONE_REG and KVM_GET_ONE_REG to access various
327
+ * registers. The id field is broken down as follows:
328
+ *
329
+ * bits[63..52] - As per linux/kvm.h
330
+ * bits[51..32] - Must be zero.
331
+ * bits[31..16] - Register set.
332
+ *
333
+ * Register set = 0: GP registers from kvm_regs (see definitions below).
334
+ *
335
+ * Register set = 1: CSR registers.
336
+ *
337
+ * Register set = 2: KVM specific registers (see definitions below).
338
+ *
339
+ * Register set = 3: FPU / SIMD registers (see definitions below).
340
+ *
341
+ * Other sets registers may be added in the future. Each set would
342
+ * have its own identifier in bits[31..16].
343
+ */
344
+
345
+#define KVM_REG_LOONGARCH_GPR        (KVM_REG_LOONGARCH | 0x00000ULL)
346
+#define KVM_REG_LOONGARCH_CSR        (KVM_REG_LOONGARCH | 0x10000ULL)
347
+#define KVM_REG_LOONGARCH_KVM        (KVM_REG_LOONGARCH | 0x20000ULL)
348
+#define KVM_REG_LOONGARCH_FPSIMD    (KVM_REG_LOONGARCH | 0x30000ULL)
349
+#define KVM_REG_LOONGARCH_CPUCFG    (KVM_REG_LOONGARCH | 0x40000ULL)
350
+#define KVM_REG_LOONGARCH_MASK        (KVM_REG_LOONGARCH | 0x70000ULL)
351
+#define KVM_CSR_IDX_MASK        0x7fff
352
+#define KVM_CPUCFG_IDX_MASK        0x7fff
353
+
354
+/*
355
+ * KVM_REG_LOONGARCH_KVM - KVM specific control registers.
356
+ */
357
+
358
+#define KVM_REG_LOONGARCH_COUNTER    (KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 1)
359
+#define KVM_REG_LOONGARCH_VCPU_RESET    (KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 2)
360
+
361
+#define LOONGARCH_REG_SHIFT        3
362
+#define LOONGARCH_REG_64(TYPE, REG)    (TYPE | KVM_REG_SIZE_U64 | (REG << LOONGARCH_REG_SHIFT))
363
+#define KVM_IOC_CSRID(REG)        LOONGARCH_REG_64(KVM_REG_LOONGARCH_CSR, REG)
364
+#define KVM_IOC_CPUCFG(REG)        LOONGARCH_REG_64(KVM_REG_LOONGARCH_CPUCFG, REG)
365
+
366
+struct kvm_debug_exit_arch {
367
+};
368
+
369
+/* for KVM_SET_GUEST_DEBUG */
370
+struct kvm_guest_debug_arch {
371
+};
372
+
373
+/* definition of registers in kvm_run */
374
+struct kvm_sync_regs {
375
+};
376
+
377
+/* dummy definition */
378
+struct kvm_sregs {
379
+};
380
+
381
+struct kvm_iocsr_entry {
382
+    __u32 addr;
383
+    __u32 pad;
384
+    __u64 data;
385
+};
386
+
387
+#define KVM_NR_IRQCHIPS        1
388
+#define KVM_IRQCHIP_NUM_PINS    64
389
+#define KVM_MAX_CORES        256
390
+
391
+#endif /* __UAPI_ASM_LOONGARCH_KVM_H */
392
diff --git a/linux-headers/asm-loongarch/mman.h b/linux-headers/asm-loongarch/mman.h
393
new file mode 100644
394
index XXXXXXX..XXXXXXX
395
--- /dev/null
396
+++ b/linux-headers/asm-loongarch/mman.h
397
@@ -0,0 +1 @@
398
+#include <asm-generic/mman.h>
399
diff --git a/linux-headers/asm-loongarch/unistd.h b/linux-headers/asm-loongarch/unistd.h
400
new file mode 100644
401
index XXXXXXX..XXXXXXX
402
--- /dev/null
403
+++ b/linux-headers/asm-loongarch/unistd.h
404
@@ -XXX,XX +XXX,XX @@
405
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
406
+#define __ARCH_WANT_SYS_CLONE
407
+#define __ARCH_WANT_SYS_CLONE3
408
+
409
+#include <asm-generic/unistd.h>
410
diff --git a/linux-headers/asm-mips/unistd_n32.h b/linux-headers/asm-mips/unistd_n32.h
411
index XXXXXXX..XXXXXXX 100644
412
--- a/linux-headers/asm-mips/unistd_n32.h
413
+++ b/linux-headers/asm-mips/unistd_n32.h
414
@@ -XXX,XX +XXX,XX @@
415
#define __NR_set_mempolicy_home_node (__NR_Linux + 450)
416
#define __NR_cachestat (__NR_Linux + 451)
417
#define __NR_fchmodat2 (__NR_Linux + 452)
418
+#define __NR_map_shadow_stack (__NR_Linux + 453)
419
+#define __NR_futex_wake (__NR_Linux + 454)
420
+#define __NR_futex_wait (__NR_Linux + 455)
421
+#define __NR_futex_requeue (__NR_Linux + 456)
422
423
#endif /* _ASM_UNISTD_N32_H */
424
diff --git a/linux-headers/asm-mips/unistd_n64.h b/linux-headers/asm-mips/unistd_n64.h
425
index XXXXXXX..XXXXXXX 100644
426
--- a/linux-headers/asm-mips/unistd_n64.h
427
+++ b/linux-headers/asm-mips/unistd_n64.h
428
@@ -XXX,XX +XXX,XX @@
429
#define __NR_set_mempolicy_home_node (__NR_Linux + 450)
430
#define __NR_cachestat (__NR_Linux + 451)
431
#define __NR_fchmodat2 (__NR_Linux + 452)
432
+#define __NR_map_shadow_stack (__NR_Linux + 453)
433
+#define __NR_futex_wake (__NR_Linux + 454)
434
+#define __NR_futex_wait (__NR_Linux + 455)
435
+#define __NR_futex_requeue (__NR_Linux + 456)
436
437
#endif /* _ASM_UNISTD_N64_H */
438
diff --git a/linux-headers/asm-mips/unistd_o32.h b/linux-headers/asm-mips/unistd_o32.h
439
index XXXXXXX..XXXXXXX 100644
440
--- a/linux-headers/asm-mips/unistd_o32.h
441
+++ b/linux-headers/asm-mips/unistd_o32.h
442
@@ -XXX,XX +XXX,XX @@
443
#define __NR_set_mempolicy_home_node (__NR_Linux + 450)
444
#define __NR_cachestat (__NR_Linux + 451)
445
#define __NR_fchmodat2 (__NR_Linux + 452)
446
+#define __NR_map_shadow_stack (__NR_Linux + 453)
447
+#define __NR_futex_wake (__NR_Linux + 454)
448
+#define __NR_futex_wait (__NR_Linux + 455)
449
+#define __NR_futex_requeue (__NR_Linux + 456)
450
451
#endif /* _ASM_UNISTD_O32_H */
452
diff --git a/linux-headers/asm-powerpc/unistd_32.h b/linux-headers/asm-powerpc/unistd_32.h
453
index XXXXXXX..XXXXXXX 100644
454
--- a/linux-headers/asm-powerpc/unistd_32.h
455
+++ b/linux-headers/asm-powerpc/unistd_32.h
456
@@ -XXX,XX +XXX,XX @@
457
#define __NR_set_mempolicy_home_node 450
458
#define __NR_cachestat 451
459
#define __NR_fchmodat2 452
460
+#define __NR_map_shadow_stack 453
461
+#define __NR_futex_wake 454
462
+#define __NR_futex_wait 455
463
+#define __NR_futex_requeue 456
464
465
466
#endif /* _ASM_UNISTD_32_H */
467
diff --git a/linux-headers/asm-powerpc/unistd_64.h b/linux-headers/asm-powerpc/unistd_64.h
468
index XXXXXXX..XXXXXXX 100644
469
--- a/linux-headers/asm-powerpc/unistd_64.h
470
+++ b/linux-headers/asm-powerpc/unistd_64.h
471
@@ -XXX,XX +XXX,XX @@
472
#define __NR_set_mempolicy_home_node 450
473
#define __NR_cachestat 451
474
#define __NR_fchmodat2 452
475
+#define __NR_map_shadow_stack 453
476
+#define __NR_futex_wake 454
477
+#define __NR_futex_wait 455
478
+#define __NR_futex_requeue 456
479
480
481
#endif /* _ASM_UNISTD_64_H */
482
diff --git a/linux-headers/asm-riscv/kvm.h b/linux-headers/asm-riscv/kvm.h
483
index XXXXXXX..XXXXXXX 100644
484
--- a/linux-headers/asm-riscv/kvm.h
485
+++ b/linux-headers/asm-riscv/kvm.h
486
@@ -XXX,XX +XXX,XX @@ struct kvm_riscv_csr {
487
    unsigned long sip;
488
    unsigned long satp;
489
    unsigned long scounteren;
490
+    unsigned long senvcfg;
491
};
492
493
/* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
494
@@ -XXX,XX +XXX,XX @@ struct kvm_riscv_aia_csr {
495
    unsigned long iprio2h;
496
};
497
498
+/* Smstateen CSR for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
499
+struct kvm_riscv_smstateen_csr {
500
+    unsigned long sstateen0;
501
+};
502
+
503
/* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
504
struct kvm_riscv_timer {
505
    __u64 frequency;
506
@@ -XXX,XX +XXX,XX @@ enum KVM_RISCV_ISA_EXT_ID {
507
    KVM_RISCV_ISA_EXT_ZICSR,
508
    KVM_RISCV_ISA_EXT_ZIFENCEI,
509
    KVM_RISCV_ISA_EXT_ZIHPM,
510
+    KVM_RISCV_ISA_EXT_SMSTATEEN,
511
+    KVM_RISCV_ISA_EXT_ZICOND,
512
    KVM_RISCV_ISA_EXT_MAX,
513
};
514
515
@@ -XXX,XX +XXX,XX @@ enum KVM_RISCV_SBI_EXT_ID {
516
    KVM_RISCV_SBI_EXT_PMU,
517
    KVM_RISCV_SBI_EXT_EXPERIMENTAL,
518
    KVM_RISCV_SBI_EXT_VENDOR,
519
+    KVM_RISCV_SBI_EXT_DBCN,
520
    KVM_RISCV_SBI_EXT_MAX,
521
};
522
523
@@ -XXX,XX +XXX,XX @@ enum KVM_RISCV_SBI_EXT_ID {
524
#define KVM_REG_RISCV_CSR        (0x03 << KVM_REG_RISCV_TYPE_SHIFT)
525
#define KVM_REG_RISCV_CSR_GENERAL    (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
526
#define KVM_REG_RISCV_CSR_AIA        (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
527
+#define KVM_REG_RISCV_CSR_SMSTATEEN    (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
528
#define KVM_REG_RISCV_CSR_REG(name)    \
529
        (offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long))
530
#define KVM_REG_RISCV_CSR_AIA_REG(name)    \
531
    (offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long))
532
+#define KVM_REG_RISCV_CSR_SMSTATEEN_REG(name) \
533
+    (offsetof(struct kvm_riscv_smstateen_csr, name) / sizeof(unsigned long))
534
535
/* Timer registers are mapped as type 4 */
536
#define KVM_REG_RISCV_TIMER        (0x04 << KVM_REG_RISCV_TYPE_SHIFT)
537
diff --git a/linux-headers/asm-s390/unistd_32.h b/linux-headers/asm-s390/unistd_32.h
538
index XXXXXXX..XXXXXXX 100644
539
--- a/linux-headers/asm-s390/unistd_32.h
540
+++ b/linux-headers/asm-s390/unistd_32.h
541
@@ -XXX,XX +XXX,XX @@
542
#define __NR_set_mempolicy_home_node 450
543
#define __NR_cachestat 451
544
#define __NR_fchmodat2 452
545
+#define __NR_map_shadow_stack 453
546
+#define __NR_futex_wake 454
547
+#define __NR_futex_wait 455
548
+#define __NR_futex_requeue 456
549
550
#endif /* _ASM_S390_UNISTD_32_H */
551
diff --git a/linux-headers/asm-s390/unistd_64.h b/linux-headers/asm-s390/unistd_64.h
552
index XXXXXXX..XXXXXXX 100644
553
--- a/linux-headers/asm-s390/unistd_64.h
554
+++ b/linux-headers/asm-s390/unistd_64.h
555
@@ -XXX,XX +XXX,XX @@
556
#define __NR_set_mempolicy_home_node 450
557
#define __NR_cachestat 451
558
#define __NR_fchmodat2 452
559
+#define __NR_map_shadow_stack 453
560
+#define __NR_futex_wake 454
561
+#define __NR_futex_wait 455
562
+#define __NR_futex_requeue 456
563
564
#endif /* _ASM_S390_UNISTD_64_H */
565
diff --git a/linux-headers/asm-x86/unistd_32.h b/linux-headers/asm-x86/unistd_32.h
566
index XXXXXXX..XXXXXXX 100644
567
--- a/linux-headers/asm-x86/unistd_32.h
568
+++ b/linux-headers/asm-x86/unistd_32.h
569
@@ -XXX,XX +XXX,XX @@
570
#define __NR_set_mempolicy_home_node 450
571
#define __NR_cachestat 451
572
#define __NR_fchmodat2 452
573
+#define __NR_map_shadow_stack 453
574
+#define __NR_futex_wake 454
575
+#define __NR_futex_wait 455
576
+#define __NR_futex_requeue 456
577
578
579
#endif /* _ASM_UNISTD_32_H */
580
diff --git a/linux-headers/asm-x86/unistd_64.h b/linux-headers/asm-x86/unistd_64.h
581
index XXXXXXX..XXXXXXX 100644
582
--- a/linux-headers/asm-x86/unistd_64.h
583
+++ b/linux-headers/asm-x86/unistd_64.h
584
@@ -XXX,XX +XXX,XX @@
585
#define __NR_cachestat 451
586
#define __NR_fchmodat2 452
587
#define __NR_map_shadow_stack 453
588
+#define __NR_futex_wake 454
589
+#define __NR_futex_wait 455
590
+#define __NR_futex_requeue 456
591
592
593
#endif /* _ASM_UNISTD_64_H */
594
diff --git a/linux-headers/asm-x86/unistd_x32.h b/linux-headers/asm-x86/unistd_x32.h
595
index XXXXXXX..XXXXXXX 100644
596
--- a/linux-headers/asm-x86/unistd_x32.h
597
+++ b/linux-headers/asm-x86/unistd_x32.h
598
@@ -XXX,XX +XXX,XX @@
599
#define __NR_set_mempolicy_home_node (__X32_SYSCALL_BIT + 450)
600
#define __NR_cachestat (__X32_SYSCALL_BIT + 451)
601
#define __NR_fchmodat2 (__X32_SYSCALL_BIT + 452)
602
+#define __NR_futex_wake (__X32_SYSCALL_BIT + 454)
603
+#define __NR_futex_wait (__X32_SYSCALL_BIT + 455)
604
+#define __NR_futex_requeue (__X32_SYSCALL_BIT + 456)
605
#define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
606
#define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
607
#define __NR_ioctl (__X32_SYSCALL_BIT + 514)
608
diff --git a/linux-headers/linux/iommufd.h b/linux-headers/linux/iommufd.h
609
index XXXXXXX..XXXXXXX 100644
610
--- a/linux-headers/linux/iommufd.h
611
+++ b/linux-headers/linux/iommufd.h
612
@@ -XXX,XX +XXX,XX @@ enum {
613
    IOMMUFD_CMD_VFIO_IOAS,
614
    IOMMUFD_CMD_HWPT_ALLOC,
615
    IOMMUFD_CMD_GET_HW_INFO,
616
+    IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING,
617
+    IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP,
618
};
619
620
/**
621
@@ -XXX,XX +XXX,XX @@ struct iommu_vfio_ioas {
622
};
623
#define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS)
624
625
+/**
626
+ * enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation
627
+ * @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a HWPT that can serve as
628
+ * the parent HWPT in a nesting configuration.
629
+ * @IOMMU_HWPT_ALLOC_DIRTY_TRACKING: Dirty tracking support for device IOMMU is
630
+ * enforced on device attachment
631
+ */
632
+enum iommufd_hwpt_alloc_flags {
633
+    IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0,
634
+    IOMMU_HWPT_ALLOC_DIRTY_TRACKING = 1 << 1,
635
+};
636
+
637
+/**
638
+ * enum iommu_hwpt_vtd_s1_flags - Intel VT-d stage-1 page table
639
+ * entry attributes
640
+ * @IOMMU_VTD_S1_SRE: Supervisor request
641
+ * @IOMMU_VTD_S1_EAFE: Extended access enable
642
+ * @IOMMU_VTD_S1_WPE: Write protect enable
643
+ */
644
+enum iommu_hwpt_vtd_s1_flags {
645
+    IOMMU_VTD_S1_SRE = 1 << 0,
646
+    IOMMU_VTD_S1_EAFE = 1 << 1,
647
+    IOMMU_VTD_S1_WPE = 1 << 2,
648
+};
649
+
650
+/**
651
+ * struct iommu_hwpt_vtd_s1 - Intel VT-d stage-1 page table
652
+ * info (IOMMU_HWPT_DATA_VTD_S1)
653
+ * @flags: Combination of enum iommu_hwpt_vtd_s1_flags
654
+ * @pgtbl_addr: The base address of the stage-1 page table.
655
+ * @addr_width: The address width of the stage-1 page table
656
+ * @__reserved: Must be 0
657
+ */
658
+struct iommu_hwpt_vtd_s1 {
659
+    __aligned_u64 flags;
660
+    __aligned_u64 pgtbl_addr;
661
+    __u32 addr_width;
662
+    __u32 __reserved;
663
+};
664
+
665
+/**
666
+ * enum iommu_hwpt_data_type - IOMMU HWPT Data Type
667
+ * @IOMMU_HWPT_DATA_NONE: no data
668
+ * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table
669
+ */
670
+enum iommu_hwpt_data_type {
671
+    IOMMU_HWPT_DATA_NONE,
672
+    IOMMU_HWPT_DATA_VTD_S1,
673
+};
674
+
675
/**
676
* struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC)
677
* @size: sizeof(struct iommu_hwpt_alloc)
678
- * @flags: Must be 0
679
+ * @flags: Combination of enum iommufd_hwpt_alloc_flags
680
* @dev_id: The device to allocate this HWPT for
681
- * @pt_id: The IOAS to connect this HWPT to
682
+ * @pt_id: The IOAS or HWPT to connect this HWPT to
683
* @out_hwpt_id: The ID of the new HWPT
684
* @__reserved: Must be 0
685
+ * @data_type: One of enum iommu_hwpt_data_type
686
+ * @data_len: Length of the type specific data
687
+ * @data_uptr: User pointer to the type specific data
688
*
689
* Explicitly allocate a hardware page table object. This is the same object
690
* type that is returned by iommufd_device_attach() and represents the
691
* underlying iommu driver's iommu_domain kernel object.
692
*
693
- * A HWPT will be created with the IOVA mappings from the given IOAS.
694
+ * A kernel-managed HWPT will be created with the mappings from the given
695
+ * IOAS via the @pt_id. The @data_type for this allocation must be set to
696
+ * IOMMU_HWPT_DATA_NONE. The HWPT can be allocated as a parent HWPT for a
697
+ * nesting configuration by passing IOMMU_HWPT_ALLOC_NEST_PARENT via @flags.
698
+ *
699
+ * A user-managed nested HWPT will be created from a given parent HWPT via
700
+ * @pt_id, in which the parent HWPT must be allocated previously via the
701
+ * same ioctl from a given IOAS (@pt_id). In this case, the @data_type
702
+ * must be set to a pre-defined type corresponding to an I/O page table
703
+ * type supported by the underlying IOMMU hardware.
704
+ *
705
+ * If the @data_type is set to IOMMU_HWPT_DATA_NONE, @data_len and
706
+ * @data_uptr should be zero. Otherwise, both @data_len and @data_uptr
707
+ * must be given.
708
*/
709
struct iommu_hwpt_alloc {
710
    __u32 size;
711
@@ -XXX,XX +XXX,XX @@ struct iommu_hwpt_alloc {
712
    __u32 pt_id;
713
    __u32 out_hwpt_id;
714
    __u32 __reserved;
715
+    __u32 data_type;
716
+    __u32 data_len;
717
+    __aligned_u64 data_uptr;
718
};
719
#define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC)
720
721
+/**
722
+ * enum iommu_hw_info_vtd_flags - Flags for VT-d hw_info
723
+ * @IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17: If set, disallow read-only mappings
724
+ * on a nested_parent domain.
725
+ * https://www.intel.com/content/www/us/en/content-details/772415/content-details.html
726
+ */
727
+enum iommu_hw_info_vtd_flags {
728
+    IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17 = 1 << 0,
729
+};
730
+
731
/**
732
* struct iommu_hw_info_vtd - Intel VT-d hardware information
733
*
734
- * @flags: Must be 0
735
+ * @flags: Combination of enum iommu_hw_info_vtd_flags
736
* @__reserved: Must be 0
737
*
738
* @cap_reg: Value of Intel VT-d capability register defined in VT-d spec
739
@@ -XXX,XX +XXX,XX @@ enum iommu_hw_info_type {
740
    IOMMU_HW_INFO_TYPE_INTEL_VTD,
741
};
742
743
+/**
744
+ * enum iommufd_hw_capabilities
745
+ * @IOMMU_HW_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking
746
+ * If available, it means the following APIs
747
+ * are supported:
748
+ *
749
+ * IOMMU_HWPT_GET_DIRTY_BITMAP
750
+ * IOMMU_HWPT_SET_DIRTY_TRACKING
751
+ *
752
+ */
753
+enum iommufd_hw_capabilities {
754
+    IOMMU_HW_CAP_DIRTY_TRACKING = 1 << 0,
755
+};
756
+
757
/**
758
* struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO)
759
* @size: sizeof(struct iommu_hw_info)
760
@@ -XXX,XX +XXX,XX @@ enum iommu_hw_info_type {
761
* the iommu type specific hardware information data
762
* @out_data_type: Output the iommu hardware info type as defined in the enum
763
* iommu_hw_info_type.
764
+ * @out_capabilities: Output the generic iommu capability info type as defined
765
+ * in the enum iommu_hw_capabilities.
766
* @__reserved: Must be 0
767
*
768
* Query an iommu type specific hardware information data from an iommu behind
769
@@ -XXX,XX +XXX,XX @@ struct iommu_hw_info {
770
    __aligned_u64 data_uptr;
771
    __u32 out_data_type;
772
    __u32 __reserved;
773
+    __aligned_u64 out_capabilities;
774
};
775
#define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO)
776
+
777
+/*
778
+ * enum iommufd_hwpt_set_dirty_tracking_flags - Flags for steering dirty
779
+ * tracking
780
+ * @IOMMU_HWPT_DIRTY_TRACKING_ENABLE: Enable dirty tracking
781
+ */
782
+enum iommufd_hwpt_set_dirty_tracking_flags {
783
+    IOMMU_HWPT_DIRTY_TRACKING_ENABLE = 1,
784
+};
785
+
786
+/**
787
+ * struct iommu_hwpt_set_dirty_tracking - ioctl(IOMMU_HWPT_SET_DIRTY_TRACKING)
788
+ * @size: sizeof(struct iommu_hwpt_set_dirty_tracking)
789
+ * @flags: Combination of enum iommufd_hwpt_set_dirty_tracking_flags
790
+ * @hwpt_id: HW pagetable ID that represents the IOMMU domain
791
+ * @__reserved: Must be 0
792
+ *
793
+ * Toggle dirty tracking on an HW pagetable.
794
+ */
795
+struct iommu_hwpt_set_dirty_tracking {
796
+    __u32 size;
797
+    __u32 flags;
798
+    __u32 hwpt_id;
799
+    __u32 __reserved;
800
+};
801
+#define IOMMU_HWPT_SET_DIRTY_TRACKING _IO(IOMMUFD_TYPE, \
802
+                     IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING)
803
+
804
+/**
805
+ * enum iommufd_hwpt_get_dirty_bitmap_flags - Flags for getting dirty bits
806
+ * @IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR: Just read the PTEs without clearing
807
+ * any dirty bits metadata. This flag
808
+ * can be passed in the expectation
809
+ * where the next operation is an unmap
810
+ * of the same IOVA range.
811
+ *
812
+ */
813
+enum iommufd_hwpt_get_dirty_bitmap_flags {
814
+    IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR = 1,
815
+};
816
+
817
+/**
818
+ * struct iommu_hwpt_get_dirty_bitmap - ioctl(IOMMU_HWPT_GET_DIRTY_BITMAP)
819
+ * @size: sizeof(struct iommu_hwpt_get_dirty_bitmap)
820
+ * @hwpt_id: HW pagetable ID that represents the IOMMU domain
821
+ * @flags: Combination of enum iommufd_hwpt_get_dirty_bitmap_flags
822
+ * @__reserved: Must be 0
823
+ * @iova: base IOVA of the bitmap first bit
824
+ * @length: IOVA range size
825
+ * @page_size: page size granularity of each bit in the bitmap
826
+ * @data: bitmap where to set the dirty bits. The bitmap bits each
827
+ * represent a page_size which you deviate from an arbitrary iova.
828
+ *
829
+ * Checking a given IOVA is dirty:
830
+ *
831
+ * data[(iova / page_size) / 64] & (1ULL << ((iova / page_size) % 64))
832
+ *
833
+ * Walk the IOMMU pagetables for a given IOVA range to return a bitmap
834
+ * with the dirty IOVAs. In doing so it will also by default clear any
835
+ * dirty bit metadata set in the IOPTE.
836
+ */
837
+struct iommu_hwpt_get_dirty_bitmap {
838
+    __u32 size;
839
+    __u32 hwpt_id;
840
+    __u32 flags;
841
+    __u32 __reserved;
842
+    __aligned_u64 iova;
843
+    __aligned_u64 length;
844
+    __aligned_u64 page_size;
845
+    __aligned_u64 data;
846
+};
847
+#define IOMMU_HWPT_GET_DIRTY_BITMAP _IO(IOMMUFD_TYPE, \
848
+                    IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP)
849
+
850
#endif
851
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
852
index XXXXXXX..XXXXXXX 100644
853
--- a/linux-headers/linux/kvm.h
854
+++ b/linux-headers/linux/kvm.h
855
@@ -XXX,XX +XXX,XX @@ struct kvm_xen_exit {
856
#define KVM_EXIT_RISCV_SBI 35
857
#define KVM_EXIT_RISCV_CSR 36
858
#define KVM_EXIT_NOTIFY 37
859
+#define KVM_EXIT_LOONGARCH_IOCSR 38
860
861
/* For KVM_EXIT_INTERNAL_ERROR */
862
/* Emulate instruction failed. */
863
@@ -XXX,XX +XXX,XX @@ struct kvm_run {
864
            __u32 len;
865
            __u8 is_write;
866
        } mmio;
867
+        /* KVM_EXIT_LOONGARCH_IOCSR */
868
+        struct {
869
+            __u64 phys_addr;
870
+            __u8 data[8];
871
+            __u32 len;
872
+            __u8 is_write;
873
+        } iocsr_io;
874
        /* KVM_EXIT_HYPERCALL */
875
        struct {
876
            __u64 nr;
877
@@ -XXX,XX +XXX,XX @@ struct kvm_ppc_resize_hpt {
878
#define KVM_CAP_COUNTER_OFFSET 227
879
#define KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE 228
880
#define KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES 229
881
+#define KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES 230
882
883
#ifdef KVM_CAP_IRQ_ROUTING
884
885
@@ -XXX,XX +XXX,XX @@ struct kvm_dirty_tlb {
886
#define KVM_REG_ARM64        0x6000000000000000ULL
887
#define KVM_REG_MIPS        0x7000000000000000ULL
888
#define KVM_REG_RISCV        0x8000000000000000ULL
889
+#define KVM_REG_LOONGARCH    0x9000000000000000ULL
890
891
#define KVM_REG_SIZE_SHIFT    52
892
#define KVM_REG_SIZE_MASK    0x00f0000000000000ULL
893
@@ -XXX,XX +XXX,XX @@ struct kvm_s390_ucas_mapping {
894
#define KVM_ARM_MTE_COPY_TAGS     _IOR(KVMIO, 0xb4, struct kvm_arm_copy_mte_tags)
895
/* Available with KVM_CAP_COUNTER_OFFSET */
896
#define KVM_ARM_SET_COUNTER_OFFSET _IOW(KVMIO, 0xb5, struct kvm_arm_counter_offset)
897
+#define KVM_ARM_GET_REG_WRITABLE_MASKS _IOR(KVMIO, 0xb6, struct reg_mask_range)
898
899
/* ioctl for vm fd */
900
#define KVM_CREATE_DEVICE     _IOWR(KVMIO, 0xe0, struct kvm_create_device)
901
diff --git a/linux-headers/linux/psp-sev.h b/linux-headers/linux/psp-sev.h
902
index XXXXXXX..XXXXXXX 100644
903
--- a/linux-headers/linux/psp-sev.h
904
+++ b/linux-headers/linux/psp-sev.h
905
@@ -XXX,XX +XXX,XX @@ typedef enum {
906
    SEV_RET_INVALID_PARAM,
907
    SEV_RET_RESOURCE_LIMIT,
908
    SEV_RET_SECURE_DATA_INVALID,
909
+    SEV_RET_INVALID_KEY = 0x27,
910
    SEV_RET_MAX,
911
} sev_ret_code;
912
913
diff --git a/linux-headers/linux/stddef.h b/linux-headers/linux/stddef.h
914
index XXXXXXX..XXXXXXX 100644
915
--- a/linux-headers/linux/stddef.h
916
+++ b/linux-headers/linux/stddef.h
917
@@ -XXX,XX +XXX,XX @@
918
    union { \
919
        struct { MEMBERS } ATTRS; \
920
        struct TAG { MEMBERS } ATTRS NAME; \
921
-    }
922
+    } ATTRS
923
924
+#ifdef __cplusplus
925
+/* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */
926
+#define __DECLARE_FLEX_ARRAY(T, member)    \
927
+    T member[0]
928
+#else
929
/**
930
* __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
931
*
932
@@ -XXX,XX +XXX,XX @@
933
#ifndef __counted_by
934
#define __counted_by(m)
935
#endif
936
+
937
+#endif /* _LINUX_STDDEF_H */
938
diff --git a/linux-headers/linux/userfaultfd.h b/linux-headers/linux/userfaultfd.h
939
index XXXXXXX..XXXXXXX 100644
940
--- a/linux-headers/linux/userfaultfd.h
941
+++ b/linux-headers/linux/userfaultfd.h
942
@@ -XXX,XX +XXX,XX @@
943
             UFFD_FEATURE_EXACT_ADDRESS |        \
944
             UFFD_FEATURE_WP_HUGETLBFS_SHMEM |    \
945
             UFFD_FEATURE_WP_UNPOPULATED |    \
946
-             UFFD_FEATURE_POISON)
947
+             UFFD_FEATURE_POISON |        \
948
+             UFFD_FEATURE_WP_ASYNC)
949
#define UFFD_API_IOCTLS                \
950
    ((__u64)1 << _UFFDIO_REGISTER |        \
951
     (__u64)1 << _UFFDIO_UNREGISTER |    \
952
@@ -XXX,XX +XXX,XX @@ struct uffdio_api {
953
     * (i.e. empty ptes). This will be the default behavior for shmem
954
     * & hugetlbfs, so this flag only affects anonymous memory behavior
955
     * when userfault write-protection mode is registered.
956
+     *
957
+     * UFFD_FEATURE_WP_ASYNC indicates that userfaultfd write-protection
958
+     * asynchronous mode is supported in which the write fault is
959
+     * automatically resolved and write-protection is un-set.
960
+     * It implies UFFD_FEATURE_WP_UNPOPULATED.
961
     */
962
#define UFFD_FEATURE_PAGEFAULT_FLAG_WP        (1<<0)
963
#define UFFD_FEATURE_EVENT_FORK            (1<<1)
964
@@ -XXX,XX +XXX,XX @@ struct uffdio_api {
965
#define UFFD_FEATURE_WP_HUGETLBFS_SHMEM        (1<<12)
966
#define UFFD_FEATURE_WP_UNPOPULATED        (1<<13)
967
#define UFFD_FEATURE_POISON            (1<<14)
968
+#define UFFD_FEATURE_WP_ASYNC            (1<<15)
969
    __u64 features;
970
971
    __u64 ioctls;
972
diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
973
index XXXXXXX..XXXXXXX 100644
974
--- a/linux-headers/linux/vfio.h
975
+++ b/linux-headers/linux/vfio.h
976
@@ -XXX,XX +XXX,XX @@ struct vfio_region_info {
977
#define VFIO_REGION_INFO_FLAG_CAPS    (1 << 3) /* Info supports caps */
978
    __u32    index;        /* Region index */
979
    __u32    cap_offset;    /* Offset within info struct of first cap */
980
-    __u64    size;        /* Region size (bytes) */
981
-    __u64    offset;        /* Region offset from start of device fd */
982
+    __aligned_u64    size;    /* Region size (bytes) */
983
+    __aligned_u64    offset;    /* Region offset from start of device fd */
984
};
985
#define VFIO_DEVICE_GET_REGION_INFO    _IO(VFIO_TYPE, VFIO_BASE + 8)
986
987
@@ -XXX,XX +XXX,XX @@ struct vfio_region_info {
988
#define VFIO_REGION_INFO_CAP_SPARSE_MMAP    1
989
990
struct vfio_region_sparse_mmap_area {
991
-    __u64    offset;    /* Offset of mmap'able area within region */
992
-    __u64    size;    /* Size of mmap'able area */
993
+    __aligned_u64    offset;    /* Offset of mmap'able area within region */
994
+    __aligned_u64    size;    /* Size of mmap'able area */
995
};
996
997
struct vfio_region_info_cap_sparse_mmap {
998
@@ -XXX,XX +XXX,XX @@ struct vfio_device_migration_info {
999
                     VFIO_DEVICE_STATE_V1_RESUMING)
1000
1001
    __u32 reserved;
1002
-    __u64 pending_bytes;
1003
-    __u64 data_offset;
1004
-    __u64 data_size;
1005
+    __aligned_u64 pending_bytes;
1006
+    __aligned_u64 data_offset;
1007
+    __aligned_u64 data_size;
1008
};
1009
1010
/*
1011
@@ -XXX,XX +XXX,XX @@ struct vfio_device_migration_info {
1012
1013
struct vfio_region_info_cap_nvlink2_ssatgt {
1014
    struct vfio_info_cap_header header;
1015
-    __u64 tgt;
1016
+    __aligned_u64 tgt;
1017
};
1018
1019
/*
1020
@@ -XXX,XX +XXX,XX @@ struct vfio_device_gfx_plane_info {
1021
    __u32 drm_plane_type;    /* type of plane: DRM_PLANE_TYPE_* */
1022
    /* out */
1023
    __u32 drm_format;    /* drm format of plane */
1024
-    __u64 drm_format_mod; /* tiled mode */
1025
+    __aligned_u64 drm_format_mod; /* tiled mode */
1026
    __u32 width;    /* width of plane */
1027
    __u32 height;    /* height of plane */
1028
    __u32 stride;    /* stride of plane */
1029
@@ -XXX,XX +XXX,XX @@ struct vfio_device_gfx_plane_info {
1030
        __u32 region_index;    /* region index */
1031
        __u32 dmabuf_id;    /* dma-buf id */
1032
    };
1033
+    __u32 reserved;
1034
};
1035
1036
#define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14)
1037
@@ -XXX,XX +XXX,XX @@ struct vfio_device_ioeventfd {
1038
#define VFIO_DEVICE_IOEVENTFD_32    (1 << 2) /* 4-byte write */
1039
#define VFIO_DEVICE_IOEVENTFD_64    (1 << 3) /* 8-byte write */
1040
#define VFIO_DEVICE_IOEVENTFD_SIZE_MASK    (0xf)
1041
-    __u64    offset;            /* device fd offset of write */
1042
-    __u64    data;            /* data to be written */
1043
+    __aligned_u64    offset;        /* device fd offset of write */
1044
+    __aligned_u64    data;        /* data to be written */
1045
    __s32    fd;            /* -1 for de-assignment */
1046
+    __u32    reserved;
1047
};
1048
1049
#define VFIO_DEVICE_IOEVENTFD        _IO(VFIO_TYPE, VFIO_BASE + 16)
1050
@@ -XXX,XX +XXX,XX @@ struct vfio_device_feature_mig_data_size {
1051
1052
#define VFIO_DEVICE_FEATURE_MIG_DATA_SIZE 9
1053
1054
+/**
1055
+ * Upon VFIO_DEVICE_FEATURE_SET, set or clear the BUS mastering for the device
1056
+ * based on the operation specified in op flag.
1057
+ *
1058
+ * The functionality is incorporated for devices that needs bus master control,
1059
+ * but the in-band device interface lacks the support. Consequently, it is not
1060
+ * applicable to PCI devices, as bus master control for PCI devices is managed
1061
+ * in-band through the configuration space. At present, this feature is supported
1062
+ * only for CDX devices.
1063
+ * When the device's BUS MASTER setting is configured as CLEAR, it will result in
1064
+ * blocking all incoming DMA requests from the device. On the other hand, configuring
1065
+ * the device's BUS MASTER setting as SET (enable) will grant the device the
1066
+ * capability to perform DMA to the host memory.
1067
+ */
1068
+struct vfio_device_feature_bus_master {
1069
+    __u32 op;
1070
+#define        VFIO_DEVICE_FEATURE_CLEAR_MASTER    0    /* Clear Bus Master */
1071
+#define        VFIO_DEVICE_FEATURE_SET_MASTER        1    /* Set Bus Master */
1072
+};
1073
+#define VFIO_DEVICE_FEATURE_BUS_MASTER 10
1074
+
1075
/* -------- API for Type1 VFIO IOMMU -------- */
1076
1077
/**
1078
@@ -XXX,XX +XXX,XX @@ struct vfio_iommu_type1_info {
1079
    __u32    flags;
1080
#define VFIO_IOMMU_INFO_PGSIZES (1 << 0)    /* supported page sizes info */
1081
#define VFIO_IOMMU_INFO_CAPS    (1 << 1)    /* Info supports caps */
1082
-    __u64    iova_pgsizes;    /* Bitmap of supported page sizes */
1083
+    __aligned_u64    iova_pgsizes;        /* Bitmap of supported page sizes */
1084
    __u32 cap_offset;    /* Offset within info struct of first cap */
1085
    __u32 pad;
1086
};
1087
diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h
1088
index XXXXXXX..XXXXXXX 100644
1089
--- a/linux-headers/linux/vhost.h
1090
+++ b/linux-headers/linux/vhost.h
1091
@@ -XXX,XX +XXX,XX @@
1092
*/
1093
#define VHOST_VDPA_RESUME        _IO(VHOST_VIRTIO, 0x7E)
1094
1095
+/* Get the group for the descriptor table including driver & device areas
1096
+ * of a virtqueue: read index, write group in num.
1097
+ * The virtqueue index is stored in the index field of vhost_vring_state.
1098
+ * The group ID of the descriptor table for this specific virtqueue
1099
+ * is returned via num field of vhost_vring_state.
1100
+ */
1101
+#define VHOST_VDPA_GET_VRING_DESC_GROUP    _IOWR(VHOST_VIRTIO, 0x7F,    \
1102
+                     struct vhost_vring_state)
1103
#endif
1104
--
1105
2.43.0
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
KVM vector support for RISC-V requires the linux-header ptrace.h.
3
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
4
4
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
5
Message-ID: <20250116223609.81594-1-philmd@linaro.org>
6
Acked-by: Alistair Francis <alistair.francis@wdc.com>
7
Message-ID: <20231218204321.75757-3-dbarboza@ventanamicro.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
---
7
---
10
linux-headers/asm-riscv/ptrace.h | 132 +++++++++++++++++++++++++++++++
8
hw/char/riscv_htif.c | 15 +++------------
11
scripts/update-linux-headers.sh | 3 +
9
hw/char/trace-events | 4 ++++
12
2 files changed, 135 insertions(+)
10
2 files changed, 7 insertions(+), 12 deletions(-)
13
create mode 100644 linux-headers/asm-riscv/ptrace.h
14
11
15
diff --git a/linux-headers/asm-riscv/ptrace.h b/linux-headers/asm-riscv/ptrace.h
12
diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c
16
new file mode 100644
13
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX
14
--- a/hw/char/riscv_htif.c
18
--- /dev/null
15
+++ b/hw/char/riscv_htif.c
19
+++ b/linux-headers/asm-riscv/ptrace.h
20
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@
21
+/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
17
#include "exec/tswap.h"
22
+/*
18
#include "system/dma.h"
23
+ * Copyright (C) 2012 Regents of the University of California
19
#include "system/runstate.h"
24
+ */
20
-
21
-#define RISCV_DEBUG_HTIF 0
22
-#define HTIF_DEBUG(fmt, ...) \
23
- do { \
24
- if (RISCV_DEBUG_HTIF) { \
25
- qemu_log_mask(LOG_TRACE, "%s: " fmt "\n", __func__, ##__VA_ARGS__);\
26
- } \
27
- } while (0)
28
+#include "trace.h"
29
30
#define HTIF_DEV_SHIFT 56
31
#define HTIF_CMD_SHIFT 48
32
@@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written)
33
uint64_t payload = val_written & 0xFFFFFFFFFFFFULL;
34
int resp = 0;
35
36
- HTIF_DEBUG("mtohost write: device: %d cmd: %d what: %02" PRIx64
37
- " -payload: %016" PRIx64 "\n", device, cmd, payload & 0xFF, payload);
38
+ trace_htif_uart_write_to_host(device, cmd, payload);
39
40
/*
41
* Currently, there is a fixed mapping of devices:
42
@@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written)
43
}
44
} else {
45
qemu_log("HTIF unknown device or command\n");
46
- HTIF_DEBUG("device: %d cmd: %d what: %02" PRIx64
47
- " payload: %016" PRIx64, device, cmd, payload & 0xFF, payload);
48
+ trace_htif_uart_unknown_device_command(device, cmd, payload);
49
}
50
/*
51
* Latest bbl does not set fromhost to 0 if there is a value in tohost.
52
diff --git a/hw/char/trace-events b/hw/char/trace-events
53
index XXXXXXX..XXXXXXX 100644
54
--- a/hw/char/trace-events
55
+++ b/hw/char/trace-events
56
@@ -XXX,XX +XXX,XX @@ stm32f2xx_usart_read(char *id, unsigned size, uint64_t ofs, uint64_t val) " %s s
57
stm32f2xx_usart_write(char *id, unsigned size, uint64_t ofs, uint64_t val) "%s size %d ofs 0x%02" PRIx64 " <- 0x%02" PRIx64
58
stm32f2xx_usart_drop(char *id) " %s dropping the chars"
59
stm32f2xx_usart_receive(char *id, uint8_t chr) " %s receiving '%c'"
25
+
60
+
26
+#ifndef _ASM_RISCV_PTRACE_H
61
+# riscv_htif.c
27
+#define _ASM_RISCV_PTRACE_H
62
+htif_uart_write_to_host(uint8_t device, uint8_t cmd, uint64_t payload) "device: %u cmd: %02u payload: %016" PRIx64
28
+
63
+htif_uart_unknown_device_command(uint8_t device, uint8_t cmd, uint64_t payload) "device: %u cmd: %02u payload: %016" PRIx64
29
+#ifndef __ASSEMBLY__
30
+
31
+#include <linux/types.h>
32
+
33
+#define PTRACE_GETFDPIC        33
34
+
35
+#define PTRACE_GETFDPIC_EXEC    0
36
+#define PTRACE_GETFDPIC_INTERP    1
37
+
38
+/*
39
+ * User-mode register state for core dumps, ptrace, sigcontext
40
+ *
41
+ * This decouples struct pt_regs from the userspace ABI.
42
+ * struct user_regs_struct must form a prefix of struct pt_regs.
43
+ */
44
+struct user_regs_struct {
45
+    unsigned long pc;
46
+    unsigned long ra;
47
+    unsigned long sp;
48
+    unsigned long gp;
49
+    unsigned long tp;
50
+    unsigned long t0;
51
+    unsigned long t1;
52
+    unsigned long t2;
53
+    unsigned long s0;
54
+    unsigned long s1;
55
+    unsigned long a0;
56
+    unsigned long a1;
57
+    unsigned long a2;
58
+    unsigned long a3;
59
+    unsigned long a4;
60
+    unsigned long a5;
61
+    unsigned long a6;
62
+    unsigned long a7;
63
+    unsigned long s2;
64
+    unsigned long s3;
65
+    unsigned long s4;
66
+    unsigned long s5;
67
+    unsigned long s6;
68
+    unsigned long s7;
69
+    unsigned long s8;
70
+    unsigned long s9;
71
+    unsigned long s10;
72
+    unsigned long s11;
73
+    unsigned long t3;
74
+    unsigned long t4;
75
+    unsigned long t5;
76
+    unsigned long t6;
77
+};
78
+
79
+struct __riscv_f_ext_state {
80
+    __u32 f[32];
81
+    __u32 fcsr;
82
+};
83
+
84
+struct __riscv_d_ext_state {
85
+    __u64 f[32];
86
+    __u32 fcsr;
87
+};
88
+
89
+struct __riscv_q_ext_state {
90
+    __u64 f[64] __attribute__((aligned(16)));
91
+    __u32 fcsr;
92
+    /*
93
+     * Reserved for expansion of sigcontext structure. Currently zeroed
94
+     * upon signal, and must be zero upon sigreturn.
95
+     */
96
+    __u32 reserved[3];
97
+};
98
+
99
+struct __riscv_ctx_hdr {
100
+    __u32 magic;
101
+    __u32 size;
102
+};
103
+
104
+struct __riscv_extra_ext_header {
105
+    __u32 __padding[129] __attribute__((aligned(16)));
106
+    /*
107
+     * Reserved for expansion of sigcontext structure. Currently zeroed
108
+     * upon signal, and must be zero upon sigreturn.
109
+     */
110
+    __u32 reserved;
111
+    struct __riscv_ctx_hdr hdr;
112
+};
113
+
114
+union __riscv_fp_state {
115
+    struct __riscv_f_ext_state f;
116
+    struct __riscv_d_ext_state d;
117
+    struct __riscv_q_ext_state q;
118
+};
119
+
120
+struct __riscv_v_ext_state {
121
+    unsigned long vstart;
122
+    unsigned long vl;
123
+    unsigned long vtype;
124
+    unsigned long vcsr;
125
+    unsigned long vlenb;
126
+    void *datap;
127
+    /*
128
+     * In signal handler, datap will be set a correct user stack offset
129
+     * and vector registers will be copied to the address of datap
130
+     * pointer.
131
+     */
132
+};
133
+
134
+struct __riscv_v_regset_state {
135
+    unsigned long vstart;
136
+    unsigned long vl;
137
+    unsigned long vtype;
138
+    unsigned long vcsr;
139
+    unsigned long vlenb;
140
+    char vreg[];
141
+};
142
+
143
+/*
144
+ * According to spec: The number of bits in a single vector register,
145
+ * VLEN >= ELEN, which must be a power of 2, and must be no greater than
146
+ * 2^16 = 65536bits = 8192bytes
147
+ */
148
+#define RISCV_MAX_VLENB (8192)
149
+
150
+#endif /* __ASSEMBLY__ */
151
+
152
+#endif /* _ASM_RISCV_PTRACE_H */
153
diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
154
index XXXXXXX..XXXXXXX 100755
155
--- a/scripts/update-linux-headers.sh
156
+++ b/scripts/update-linux-headers.sh
157
@@ -XXX,XX +XXX,XX @@ for arch in $ARCHLIST; do
158
cp_portable "$tmpdir/bootparam.h" \
159
"$output/include/standard-headers/asm-$arch"
160
fi
161
+ if [ $arch = riscv ]; then
162
+ cp "$tmpdir/include/asm/ptrace.h" "$output/linux-headers/asm-riscv/"
163
+ fi
164
done
165
166
rm -rf "$output/linux-headers/linux"
167
--
64
--
168
2.43.0
65
2.48.1
66
67
diff view generated by jsdifflib