[PATCH 09/18] dbtr: Read triggers should not read HW trigger if not mapped

Nicholas Piggin
2026-03-13T05:20:57Z

When no hardware trigger is mapped to a dbtr trig idx there is logically
no hardware trigger to be read. The mapped status can be tested in the
tstate word, so callers understand this.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
lib/sbi/sbi_dbtr.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index a2c45061..6efd5435 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -577,14 +577,26 @@ 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);
- xmit->tdata3 = cpu_to_lle(trig->tdata3);
+ if (trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)) {
+ 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->tdata1 = cpu_to_lle(trig->tdata1);
+ xmit->tdata2 = cpu_to_lle(trig->tdata2);
+ xmit->tdata3 = cpu_to_lle(trig->tdata3);
+ } else {
+ /*
+ * If the trig idx does not have a HW trigger
+ * assigned then just return zeroes in tdata
+ * words.
+ */
+ xmit->tdata1 = 0;
+ xmit->tdata2 = 0;
+ xmit->tdata3 = 0;
+ }
}
sbi_hart_protection_unmap_range((unsigned long)shmem_base,
trig_count * sizeof(*entry));