From 55e191e3b09c4979212c592a4e86e0f561ce1f97 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 3 Jan 2020 09:10:41 +0530 Subject: [PATCH] lib: Add system early_exit and final_exit APIs 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 Reviewed-by: Atish Patra --- include/sbi/sbi_platform.h | 27 +++++++++++++++++++++++++++ include/sbi/sbi_system.h | 4 ++++ lib/sbi/sbi_init.c | 4 ++++ lib/sbi/sbi_system.c | 10 ++++++++++ 4 files changed, 45 insertions(+) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 010328e..72bb7e2 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -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 diff --git a/include/sbi/sbi_system.h b/include/sbi/sbi_system.h index bf768d9..c1ef374 100644 --- a/include/sbi/sbi_system.h +++ b/include/sbi/sbi_system.h @@ -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); diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index b4c242f..d5d3513 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -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(); } diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c index cdc85d6..9ea3c21 100644 --- a/lib/sbi/sbi_system.c +++ b/lib/sbi/sbi_system.c @@ -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) -- 2.7.4