lib: sbi: enable seed access in S-mode
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 28 Oct 2023 22:49:59 +0000 (00:49 +0200)
committerAnup Patel <anup@brainfault.org>
Fri, 17 Nov 2023 06:56:22 +0000 (12:26 +0530)
If ISA extension Zkr is available, set

    mseccfg.sseed=1
    mseccfg.useed=0

This enables access to the seed CSR in S-mode but not in U-mode.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_hart.c

index 569596f182fc1dce41b94352c2c0151febcfbea4..b47f00b2ed125afb86fa3441d78ef3bbaf7bdc04 100644 (file)
@@ -160,6 +160,12 @@ static void mstatus_init(struct sbi_scratch *scratch)
                }
 
                csr_write(CSR_MENVCFG, menvcfg_val);
+
+               /* Enable S-mode access to seed CSR */
+               if (sbi_hart_has_extension(scratch, SBI_HART_EXT_ZKR)) {
+                       csr_set(CSR_MSECCFG, MSECCFG_SSEED);
+                       csr_clear(CSR_MSECCFG, MSECCFG_USEED);
+               }
        }
 
        /* Disable all interrupts */