lib: fix csr detect support
PATCH 1/1 lib: fix csr detect support
csr_read_allowed/csr_read_allowed requires trap.case to detect the results, but if no exception occurs, the value of trap.case will remain unchanged, which makes the detection results unreliable. Add code to initialize trap.case to 0.
--- include/sbi/sbi_csr_detect.h | 3 +++ lib/sbi/sbi_hart.c | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-)
include/sbi/sbi_csr_detect.h +3 -0
@@ -12,6 +12,7 @@#include <sbi/riscv_encoding.h> #include <sbi/sbi_hart.h> +#include <sbi/sbi_trap.h> #define csr_read_allowed (csr_num, trap) \ ({ \
@@ -19,6 +20,7 @@ registerulong ttmp asm("a4" ); \ registerulong mtvec =sbi_hart_expected_trap_addr (); \ registerulong ret =0 ; \ + ((struct sbi_trap_info *)(trap))->cause =0 ; \ asmvolatile ( \"add %[ttmp], %[tinfo], zero\n" \ "csrrw %[mtvec], " STR(CSR_MTVEC) ", %[mtvec]\n" \
@@ -36,6 +38,7 @@ register ulong tinfo asm("a3") = (ulong)trap; \ registerulong ttmp asm("a4" ); \ registerulong mtvec =sbi_hart_expected_trap_addr (); \ + ((struct sbi_trap_info *)(trap))->cause =0 ; \ asmvolatile ( \"add %[ttmp], %[tinfo], zero\n" \ "csrrw %[mtvec], " STR(CSR_MTVEC) ", %[mtvec]\n" \
lib/sbi/sbi_hart.c +0 -3
@@ -406,7 +406,6 @@ __mhpm_skip:#undef __check_csr/* Detect if hart supports SCOUNTEREN feature */ - trap.cause =0 ; val =csr_read_allowed (CSR_SCOUNTEREN , (unsigned long )&trap);if (!trap.cause) {csr_write_allowed (CSR_SCOUNTEREN , (unsigned long )&trap, val);
@@ -415,7 +414,6 @@ __mhpm_skip: }/* Detect if hart supports MCOUNTEREN feature */ - trap.cause =0 ; val =csr_read_allowed (CSR_MCOUNTEREN , (unsigned long )&trap);if (!trap.cause) {csr_write_allowed (CSR_MCOUNTEREN , (unsigned long )&trap, val);
@@ -424,7 +422,6 @@ __mhpm_skip: }/* Detect if hart supports time CSR */ - trap.cause =0 ;csr_read_allowed (CSR_TIME , (unsigned long )&trap);if (!trap.cause) hfeatures->features |=SBI_HART_HAS_TIME ;
Signature · 1 line
2.20.1
Anup Patel
AppliedPATCH 1/1 lib: fix csr detect support
Quoted 9 lines
-----Original Message-----
From: Xiang W <[email protected]>
Sent: 01 April 2021 13:30
To: opensbi at lists.infradead.org
Cc: Anup Patel <[email protected]>; Xiang W <[email protected]>
Subject: [PATCH] lib: fix csr detect support
Quoted 6 lines
csr_read_allowed/csr_read_allowed requires trap.case to detect the results, but if no exception occurs, the value of trap.case will remain unchanged, which makes the detection results unreliable. Add code to initialize trap.case to 0.
Signed-off-by Xiang W <[email protected]>
Looks good to me.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 68 lines
--- include/sbi/sbi_csr_detect.h | 3 +++ lib/sbi/sbi_hart.c | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-)include/sbi/sbi_csr_detect.h index renamed from include/sbi/sbi_csr_detect.h +0
-0f294888..89ba294 100644
include/sbi/sbi_csr_detect.h +1
-0@@ -12,6 +12,7 @@#include <sbi/riscv_encoding.h> #include <sbi/sbi_hart.h> +#include <sbi/sbi_trap.h> #define csr_read_allowed (csr_num, trap) \include/sbi/sbi_csr_detect.h +1
-0({ \@@ -19,6 +20,7 @@ registerulong ttmp asm("a4" ); \ registerulong mtvec =sbi_hart_expected_trap_addr (); \ registerulong ret =0 ; \ + ((struct sbi_trap_info *)(trap))->cause =0 ; \ asmvolatile ( \ "add %[ttmp], %[tinfo], zero\n"\include/sbi/sbi_csr_detect.h +1
-0"csrrw %[mtvec], " STR(CSR_MTVEC) ", %[mtvec]\n" \@@ -36,6 +38,7 @@ register ulong tinfo asm("a3") = (ulong)trap; \ registerulong ttmp asm("a4" ); \ registerulong mtvec =sbi_hart_expected_trap_addr (); \ + ((struct sbi_trap_info *)(trap))->cause =0 ; \ asmvolatile ( \ "add %[ttmp], %[tinfo], zero\n"\include/sbi/sbi_csr_detect.h +0
-0"csrrw %[mtvec], " STR(CSR_MTVEC) ", %[mtvec]\n" \lib/sbi/sbi_hart.c index d91b08c..de59b14 renamed from lib/sbi/sbi_hart.c +0
-0100644
lib/sbi/sbi_hart.c +0
-1@@ -406,7 +406,6 @@ __mhpm_skip:#undef __check_csr/* Detect if hart supports SCOUNTEREN feature */ - trap.cause =0 ; val =csr_read_allowed (CSR_SCOUNTEREN , (unsigned long )&trap);if (!trap.cause) { csr_write_allowed(CSR_SCOUNTEREN, (unsigned long)&trap,val); @@ -415,7 +414,6 @@
__mhpm_skip:lib/sbi/sbi_hart.c +0
-1}/* Detect if hart supports MCOUNTEREN feature */ - trap.cause =0 ; val =csr_read_allowed (CSR_MCOUNTEREN , (unsigned long )&trap);if (!trap.cause) { csr_write_allowed(CSR_MCOUNTEREN, (unsignedlong)&trap, val); @@ -424,7 +422,6 @@
__mhpm_skip:lib/sbi/sbi_hart.c +0
-2}/* Detect if hart supports time CSR */ - trap.cause =0 ;csr_read_allowed (CSR_TIME , (unsigned long )&trap);if (!trap.cause) hfeatures->features |=SBI_HART_HAS_TIME ; --2.20.1