The latest KVM RISC-V programes henvcfg[h] CSR so let us emulate
a dummy (read zero and write ignore) henvcfg[h] CSR for the guest
hypervisor.
Signed-off-by: Anup Patel <
apa...@ventanamicro.com>
---
arch/riscv/cpu/generic/cpu_vcpu_nested.c | 6 +++++
arch/riscv/cpu/generic/cpu_vcpu_trap.c | 8 ++++++
.../cpu/generic/include/riscv_encoding.h | 27 +++++++++++++++++--
3 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/cpu/generic/cpu_vcpu_nested.c b/arch/riscv/cpu/generic/cpu_vcpu_nested.c
index 4d3d4f08..9a96d9cd 100644
--- a/arch/riscv/cpu/generic/cpu_vcpu_nested.c
+++ b/arch/riscv/cpu/generic/cpu_vcpu_nested.c
@@ -1143,6 +1143,12 @@ int cpu_vcpu_nested_hext_csr_rmw(struct vmm_vcpu *vcpu, arch_regs_t *regs,
}
}
break;
+ case CSR_HENVCFG:
+#ifndef CONFIG_64BIT
+ case CSR_HENVCFGH:
+#endif
+ csr = &zero;
+ break;
case CSR_VSSTATUS:
csr = &npriv->vsstatus;
writeable_mask = SSTATUS_SIE | SSTATUS_SPIE | SSTATUS_UBE |
diff --git a/arch/riscv/cpu/generic/cpu_vcpu_trap.c b/arch/riscv/cpu/generic/cpu_vcpu_trap.c
index 81140ac4..a2085a08 100644
--- a/arch/riscv/cpu/generic/cpu_vcpu_trap.c
+++ b/arch/riscv/cpu/generic/cpu_vcpu_trap.c
@@ -621,6 +621,14 @@ static const struct csr_func csr_funcs[] = {
.csr_num = CSR_HGATP,
.rmw_func = cpu_vcpu_nested_hext_csr_rmw,
},
+ {
+ .csr_num = CSR_HENVCFG,
+ .rmw_func = cpu_vcpu_nested_hext_csr_rmw,
+ },
+ {
+ .csr_num = CSR_HENVCFGH,
+ .rmw_func = cpu_vcpu_nested_hext_csr_rmw,
+ },
{
.csr_num = CSR_VSSTATUS,
.rmw_func = cpu_vcpu_nested_hext_csr_rmw,
diff --git a/arch/riscv/cpu/generic/include/riscv_encoding.h b/arch/riscv/cpu/generic/include/riscv_encoding.h
index de79cf30..1124d4ba 100644
--- a/arch/riscv/cpu/generic/include/riscv_encoding.h
+++ b/arch/riscv/cpu/generic/include/riscv_encoding.h
@@ -359,6 +359,18 @@
#define HVICTL_IPRIOM 0x00000100
#define HVICTL_IPRIO 0x000000ff
+/* xENVCFG flags */
+#define ENVCFG_STCE (_AC(1, ULL) << 63)
+#define ENVCFG_PBMTE (_AC(1, ULL) << 62)
+#define ENVCFG_CBZE (_AC(1, UL) << 7)
+#define ENVCFG_CBCFE (_AC(1, UL) << 6)
+#define ENVCFG_CBIE_SHIFT 4
+#define ENVCFG_CBIE (_AC(0x3, UL) << ENVCFG_CBIE_SHIFT)
+#define ENVCFG_CBIE_ILL _AC(0x0, UL)
+#define ENVCFG_CBIE_FLUSH _AC(0x1, UL)
+#define ENVCFG_CBIE_INV _AC(0x3, UL)
+#define ENVCFG_FIOM _AC(0x1, UL)
+
/* ===== User-level CSRs ===== */
/* User Trap Setup (N-extension) */
@@ -482,6 +494,12 @@
#define CSR_SIEH 0x114
#define CSR_SIPH 0x154
+/* Supervisor Configuration */
+#define CSR_SENVCFG 0x10a
+
+/* Counter Overflow CSR */
+#define CSR_SCOUNTOVF 0xda0
+
/* ===== Hypervisor-level CSRs ===== */
/* Hypervisor Trap Setup (H-extension) */
@@ -506,6 +524,10 @@
#define CSR_HTIMEDELTA 0x605
#define CSR_HTIMEDELTAH 0x615
+/* Hypervisor Configuration (H-extension) */
+#define CSR_HENVCFG 0x60a
+#define CSR_HENVCFGH 0x61a
+
/* Virtual Supervisor Registers (H-extension) */
#define CSR_VSSTATUS 0x200
#define CSR_VSIE 0x204
@@ -782,8 +804,9 @@
#define CSR_MHPMEVENT30H 0x73e
#define CSR_MHPMEVENT31H 0x73f
-/* Counter Overflow CSR */
-#define CSR_SCOUNTOVF 0xda0
+/* Machine Configuration */
+#define CSR_MENVCFG 0x30a
+#define CSR_MENVCFGH 0x31a
/* Debug/Trace Registers */
#define CSR_TSELECT 0x7a0
--
2.34.1