Skip to contentSkip to conversation

dbtr: Fix sbi_dbtr_read_trig to read from CSRs

PATCH Applied Jesse Taube 2 participants 2 messages Aug 11, 2025 – Aug 28, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dbtr: Fix sbi_dbtr_read_trig to read from CSRs

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.

---
V1 -> V2:
- Add back missing cpu_to_lle

---
 lib/sbi/sbi_dbtr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/sbi/sbi_dbtr.c +3 -3
index a832c7f1..c6b04aab 100644
@@ -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));
 	}
 	sbi_hart_unmap_saddr();
 
Signature · 7 lines
2.43.0


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Applied
#1 lore raw
Quoted 19 lines · Jesse Taube

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.

---
V1 -> V2:
- Add back missing cpu_to_lle

---
 lib/sbi/sbi_dbtr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/sbi/sbi_dbtr.c +0 -0
index a832c7f1..c6b04aab 100644

lib/sbi/sbi_dbtr.c int sbi_dbtr_read_trig(unsigned long smode, · line 534

Quoted 9 lines
lib/sbi/sbi_dbtr.c +3 -3
@@ -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:

lib/sbi/sbi_dbtr.c +4 -0
index c30c2fd6..656a6261 100644
@@ -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

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi