[PATCH 08/12] lib: sbi: Remove cold_boot from sbi_hsm_init

Xiang W wxjstz at 126.com
Wed Jun 11 05:12:25 PDT 2025


Currently sbi_hsm_init only needs to be executed on coldboot hart,
so the parameter cold_boot can be removed.

Signed-off-by: Xiang W <wxjstz at 126.com>
---
 include/sbi/sbi_hsm.h |  2 +-
 lib/sbi/sbi_hsm.c     | 38 ++++++++++++++++++--------------------
 lib/sbi/sbi_init.c    | 25 +++++++++++++------------
 3 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/include/sbi/sbi_hsm.h b/include/sbi/sbi_hsm.h
index f7a6497c..05b512d7 100644
--- a/include/sbi/sbi_hsm.h
+++ b/include/sbi/sbi_hsm.h
@@ -63,7 +63,7 @@ const struct sbi_hsm_device *sbi_hsm_get_device(void);
 
 void sbi_hsm_set_device(const struct sbi_hsm_device *dev);
 
-int sbi_hsm_init(struct sbi_scratch *scratch, bool cold_boot);
+int sbi_hsm_init(struct sbi_scratch *scratch);
 
 void sbi_hsm_hart_wait(struct sbi_scratch *scratch, bool cold_boot);
 
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
index b5f3194e..b75d9e43 100644
--- a/lib/sbi/sbi_hsm.c
+++ b/lib/sbi/sbi_hsm.c
@@ -244,30 +244,28 @@ static void hsm_device_hart_resume(void)
 		hsm_dev->hart_resume();
 }
 
-int sbi_hsm_init(struct sbi_scratch *scratch, bool cold_boot)
+int sbi_hsm_init(struct sbi_scratch *scratch)
 {
 	struct sbi_scratch *rscratch;
 	struct sbi_hsm_data *hdata;
 
-	if (cold_boot) {
-		hart_data_offset = sbi_scratch_alloc_offset(sizeof(*hdata));
-		if (!hart_data_offset)
-			return SBI_ENOMEM;
-
-		/* Initialize hart state data for every hart */
-		sbi_for_each_hartindex(i) {
-			rscratch = sbi_hartindex_to_scratch(i);
-			if (!rscratch)
-				continue;
-
-			hdata = sbi_scratch_offset_ptr(rscratch,
-						       hart_data_offset);
-			ATOMIC_INIT(&hdata->state,
-				    (i == current_hartindex()) ?
-				    SBI_HSM_STATE_START_PENDING :
-				    SBI_HSM_STATE_STOPPED);
-			ATOMIC_INIT(&hdata->start_ticket, 0);
-		}
+	hart_data_offset = sbi_scratch_alloc_offset(sizeof(*hdata));
+	if (!hart_data_offset)
+		return SBI_ENOMEM;
+
+	/* Initialize hart state data for every hart */
+	sbi_for_each_hartindex(i) {
+		rscratch = sbi_hartindex_to_scratch(i);
+		if (!rscratch)
+			continue;
+
+		hdata = sbi_scratch_offset_ptr(rscratch,
+					       hart_data_offset);
+		ATOMIC_INIT(&hdata->state,
+			    (i == current_hartindex()) ?
+			    SBI_HSM_STATE_START_PENDING :
+			    SBI_HSM_STATE_STOPPED);
+		ATOMIC_INIT(&hdata->start_ticket, 0);
 	}
 
 	return 0;
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index 47802d54..73d35933 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -242,6 +242,10 @@ static void __noreturn init_startup(struct sbi_scratch *scratch, u32 hartid, boo
 		if (rc)
 			sbi_hart_hang();
 
+		rc = sbi_hsm_init(scratch);
+		if (rc)
+			sbi_hart_hang();
+
 		entry_count_offset = sbi_scratch_alloc_offset(__SIZEOF_POINTER__);
 		init_count_offset = sbi_scratch_alloc_offset(__SIZEOF_POINTER__);
 	} else {
@@ -256,21 +260,18 @@ static void __noreturn init_startup(struct sbi_scratch *scratch, u32 hartid, boo
 	if (!entry_count_offset || !init_count_offset)
 		sbi_hart_hang();
 
-	count = sbi_scratch_offset_ptr(scratch, entry_count_offset);
-	(*count)++;
-
-	rc = sbi_hsm_init(scratch, cold_boot);
-	if (rc)
-		sbi_hart_hang();
-
-	/*
-	 * All non-coldboot HARTs do HSM initialization (i.e. enter HSM state
-	 * machine) at the start of the warmboot path so it is wasteful to
-	 * have these HARTs busy spin in wait_for_coldboot() until coldboot
-	 * path is completed.
+	/**
+	 * All non-coldboot HARTs will wait for the coldboot HART to
+	 * initialize the HSM (i.e. enter the HSM state machine), so
+	 * it is wasteful to have these HARTs busy spin in
+	 * sbi_wait_for_boot_hart_first() until the coldboot HART is
+	 * complete.
 	 */
 	sbi_signal_boot_hart_first_done(cold_boot, &sync_a);
 
+	count = sbi_scratch_offset_ptr(scratch, entry_count_offset);
+	(*count)++;
+
 	rc = sbi_platform_early_init(plat, cold_boot);
 	if (rc)
 		sbi_hart_hang();
-- 
2.47.2




More information about the opensbi mailing list