lib: Add timer exit API
authorAnup Patel <anup.patel@wdc.com>
Fri, 3 Jan 2020 03:48:42 +0000 (09:18 +0530)
committerAnup Patel <anup.patel@wdc.com>
Tue, 7 Jan 2020 06:40:55 +0000 (12:10 +0530)
We add sbi_timer_exit() API for OpenSBI exit path handling in
sbi_exit() implementation.

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_timer.h
lib/sbi/sbi_init.c
lib/sbi/sbi_timer.c

index 72bb7e2..02007af 100644 (file)
@@ -125,6 +125,8 @@ struct sbi_platform_operations {
        void (*timer_event_stop)(void);
        /** Initialize platform timer for current HART */
        int (*timer_init)(bool cold_boot);
+       /** Exit platform timer for current HART */
+       void (*timer_exit)(void);
 
        /** Reboot the platform */
        int (*system_reboot)(u32 type);
@@ -553,6 +555,17 @@ static inline int sbi_platform_timer_init(const struct sbi_platform *plat,
 }
 
 /**
+ * Exit the platform timer for current HART
+ *
+ * @param plat pointer to struct sbi_platform
+ */
+static inline void sbi_platform_timer_exit(const struct sbi_platform *plat)
+{
+       if (plat && sbi_platform_ops(plat)->timer_exit)
+               sbi_platform_ops(plat)->timer_exit();
+}
+
+/**
  * Reboot the platform
  *
  * @param plat pointer to struct sbi_platform
index c14c8d0..401be68 100644 (file)
@@ -24,12 +24,12 @@ void sbi_timer_set_delta(struct sbi_scratch *scratch, ulong delta);
 
 void sbi_timer_set_delta_upper(struct sbi_scratch *scratch, ulong delta_upper);
 
-void sbi_timer_event_stop(struct sbi_scratch *scratch);
-
 void sbi_timer_event_start(struct sbi_scratch *scratch, u64 next_event);
 
 void sbi_timer_process(struct sbi_scratch *scratch);
 
 int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot);
 
+void sbi_timer_exit(struct sbi_scratch *scratch);
+
 #endif
index d5d3513..2247324 100644 (file)
@@ -205,6 +205,8 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch)
 
        sbi_platform_early_exit(plat);
 
+       sbi_timer_exit(scratch);
+
        sbi_platform_final_exit(plat);
 
        sbi_hart_hang();
index 1ba386f..60ddfaa 100644 (file)
@@ -76,11 +76,6 @@ void sbi_timer_set_delta_upper(struct sbi_scratch *scratch, ulong delta_upper)
        *time_delta |= ((u64)delta_upper << 32);
 }
 
-void sbi_timer_event_stop(struct sbi_scratch *scratch)
-{
-       sbi_platform_timer_event_stop(sbi_platform_ptr(scratch));
-}
-
 void sbi_timer_event_start(struct sbi_scratch *scratch, u64 next_event)
 {
        sbi_platform_timer_event_start(sbi_platform_ptr(scratch), next_event);
@@ -113,3 +108,13 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot)
 
        return sbi_platform_timer_init(sbi_platform_ptr(scratch), cold_boot);
 }
+
+void sbi_timer_exit(struct sbi_scratch *scratch)
+{
+       sbi_platform_timer_event_stop(sbi_platform_ptr(scratch));
+
+       csr_clear(CSR_MIP, MIP_STIP);
+       csr_clear(CSR_MIE, MIP_MTIP);
+
+       sbi_platform_timer_exit(sbi_platform_ptr(scratch));
+}