lib: Add system early_exit and final_exit APIs
authorAnup Patel <anup.patel@wdc.com>
Fri, 3 Jan 2020 03:40:41 +0000 (09:10 +0530)
committerAnup Patel <anup.patel@wdc.com>
Tue, 7 Jan 2020 06:40:48 +0000 (12:10 +0530)
This patch adds system-level early_exit and final_exit APIs
with corresponding platform hooks. These new APIs will be
primarily used by sbi_exit() in OpenSBI exit path.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
include/sbi/sbi_platform.h
include/sbi/sbi_system.h
lib/sbi/sbi_init.c
lib/sbi/sbi_system.c

index 010328e..72bb7e2 100644 (file)
@@ -76,6 +76,11 @@ struct sbi_platform_operations {
        /** Platform final initialization */
        int (*final_init)(bool cold_boot);
 
+       /** Platform early exit */
+       void (*early_exit)(void);
+       /** Platform final exit */
+       void (*final_exit)(void);
+
        /** For platforms that do not implement misa, non-standard
         * methods are needed to determine cpu extension.
         */
@@ -302,6 +307,28 @@ static inline int sbi_platform_final_init(const struct sbi_platform *plat,
 }
 
 /**
+ * Early exit for current HART
+ *
+ * @param plat pointer to struct sbi_platform
+ */
+static inline void sbi_platform_early_exit(const struct sbi_platform *plat)
+{
+       if (plat && sbi_platform_ops(plat)->early_exit)
+               sbi_platform_ops(plat)->early_exit();
+}
+
+/**
+ * Final exit for current HART
+ *
+ * @param plat pointer to struct sbi_platform
+ */
+static inline void sbi_platform_final_exit(const struct sbi_platform *plat)
+{
+       if (plat && sbi_platform_ops(plat)->final_exit)
+               sbi_platform_ops(plat)->final_exit();
+}
+
+/**
  * Check CPU extension in MISA
  *
  * @param plat pointer to struct sbi_platform
index bf768d9..c1ef374 100644 (file)
@@ -18,6 +18,10 @@ int sbi_system_early_init(struct sbi_scratch *scratch, bool cold_boot);
 
 int sbi_system_final_init(struct sbi_scratch *scratch, bool cold_boot);
 
+void sbi_system_early_exit(struct sbi_scratch *scratch);
+
+void sbi_system_final_exit(struct sbi_scratch *scratch);
+
 void __attribute__((noreturn))
 sbi_system_reboot(struct sbi_scratch *scratch, u32 type);
 
index b4c242f..d5d3513 100644 (file)
@@ -203,5 +203,9 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch)
 
        sbi_hart_unmark_available(hartid);
 
+       sbi_platform_early_exit(plat);
+
+       sbi_platform_final_exit(plat);
+
        sbi_hart_hang();
 }
index cdc85d6..9ea3c21 100644 (file)
@@ -23,6 +23,16 @@ int sbi_system_final_init(struct sbi_scratch *scratch, bool cold_boot)
        return sbi_platform_final_init(sbi_platform_ptr(scratch), cold_boot);
 }
 
+void sbi_system_early_exit(struct sbi_scratch *scratch)
+{
+       sbi_platform_early_exit(sbi_platform_ptr(scratch));
+}
+
+void sbi_system_final_exit(struct sbi_scratch *scratch)
+{
+       sbi_platform_final_exit(sbi_platform_ptr(scratch));
+}
+
 void __attribute__((noreturn))
 sbi_system_reboot(struct sbi_scratch *scratch, u32 type)