lib: sbi: Allow platform to influence cold boot HART selection
authorAnup Patel <apatel@ventanamicro.com>
Thu, 29 Dec 2022 02:56:15 +0000 (10:56 +0800)
committerAnup Patel <anup@brainfault.org>
Sat, 7 Jan 2023 10:28:49 +0000 (15:58 +0530)
We add an optional cold_boot_allowed() platform callback which allows
platform support to decide which HARTs can do cold boot initialization.

If this platform callback is not available then any HART can do cold
boot initialization.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
include/sbi/sbi_platform.h
lib/sbi/sbi_init.c

index 010e9cebdd707f2ed523de4bef4263c186db1842..43d1c031ed748a93799dbeeaba7a2422a63361a7 100644 (file)
@@ -65,6 +65,9 @@ enum sbi_platform_features {
 
 /** Platform functions */
 struct sbi_platform_operations {
+       /* Check if specified HART is allowed to do cold boot */
+       bool (*cold_boot_allowed)(u32 hartid);
+
        /* Platform nascent initialization */
        int (*nascent_init)(void);
 
@@ -356,6 +359,23 @@ static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
        return false;
 }
 
+/**
+ * Check whether given HART is allowed to do cold boot
+ *
+ * @param plat pointer to struct sbi_platform
+ * @param hartid HART ID
+ *
+ * @return true if HART is allowed to do cold boot and false otherwise
+ */
+static inline bool sbi_platform_cold_boot_allowed(
+                                       const struct sbi_platform *plat,
+                                       u32 hartid)
+{
+       if (plat && sbi_platform_ops(plat)->cold_boot_allowed)
+               return sbi_platform_ops(plat)->cold_boot_allowed(hartid);
+       return true;
+}
+
 /**
  * Nascent (very early) initialization for current HART
  *
index ded3da00a93a4c02e04475f3cc19c674758a60a6..259a191051a71dc5feaaad8e76c8b7cf9a266223 100644 (file)
@@ -498,8 +498,11 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
         * HARTs which satisfy above condition.
         */
 
-       if (next_mode_supported && atomic_xchg(&coldboot_lottery, 1) == 0)
-               coldboot = true;
+       if (sbi_platform_cold_boot_allowed(plat, hartid)) {
+               if (next_mode_supported &&
+                   atomic_xchg(&coldboot_lottery, 1) == 0)
+                       coldboot = true;
+       }
 
        /*
         * Do platform specific nascent (very early) initialization so