Skip to contentSkip to conversation

lib: sbi: Fix mstatus_init() for RV32 when Sscofpmf is not available

PATCH New Anup Patel 3 participants 3 messages Apr 28, 2022

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 lib: sbi: Fix mstatus_init() for RV32 when Sscofpmf is not available

The mhpmevent3h to mhpmevent31h CSRs are available on RV32 only when Sscofpmf extension is available so mstatus_init() should set this CSRs only when Sscofpmf extension is available.

---
 lib/sbi/sbi_hart.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/sbi/sbi_hart.c +3 -1
index a50b6e4..229c14a 100644
@@ -82,7 +82,9 @@ static void mstatus_init(struct sbi_scratch *scratch)
 	for (cidx = 0; cidx < num_mhpm; cidx++) {
 #if __riscv_xlen == 32
 		csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val & 0xFFFFFFFF);
-		csr_write_num(CSR_MHPMEVENT3H + cidx, mhpmevent_init_val >> BITS_PER_LONG);
+		if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF))
+			csr_write_num(CSR_MHPMEVENT3H + cidx,
+				      mhpmevent_init_val >> BITS_PER_LONG);
 #else
 		csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val);
 #endif
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 lib: sbi: Fix mstatus_init() for RV32 when Sscofpmf is not available

Quoted 26 lines · Anup Patel

The mhpmevent3h to mhpmevent31h CSRs are available on RV32 only when Sscofpmf extension is available so mstatus_init() should set this CSRs only when Sscofpmf extension is available.

---
 lib/sbi/sbi_hart.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/sbi/sbi_hart.c +3 -2
index a50b6e4..229c14a 100644
@@ -82,7 +82,9 @@ static void mstatus_init(struct sbi_scratch *scratch)
        for (cidx = 0; cidx < num_mhpm; cidx++) {
 #if __riscv_xlen == 32
                csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val & 0xFFFFFFFF);
-               csr_write_num(CSR_MHPMEVENT3H + cidx, mhpmevent_init_val >> BITS_PER_LONG);
+               if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF))
+                       csr_write_num(CSR_MHPMEVENT3H + cidx,
+                                     mhpmevent_init_val >> BITS_PER_LONG);
 #else
                csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val);
 #endif
--
Quoted 2 lines

2.34.1

Thanks for the fix.

Signature · 2 lines
Regards,
Atish
Applied
#2 lore raw

PATCH 1/1 lib: sbi: Fix mstatus_init() for RV32 when Sscofpmf is not available

Quoted 32 lines · Atish Patra
Quoted 26 lines · Anup Patel

The mhpmevent3h to mhpmevent31h CSRs are available on RV32 only when Sscofpmf extension is available so mstatus_init() should set this CSRs only when Sscofpmf extension is available.

---
 lib/sbi/sbi_hart.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/sbi/sbi_hart.c +3 -2
index a50b6e4..229c14a 100644
@@ -82,7 +82,9 @@ static void mstatus_init(struct sbi_scratch *scratch)
        for (cidx = 0; cidx < num_mhpm; cidx++) {
 #if __riscv_xlen == 32
                csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val & 0xFFFFFFFF);
-               csr_write_num(CSR_MHPMEVENT3H + cidx, mhpmevent_init_val >> BITS_PER_LONG);
+               if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF))
+                       csr_write_num(CSR_MHPMEVENT3H + cidx,
+                                     mhpmevent_init_val >> BITS_PER_LONG);
 #else
                csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val);
 #endif
--
Quoted 2 lines

2.34.1

Thanks for the fix.

Quoted 1 line

This is an urgent fix for RV32 so applying it sooner.

Applied this patch to the riscv/opensbi repo.

Regards,
Anup

Quoted 4 lines

--
Regards,
Atish