summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Holland <[email protected]>2024-07-10 07:26:06 -0700
committerAnup Patel <[email protected]>2024-07-29 11:34:18 +0530
commit65a3938fadc537af178c84a349ade31ec6a70846 (patch)
treef1a8c33830ba1eb5bb7024279e3a2f5c15083e3e
parent455de672dd7c2aa1992df54dfb08dc11abbc1b1a (diff)
lib: sbi_hsm: Save/restore menvcfg only when it exists
Attempting to access the menvcfg CSR raises an illegal instruction exception on hardware which implements Sm1p11 or older. Fixes: e9ee9678ba50 ("lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING") Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
-rw-r--r--lib/sbi/sbi_hsm.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
index 7e32af37..3706acfb 100644
--- a/lib/sbi/sbi_hsm.c
+++ b/lib/sbi/sbi_hsm.c
@@ -423,10 +423,12 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
hdata->saved_mie = csr_read(CSR_MIE);
hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP);
hdata->saved_medeleg = csr_read(CSR_MEDELEG);
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
#if __riscv_xlen == 32
- hdata->saved_menvcfgh = csr_read(CSR_MENVCFGH);
+ hdata->saved_menvcfgh = csr_read(CSR_MENVCFGH);
#endif
- hdata->saved_menvcfg = csr_read(CSR_MENVCFG);
+ hdata->saved_menvcfg = csr_read(CSR_MENVCFG);
+ }
}
static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
@@ -434,10 +436,12 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
hart_data_offset);
- csr_write(CSR_MENVCFG, hdata->saved_menvcfg);
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
+ csr_write(CSR_MENVCFG, hdata->saved_menvcfg);
#if __riscv_xlen == 32
- csr_write(CSR_MENVCFGH, hdata->saved_menvcfgh);
+ csr_write(CSR_MENVCFGH, hdata->saved_menvcfgh);
#endif
+ }
csr_write(CSR_MEDELEG, hdata->saved_medeleg);
csr_write(CSR_MIE, hdata->saved_mie);
csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));