summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2021-06-27 15:02:26 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2021-06-27 15:02:26 +0000
commitf51cddac0222b7a73a662718532a17752f1a3d5e (patch)
tree2d424e8b2816ffc0932af9b06969a9bc3088e023 /sys/arch
parent28f9bc811a7892b11d080ed899afeb2c6d1fb93a (diff)
Add Hart State Management functions. These will be needed to spin up
the secondary cores. From FreeBSD. ok mlarkin@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/riscv64/include/sbi.h36
-rw-r--r--sys/arch/riscv64/riscv64/sbi.c32
2 files changed, 66 insertions, 2 deletions
diff --git a/sys/arch/riscv64/include/sbi.h b/sys/arch/riscv64/include/sbi.h
index 45b4dcc4d21..70fd30f9a74 100644
--- a/sys/arch/riscv64/include/sbi.h
+++ b/sys/arch/riscv64/include/sbi.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sbi.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: sbi.h,v 1.3 2021/06/27 15:02:25 kettenis Exp $ */
/*-
* Copyright (c) 2016-2017 Ruslan Bukin <br@bsdpad.com>
@@ -68,6 +68,16 @@
#define SBI_BASE_GET_MARCHID 5
#define SBI_BASE_GET_MIMPID 6
+/* Hart State Management (HSM) Extension */
+#define SBI_EXT_ID_HSM 0x48534D
+#define SBI_HSM_HART_START 0
+#define SBI_HSM_HART_STOP 1
+#define SBI_HSM_HART_STATUS 2
+#define SBI_HSM_STATUS_STARTED 0
+#define SBI_HSM_STATUS_STOPPED 1
+#define SBI_HSM_STATUS_START_PENDING 2
+#define SBI_HSM_STATUS_STOP_PENDING 3
+
/* Legacy Extensions */
#define SBI_SET_TIMER 0
#define SBI_CONSOLE_PUTCHAR 1
@@ -130,6 +140,30 @@ sbi_probe_extension(long id)
return (SBI_CALL1(SBI_EXT_ID_BASE, SBI_BASE_PROBE_EXTENSION, id).value);
}
+/* Hart State Management extension functions. */
+
+/*
+ * Start execution on the specified hart at physical address start_addr. The
+ * register a0 will contain the hart's ID, and a1 will contain the value of
+ * priv.
+ */
+int sbi_hsm_hart_start(u_long hart, u_long start_addr, u_long priv);
+
+/*
+ * Stop execution on the current hart. Interrupts should be disabled, or this
+ * function may return.
+ */
+void sbi_hsm_hart_stop(void);
+
+/*
+ * Get the execution status of the specified hart. The status will be one of:
+ * - SBI_HSM_STATUS_STARTED
+ * - SBI_HSM_STATUS_STOPPED
+ * - SBI_HSM_STATUS_START_PENDING
+ * - SBI_HSM_STATUS_STOP_PENDING
+ */
+int sbi_hsm_hart_status(u_long hart);
+
/* Legacy extension functions. */
static __inline void
sbi_console_putchar(int ch)
diff --git a/sys/arch/riscv64/riscv64/sbi.c b/sys/arch/riscv64/riscv64/sbi.c
index 08a6cddddb3..f5ddaa30ec9 100644
--- a/sys/arch/riscv64/riscv64/sbi.c
+++ b/sys/arch/riscv64/riscv64/sbi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sbi.c,v 1.4 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: sbi.c,v 1.5 2021/06/27 15:02:25 kettenis Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -117,6 +117,36 @@ sbi_print_version(void)
printf("SBI Specification Version: %u.%u\n", major, minor);
}
+#ifdef MULTIPROCESSOR
+
+int
+sbi_hsm_hart_start(u_long hart, u_long start_addr, u_long priv)
+{
+ struct sbi_ret ret;
+
+ ret = SBI_CALL3(SBI_EXT_ID_HSM, SBI_HSM_HART_START, hart, start_addr,
+ priv);
+ return (ret.error != 0 ? (int)ret.error : 0);
+}
+
+void
+sbi_hsm_hart_stop(void)
+{
+ (void)SBI_CALL0(SBI_EXT_ID_HSM, SBI_HSM_HART_STOP);
+}
+
+int
+sbi_hsm_hart_status(u_long hart)
+{
+ struct sbi_ret ret;
+
+ ret = SBI_CALL1(SBI_EXT_ID_HSM, SBI_HSM_HART_STATUS, hart);
+
+ return (ret.error != 0 ? (int)ret.error : (int)ret.value);
+}
+
+#endif
+
void
sbi_init(void)
{