[PATCH 15/18] dbtr: Move trigger feature support test into a function

Nicholas Piggin
2026-03-13T05:21:14Z

With heterogeneous triggers this test becomes more complicated and is
neeed in more places, so move it into a function.

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

diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index 74b114b8..77162efe 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -85,6 +85,14 @@ static inline void *hart_shmem_base(
hs->shmem.phys_hi, hs->shmem.phys_lo));
}

+static bool sbi_hw_trigger_supports(struct sbi_hw_trigger *hw_trig,
+ unsigned long type, unsigned long tdata1)
+{
+ if (!(BIT(type) & hw_trig->type_mask))
+ return false;
+ return true;
+}
+
static inline struct sbi_dbtr_trigger *sbi_alloc_trigger(void)
{
int i;
@@ -555,7 +563,6 @@ int sbi_dbtr_num_trig(unsigned long data, unsigned long *out)
unsigned long type = TDATA1_GET_TYPE(data);
u32 hartid = current_hartid();
unsigned long total = 0;
- struct sbi_hw_trigger *hw_trig;
int i;
struct sbi_dbtr_hart_triggers_state *hs;

@@ -569,9 +576,7 @@ int sbi_dbtr_num_trig(unsigned long data, unsigned long *out)
}

for (i = 0; i < hs->total_trigs; i++) {
- hw_trig = INDEX_TO_HW_TRIGGER(i);
-
- if (__test_bit(type, &hw_trig->type_mask))
+ if (sbi_hw_trigger_supports(INDEX_TO_HW_TRIGGER(i), type, data))
total++;