[PATCH v2] dbtr: Fix sbi_dbtr_read_trig to read from CSRs
Anup Patel
anup at brainfault.org
Wed Aug 27 22:23:07 PDT 2025
On Tue, Aug 12, 2025 at 3:32 AM Jesse Taube <jesse at rivosinc.com> wrote:
>
> sbi_dbtr_read_trig returned the saved state of tdata{1-3}, when it
> should have returned the updated state read from CSRs.
>
> Update sbi_dbtr_read_trig to return updated state read from CSRs.
>
> Signed-off-by: Jesse Taube <jesse at rivosinc.com>
> ---
> V1 -> V2:
> - Add back missing cpu_to_lle
> ---
> lib/sbi/sbi_dbtr.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
> index a832c7f1..c6b04aab 100644
> --- a/lib/sbi/sbi_dbtr.c
> +++ b/lib/sbi/sbi_dbtr.c
> @@ -529,9 +529,9 @@ int sbi_dbtr_read_trig(unsigned long smode,
> xmit = &entry->data;
> trig = INDEX_TO_TRIGGER((_idx + trig_idx_base));
> xmit->tstate = cpu_to_lle(trig->state);
> - xmit->tdata1 = cpu_to_lle(trig->tdata1);
> - xmit->tdata2 = cpu_to_lle(trig->tdata2);
> - xmit->tdata3 = cpu_to_lle(trig->tdata3);
> + xmit->tdata1 = cpu_to_lle(csr_read(CSR_TDATA1));
> + xmit->tdata2 = cpu_to_lle(csr_read(CSR_TDATA2));
> + xmit->tdata3 = cpu_to_lle(csr_read(CSR_TDATA1));
Typo over here. This should have been:
xmit->tdata3 = cpu_to_lle(csr_read(CSR_TDATA1));
Anyway, this patch is broken because we need to write
CSR_TSELECT before reading CSR_TDATAx.
The following would suffice:
diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index c30c2fd6..656a6261 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -563,6 +563,10 @@ int sbi_dbtr_read_trig(unsigned long smode,
for_each_trig_entry(shmem_base, trig_count, typeof(*entry), entry) {
xmit = &entry->data;
trig = INDEX_TO_TRIGGER((_idx + trig_idx_base));
+ csr_write(CSR_TSELECT, trig->index);
+ trig->tdata1 = csr_read(CSR_TDATA1);
+ trig->tdata2 = csr_read(CSR_TDATA2);
+ trig->tdata3 = csr_read(CSR_TDATA3);
xmit->tstate = cpu_to_lle(trig->state);
xmit->tdata1 = cpu_to_lle(trig->tdata1);
xmit->tdata2 = cpu_to_lle(trig->tdata2);
I have taken care of the above at the time of merging this patch.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
More information about the opensbi
mailing list