summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2020-04-24 09:56:22 +0300
committerAnup Patel <anup@brainfault.org>2020-04-27 12:05:29 +0300
commita9eac67ad019200e9a281a6fc10e394353a026f2 (patch)
treebb99209d3573cfc5a6e0a2617163a160e5e452a7
parent1bb00ab3aeabde78579774eef8eadc7b7e765924 (diff)
downloadopensbi-a9eac67ad019200e9a281a6fc10e394353a026f2.tar.xz
include: sbi_platform: Combine reboot and shutdown into one callback
We can achieve shutdown, cold reboot, and warm reboot using just one sbi_platform callback so we combine system_reboot() and system_shutdown() callbacks into one system_reset() callback. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
-rw-r--r--include/sbi/sbi_platform.h37
-rw-r--r--include/sbi/sbi_system.h4
-rw-r--r--include/sbi_utils/sys/htif.h2
-rw-r--r--lib/sbi/sbi_ecall_legacy.c3
-rw-r--r--lib/sbi/sbi_system.c34
-rw-r--r--lib/utils/sys/htif.c2
-rw-r--r--platform/andes/ae350/platform.c17
-rw-r--r--platform/fpga/ariane/platform.c19
-rw-r--r--platform/fpga/openpiton/platform.c19
-rw-r--r--platform/kendryte/k210/platform.c15
-rw-r--r--platform/qemu/virt/platform.c5
-rw-r--r--platform/sifive/fu540/platform.c5
-rw-r--r--platform/spike/platform.c3
-rw-r--r--platform/template/platform.c15
-rw-r--r--platform/thead/c910/platform.c4
15 files changed, 46 insertions, 138 deletions
diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h
index fc2913d..9eaf82e 100644
--- a/include/sbi/sbi_platform.h
+++ b/include/sbi/sbi_platform.h
@@ -146,10 +146,11 @@ struct sbi_platform_operations {
*/
int (*hart_stop)(void);
- /** Reboot the platform */
- int (*system_reboot)(u32 type);
- /** Shutdown or poweroff the platform */
- int (*system_shutdown)(u32 type);
+ /** Reset the platform */
+#define SBI_PLATFORM_RESET_SHUTDOWN 0
+#define SBI_PLATFORM_RESET_COLD 1
+#define SBI_PLATFORM_RESET_WARM 2
+ int (*system_reset)(u32 reset_type);
/** platform specific SBI extension implementation probe function */
int (*vendor_ext_check)(long extid);
@@ -686,34 +687,18 @@ static inline void sbi_platform_timer_exit(const struct sbi_platform *plat)
}
/**
- * Reboot the platform
+ * Reset the platform
*
* @param plat pointer to struct sbi_platform
- * @param type type of reboot
+ * @param reset_type type of reset
*
* @return 0 on success and negative error code on failure
*/
-static inline int sbi_platform_system_reboot(const struct sbi_platform *plat,
- u32 type)
+static inline int sbi_platform_system_reset(const struct sbi_platform *plat,
+ u32 reset_type)
{
- if (plat && sbi_platform_ops(plat)->system_reboot)
- return sbi_platform_ops(plat)->system_reboot(type);
- return 0;
-}
-
-/**
- * Shutdown or poweroff the platform
- *
- * @param plat pointer to struct sbi_platform
- * @param type type of shutdown or poweroff
- *
- * @return 0 on success and negative error code on failure
- */
-static inline int sbi_platform_system_shutdown(const struct sbi_platform *plat,
- u32 type)
-{
- if (plat && sbi_platform_ops(plat)->system_shutdown)
- return sbi_platform_ops(plat)->system_shutdown(type);
+ if (plat && sbi_platform_ops(plat)->system_reset)
+ return sbi_platform_ops(plat)->system_reset(reset_type);
return 0;
}
diff --git a/include/sbi/sbi_system.h b/include/sbi/sbi_system.h
index 8d9c18b..d44ef12 100644
--- a/include/sbi/sbi_system.h
+++ b/include/sbi/sbi_system.h
@@ -12,8 +12,6 @@
#include <sbi/sbi_types.h>
-void __noreturn sbi_system_reboot(u32 type);
-
-void __noreturn sbi_system_shutdown(u32 type);
+void __noreturn sbi_system_reset(u32 platform_reset_type);
#endif
diff --git a/include/sbi_utils/sys/htif.h b/include/sbi_utils/sys/htif.h
index 42903e8..7384b48 100644
--- a/include/sbi_utils/sys/htif.h
+++ b/include/sbi_utils/sys/htif.h
@@ -14,6 +14,6 @@ void htif_putc(char ch);
int htif_getc(void);
-int htif_system_down(u32 type);
+int htif_system_reset(u32 type);
#endif
diff --git a/lib/sbi/sbi_ecall_legacy.c b/lib/sbi/sbi_ecall_legacy.c
index 8f32027..9f7a5b6 100644
--- a/lib/sbi/sbi_ecall_legacy.c
+++ b/lib/sbi/sbi_ecall_legacy.c
@@ -15,6 +15,7 @@
#include <sbi/sbi_error.h>
#include <sbi/sbi_hsm.h>
#include <sbi/sbi_ipi.h>
+#include <sbi/sbi_platform.h>
#include <sbi/sbi_system.h>
#include <sbi/sbi_timer.h>
#include <sbi/sbi_tlb.h>
@@ -99,7 +100,7 @@ static int sbi_ecall_legacy_handler(unsigned long extid, unsigned long funcid,
}
break;
case SBI_EXT_0_1_SHUTDOWN:
- sbi_system_shutdown(0);
+ sbi_system_reset(SBI_PLATFORM_RESET_SHUTDOWN);
break;
default:
ret = SBI_ENOTSUPP;
diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c
index 5d4c7de..6f7be14 100644
--- a/lib/sbi/sbi_system.c
+++ b/lib/sbi/sbi_system.c
@@ -17,7 +17,7 @@
#include <sbi/sbi_ipi.h>
#include <sbi/sbi_init.h>
-void __noreturn sbi_system_reboot(u32 type)
+void __noreturn sbi_system_reset(u32 platform_reset_type)
{
ulong hbase = 0, hmask;
u32 cur_hartid = current_hartid();
@@ -35,34 +35,10 @@ void __noreturn sbi_system_reboot(u32 type)
/* Stop current HART */
sbi_hsm_hart_stop(scratch, FALSE);
- /* Platform specific reooot */
- sbi_platform_system_reboot(sbi_platform_ptr(scratch), type);
+ /* Platform specific reset */
+ sbi_platform_system_reset(sbi_platform_ptr(scratch),
+ platform_reset_type);
- /* If platform specific reboot did not work then do sbi_exit() */
- sbi_exit(scratch);
-}
-
-void __noreturn sbi_system_shutdown(u32 type)
-{
- ulong hbase = 0, hmask;
- u32 cur_hartid = current_hartid();
- struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
-
- /* Send HALT IPI to every hart other than the current hart */
- while (!sbi_hsm_hart_started_mask(hbase, &hmask)) {
- if (hbase <= cur_hartid)
- hmask &= ~(1UL << (cur_hartid - hbase));
- if (hmask)
- sbi_ipi_send_halt(hmask, hbase);
- hbase += BITS_PER_LONG;
- }
-
- /* Stop current HART */
- sbi_hsm_hart_stop(scratch, FALSE);
-
- /* Platform specific shutdown */
- sbi_platform_system_shutdown(sbi_platform_ptr(scratch), type);
-
- /* If platform specific shutdown did not work then do sbi_exit() */
+ /* If platform specific reset did not work then do sbi_exit() */
sbi_exit(scratch);
}
diff --git a/lib/utils/sys/htif.c b/lib/utils/sys/htif.c
index e82590f..ed800a5 100644
--- a/lib/utils/sys/htif.c
+++ b/lib/utils/sys/htif.c
@@ -140,7 +140,7 @@ int htif_getc(void)
return ch - 1;
}
-int htif_system_down(u32 type)
+int htif_system_reset(u32 type)
{
while (1) {
fromhost = 0;
diff --git a/platform/andes/ae350/platform.c b/platform/andes/ae350/platform.c
index 69a3cbc..774ea90 100644
--- a/platform/andes/ae350/platform.c
+++ b/platform/andes/ae350/platform.c
@@ -110,19 +110,11 @@ static int ae350_timer_init(bool cold_boot)
return plmt_warm_timer_init();
}
-/* Reboot the platform. */
-static int ae350_system_reboot(u32 type)
+/* Reset the platform. */
+static int ae350_system_reset(u32 type)
{
/* For now nothing to do. */
- sbi_printf("System reboot\n");
- return 0;
-}
-
-/* Shutdown or poweroff the platform. */
-static int ae350_system_shutdown(u32 type)
-{
- /* For now nothing to do. */
- sbi_printf("System shutdown\n");
+ sbi_printf("System reset\n");
return 0;
}
@@ -145,8 +137,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_event_start = plmt_timer_event_start,
.timer_event_stop = plmt_timer_event_stop,
- .system_reboot = ae350_system_reboot,
- .system_shutdown = ae350_system_shutdown
+ .system_reset = ae350_system_reset
};
const struct sbi_platform platform = {
diff --git a/platform/fpga/ariane/platform.c b/platform/fpga/ariane/platform.c
index 9537b64..7c76ff8 100644
--- a/platform/fpga/ariane/platform.c
+++ b/platform/fpga/ariane/platform.c
@@ -150,22 +150,12 @@ static int ariane_timer_init(bool cold_boot)
}
/*
- * Reboot the ariane.
+ * Reset the ariane.
*/
-static int ariane_system_reboot(u32 type)
+static int ariane_system_reset(u32 type)
{
/* For now nothing to do. */
- sbi_printf("System reboot\n");
- return 0;
-}
-
-/*
- * Shutdown or poweroff the ariane.
- */
-static int ariane_system_shutdown(u32 type)
-{
- /* For now nothing to do. */
- sbi_printf("System shutdown\n");
+ sbi_printf("System reset\n");
return 0;
}
@@ -186,8 +176,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_value = clint_timer_value,
.timer_event_start = clint_timer_event_start,
.timer_event_stop = clint_timer_event_stop,
- .system_reboot = ariane_system_reboot,
- .system_shutdown = ariane_system_shutdown
+ .system_reset = ariane_system_reset
};
const struct sbi_platform platform = {
diff --git a/platform/fpga/openpiton/platform.c b/platform/fpga/openpiton/platform.c
index 4c83f6d..019dcc5 100644
--- a/platform/fpga/openpiton/platform.c
+++ b/platform/fpga/openpiton/platform.c
@@ -182,22 +182,12 @@ static int openpiton_timer_init(bool cold_boot)
}
/*
- * Reboot the openpiton.
+ * Reset the openpiton.
*/
-static int openpiton_system_reboot(u32 type)
+static int openpiton_system_reset(u32 type)
{
/* For now nothing to do. */
- sbi_printf("System reboot\n");
- return 0;
-}
-
-/*
- * Shutdown or poweroff the openpiton.
- */
-static int openpiton_system_shutdown(u32 type)
-{
- /* For now nothing to do. */
- sbi_printf("System shutdown\n");
+ sbi_printf("System reset\n");
return 0;
}
@@ -218,8 +208,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_value = clint_timer_value,
.timer_event_start = clint_timer_event_start,
.timer_event_stop = clint_timer_event_stop,
- .system_reboot = openpiton_system_reboot,
- .system_shutdown = openpiton_system_shutdown
+ .system_reset = openpiton_system_reset
};
const struct sbi_platform platform = {
diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c
index 16ee985..69c0e21 100644
--- a/platform/kendryte/k210/platform.c
+++ b/platform/kendryte/k210/platform.c
@@ -96,18 +96,10 @@ static int k210_timer_init(bool cold_boot)
return clint_warm_timer_init();
}
-static int k210_system_reboot(u32 type)
+static int k210_system_reset(u32 type)
{
/* For now nothing to do. */
- sbi_printf("System reboot\n");
-
- return 0;
-}
-
-static int k210_system_shutdown(u32 type)
-{
- /* For now nothing to do. */
- sbi_printf("System shutdown\n");
+ sbi_printf("System reset\n");
return 0;
}
@@ -128,8 +120,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_event_stop = clint_timer_event_stop,
.timer_event_start = clint_timer_event_start,
- .system_reboot = k210_system_reboot,
- .system_shutdown = k210_system_shutdown
+ .system_reset = k210_system_reset
};
const struct sbi_platform platform = {
diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c
index 5c12f53..fd4571d 100644
--- a/platform/qemu/virt/platform.c
+++ b/platform/qemu/virt/platform.c
@@ -100,7 +100,7 @@ static int virt_timer_init(bool cold_boot)
return clint_warm_timer_init();
}
-static int virt_system_down(u32 type)
+static int virt_system_reset(u32 type)
{
/* Tell the "finisher" that the simulation
* was successful so that QEMU exits
@@ -123,8 +123,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_event_stop = clint_timer_event_stop,
.timer_event_start = clint_timer_event_start,
.timer_init = virt_timer_init,
- .system_reboot = virt_system_down,
- .system_shutdown = virt_system_down
+ .system_reset = virt_system_reset,
};
const struct sbi_platform platform = {
diff --git a/platform/sifive/fu540/platform.c b/platform/sifive/fu540/platform.c
index 3a9f4b5..aeb2f41 100644
--- a/platform/sifive/fu540/platform.c
+++ b/platform/sifive/fu540/platform.c
@@ -138,7 +138,7 @@ static u32 fu540_hart_index2id[FU540_HART_COUNT - 1] = {
[3] = 4,
};
-static int fu540_system_down(u32 type)
+static int fu540_system_reset(u32 type)
{
/* For now nothing to do. */
return 0;
@@ -158,8 +158,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_event_stop = clint_timer_event_stop,
.timer_event_start = clint_timer_event_start,
.timer_init = fu540_timer_init,
- .system_reboot = fu540_system_down,
- .system_shutdown = fu540_system_down
+ .system_reset = fu540_system_reset
};
const struct sbi_platform platform = {
diff --git a/platform/spike/platform.c b/platform/spike/platform.c
index b09e7c6..066720a 100644
--- a/platform/spike/platform.c
+++ b/platform/spike/platform.c
@@ -72,8 +72,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_event_stop = clint_timer_event_stop,
.timer_event_start = clint_timer_event_start,
.timer_init = spike_timer_init,
- .system_reboot = htif_system_down,
- .system_shutdown = htif_system_down
+ .system_reset = htif_system_reset
};
const struct sbi_platform platform = {
diff --git a/platform/template/platform.c b/platform/template/platform.c
index ef32941..84fbf56 100644
--- a/platform/template/platform.c
+++ b/platform/template/platform.c
@@ -162,17 +162,9 @@ static void platform_timer_event_stop(void)
}
/*
- * Reboot the platform.
+ * Reset the platform.
*/
-static int platform_system_reboot(u32 type)
-{
- return 0;
-}
-
-/*
- * Shutdown or poweroff the platform.
- */
-static int platform_system_shutdown(u32 type)
+static int platform_system_reset(u32 type)
{
return 0;
}
@@ -194,8 +186,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_event_stop = platform_timer_event_stop,
.timer_event_start = platform_timer_event_start,
.timer_init = platform_timer_init,
- .system_reboot = platform_system_reboot,
- .system_shutdown = platform_system_shutdown
+ .system_reset = platform_system_reset
};
const struct sbi_platform platform = {
.opensbi_version = OPENSBI_VERSION,
diff --git a/platform/thead/c910/platform.c b/platform/thead/c910/platform.c
index adb1a20..82f910a 100644
--- a/platform/thead/c910/platform.c
+++ b/platform/thead/c910/platform.c
@@ -100,7 +100,7 @@ static int c910_timer_init(bool cold_boot)
return clint_warm_timer_init();
}
-static int c910_system_shutdown(u32 type)
+static int c910_system_reset(u32 type)
{
asm volatile ("ebreak");
return 0;
@@ -127,7 +127,7 @@ const struct sbi_platform_operations platform_ops = {
.timer_init = c910_timer_init,
.timer_event_start = clint_timer_event_start,
- .system_shutdown = c910_system_shutdown,
+ .system_reset = c910_system_reset,
.hart_start = c910_hart_start,
};