[PATCH 11/12] lib: sbi: Fix dtbr initialization
Xiang W
wxjstz at 126.com
Wed Jun 11 05:15:24 PDT 2025
Previously, dbtr initialization and extension registration were
performed only on the coldboot HART, resulting in extension
registration only depending on whether the coldboot HART supports
dbtr. Now that the boot sequence has been corrected, dtbr extensions
can be registered even if some cores support dtbr.
Signed-off-by: Xiang W <wxjstz at 126.com>
---
lib/sbi/sbi_dbtr.c | 29 ++++++++++++++++++++++++-----
lib/sbi/sbi_ecall_dbtr.c | 2 +-
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index bdfbcde9..de459880 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -23,6 +23,8 @@
/** Offset of pointer to HART's debug triggers info in scratch space */
static unsigned long hart_state_ptr_offset;
+static bool has_dtbr_triggers;
+
#define dbtr_get_hart_state_ptr(__scratch) \
sbi_scratch_read_type((__scratch), void *, hart_state_ptr_offset)
@@ -138,12 +140,10 @@ int sbi_dbtr_init(struct sbi_scratch *scratch, bool coldboot)
struct sbi_trap_info trap = {0};
unsigned long tdata1;
unsigned long val;
- int i;
+ int i, ret = SBI_SUCCESS;
struct sbi_dbtr_hart_triggers_state *hart_state = NULL;
static atomic_t sync_a = ATOMIC_INITIALIZER(0);
-
- if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SDTRIG))
- return SBI_SUCCESS;
+ static atomic_t sync_b = ATOMIC_INITIALIZER(0);
sbi_wait_for_boot_hart_first(coldboot, &sync_a);
if (coldboot) {
@@ -153,6 +153,9 @@ int sbi_dbtr_init(struct sbi_scratch *scratch, bool coldboot)
}
sbi_signal_boot_hart_first_done(coldboot, &sync_a);
+ if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SDTRIG))
+ goto _exit;
+
hart_state = dbtr_get_hart_state_ptr(scratch);
if (!hart_state) {
hart_state = sbi_zalloc(sizeof(*hart_state));
@@ -215,10 +218,26 @@ int sbi_dbtr_init(struct sbi_scratch *scratch, bool coldboot)
hart_state->probed = 1;
+ if (hart_state->total_trigs > 0)
+ has_dtbr_triggers = true;
+
_probed:
hart_state->available_trigs = hart_state->total_trigs;
+_exit:
- return SBI_SUCCESS;
+ /*
+ * Wait for all HARTs to complete sbi_dbtr_init to
+ * ensure that the following code can determine whether
+ * dtbr is supported
+ */
+ sbi_sync_and_wait_all_harts(&sync_b);
+
+ return ret;
+}
+
+int sbi_dbtr_supported(void)
+{
+ return has_dtbr_triggers;
}
int sbi_dbtr_get_total_triggers(void)
diff --git a/lib/sbi/sbi_ecall_dbtr.c b/lib/sbi/sbi_ecall_dbtr.c
index 9c496c42..f5639141 100644
--- a/lib/sbi/sbi_ecall_dbtr.c
+++ b/lib/sbi/sbi_ecall_dbtr.c
@@ -59,7 +59,7 @@ struct sbi_ecall_extension ecall_dbtr;
static int sbi_ecall_dbtr_register_extensions(void)
{
- if (sbi_dbtr_get_total_triggers() == 0)
+ if (!sbi_dbtr_supported())
return 0;
return sbi_ecall_register_extension(&ecall_dbtr);
--
2.47.2
More information about the opensbi
mailing list