[PATCH] lib: sbi: dbtr: Fix update_triggers to match SBI

Charlie Jenkins charlie at rivosinc.com
Wed May 28 12:53:57 PDT 2025


On Wed, May 28, 2025 at 08:46:04AM -0700, Jesse Taube wrote:
> OpenSBI implements sbi_dbtr_update_trig as
> `sbi_dbtr_update_trig(unsigned long trig_idx_base,
>                       unsigned long trig_idx_mask)`
> yet SBI v3.0-rc7 Chapter 19. Debug Triggers Extension [0] declares it as
> `sbi_debug_update_triggers(unsigned long trig_count)`
> 
> Change update_triggers to match SBI.
> 
> [0] https://github.com/riscv-non-isa/riscv-sbi-doc/tree/v3.0-rc7/src/ext-debug-triggers.adoc
> 
> Fixes: 97f234f15c96 ("lib: sbi: Introduce the SBI debug triggers extension support")
> Signed-off-by: Jesse Taube <jesse at rivosinc.com>

Tested-by: Charlie Jenkins <charlie at rivosinc.com>
Reviewed-by: Charlie Jenkins <charlie at rivosinc.com>

> ---
>  include/sbi/sbi_dbtr.h   |  3 +--
>  lib/sbi/sbi_dbtr.c       | 33 ++++++++++++++++++++-------------
>  lib/sbi/sbi_ecall_dbtr.c |  2 +-
>  3 files changed, 22 insertions(+), 16 deletions(-)
> 
> diff --git a/include/sbi/sbi_dbtr.h b/include/sbi/sbi_dbtr.h
> index 8cb776c..b1cfb5b 100644
> --- a/include/sbi/sbi_dbtr.h
> +++ b/include/sbi/sbi_dbtr.h
> @@ -117,8 +117,7 @@ int sbi_dbtr_uninstall_trig(unsigned long trig_idx_base,
>  int sbi_dbtr_enable_trig(unsigned long trig_idx_base,
>  			 unsigned long trig_idx_mask);
>  int sbi_dbtr_update_trig(unsigned long smode,
> -			 unsigned long trig_idx_base,
> -			 unsigned long trig_idx_mask);
> +			 unsigned long trig_count);
>  int sbi_dbtr_disable_trig(unsigned long trig_idx_base,
>  			  unsigned long trig_idx_mask);
>  
> diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
> index f0e9128..1248634 100644
> --- a/lib/sbi/sbi_dbtr.c
> +++ b/lib/sbi/sbi_dbtr.c
> @@ -651,13 +651,9 @@ int sbi_dbtr_enable_trig(unsigned long trig_idx_base,
>  }
>  
>  int sbi_dbtr_update_trig(unsigned long smode,
> -			 unsigned long trig_idx_base,
> -			 unsigned long trig_idx_mask)
> +			 unsigned long trig_count)
>  {
> -	unsigned long trig_mask = trig_idx_mask << trig_idx_base;
> -	unsigned long idx = trig_idx_base;
> -	struct sbi_dbtr_data_msg *recv;
> -	unsigned long uidx = 0;
> +	unsigned long trig_idx;
>  	struct sbi_dbtr_trigger *trig;
>  	struct sbi_dbtr_shmem_entry *entry;
>  	void *shmem_base = NULL;
> @@ -672,18 +668,29 @@ int sbi_dbtr_update_trig(unsigned long smode,
>  
>  	shmem_base = hart_shmem_base(hs);
>  
> -	for_each_set_bit_from(idx, &trig_mask, hs->total_trigs) {
> -		trig = INDEX_TO_TRIGGER(idx);
>  
> -		if (!(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)))
> +	if (trig_count >= hs->total_trigs)
> +		return SBI_ERR_BAD_RANGE;
> +
> +	for_each_trig_entry(shmem_base, trig_count, typeof(*entry), entry) {
> +		sbi_hart_map_saddr((unsigned long)entry, sizeof(*entry));
> +		trig_idx = entry->id.idx;
> +
> +		if (trig_idx >= hs->total_trigs) {
> +			sbi_hart_unmap_saddr();
>  			return SBI_ERR_INVALID_PARAM;
> +		}
>  
> -		entry = (shmem_base + uidx * sizeof(*entry));
> -		recv = &entry->data;
> +		trig = INDEX_TO_TRIGGER(trig_idx);
>  
> -		trig->tdata2 = lle_to_cpu(recv->tdata2);
> +		if (!(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED))) {
> +			sbi_hart_unmap_saddr();
> +			return SBI_ERR_FAILED;
> +		}
> +
> +		dbtr_trigger_setup(trig, &entry->data);
> +		sbi_hart_unmap_saddr();
>  		dbtr_trigger_enable(trig);
> -		uidx++;
>  	}
>  
>  	return SBI_SUCCESS;
> diff --git a/lib/sbi/sbi_ecall_dbtr.c b/lib/sbi/sbi_ecall_dbtr.c
> index 9c496c4..40a437e 100644
> --- a/lib/sbi/sbi_ecall_dbtr.c
> +++ b/lib/sbi/sbi_ecall_dbtr.c
> @@ -43,7 +43,7 @@ static int sbi_ecall_dbtr_handler(unsigned long extid, unsigned long funcid,
>  		ret = sbi_dbtr_enable_trig(regs->a0, regs->a1);
>  		break;
>  	case SBI_EXT_DBTR_TRIGGER_UPDATE:
> -		ret = sbi_dbtr_update_trig(smode, regs->a0, regs->a1);
> +		ret = sbi_dbtr_update_trig(smode, regs->a0);
>  		break;
>  	case SBI_EXT_DBTR_TRIGGER_DISABLE:
>  		ret = sbi_dbtr_disable_trig(regs->a0, regs->a1);
> -- 
> 2.43.0
> 



More information about the opensbi mailing list