summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sbi/sbi_ecall_interface.h5
-rw-r--r--include/sbi/sbi_hsm.h1
-rw-r--r--lib/sbi/sbi_hsm.c25
3 files changed, 31 insertions, 0 deletions
diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index 93c0747..ba88e8b 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -51,6 +51,11 @@
#define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA 0x5
#define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID 0x6
+#define SBI_HSM_HART_STATUS_STARTED 0x0
+#define SBI_HSM_HART_STATUS_STOPPED 0x1
+#define SBI_HSM_HART_STATUS_START_PENDING 0x2
+#define SBI_HSM_HART_STATUS_STOP_PENDING 0x3
+
#define SBI_SPEC_VERSION_MAJOR_OFFSET 24
#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff
diff --git a/include/sbi/sbi_hsm.h b/include/sbi/sbi_hsm.h
index 2566afb..11ea7cf 100644
--- a/include/sbi/sbi_hsm.h
+++ b/include/sbi/sbi_hsm.h
@@ -25,6 +25,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, u32 hartid,
ulong saddr, ulong priv);
int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow);
int sbi_hsm_hart_get_state(struct sbi_scratch *scratch, u32 hartid);
+int sbi_hsm_hart_state_to_status(int state);
bool sbi_hsm_hart_started(struct sbi_scratch *scratch, u32 hartid);
void sbi_hsm_prepare_next_jump(struct sbi_scratch *scratch, u32 hartid);
#endif
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
index f3207ee..36fafed 100644
--- a/lib/sbi/sbi_hsm.c
+++ b/lib/sbi/sbi_hsm.c
@@ -14,6 +14,7 @@
#include <sbi/sbi_bits.h>
#include <sbi/sbi_console.h>
#include <sbi/sbi_error.h>
+#include <sbi/sbi_ecall_interface.h>
#include <sbi/sbi_hart.h>
#include <sbi/sbi_hsm.h>
#include <sbi/sbi_init.h>
@@ -30,6 +31,30 @@ struct sbi_hsm_data {
atomic_t state;
};
+int sbi_hsm_hart_state_to_status(int state)
+{
+ int ret;
+
+ switch (state) {
+ case SBI_HART_STOPPED:
+ ret = SBI_HSM_HART_STATUS_STOPPED;
+ break;
+ case SBI_HART_STOPPING:
+ ret = SBI_HSM_HART_STATUS_STOP_PENDING;
+ break;
+ case SBI_HART_STARTING:
+ ret = SBI_HSM_HART_STATUS_START_PENDING;
+ break;
+ case SBI_HART_STARTED:
+ ret = SBI_HSM_HART_STATUS_STARTED;
+ break;
+ default:
+ ret = SBI_EINVAL;
+ }
+
+ return ret;
+}
+
int sbi_hsm_hart_get_state(struct sbi_scratch *scratch, u32 hartid)
{
struct sbi_hsm_data *hdata;