aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/kernel/arch.h
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-08-04 20:50:41 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2023-08-04 20:50:41 +0300
commite16f5f81dfb2e97a554ec19b941ec05a7942fd2d (patch)
tree46f0609b5be009d4d1057fa02ece4461732941e0 /arch/riscv64/kernel/arch.h
parent5f30284181fcfe5b16dfb94d4fba9a9ed4a2dc6a (diff)
downloadkmi-e16f5f81dfb2e97a554ec19b941ec05a7942fd2d.tar.gz
kmi-e16f5f81dfb2e97a554ec19b941ec05a7942fd2d.zip
add initial smp bringup
Diffstat (limited to 'arch/riscv64/kernel/arch.h')
-rw-r--r--arch/riscv64/kernel/arch.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/arch/riscv64/kernel/arch.h b/arch/riscv64/kernel/arch.h
new file mode 100644
index 0000000..d38dad0
--- /dev/null
+++ b/arch/riscv64/kernel/arch.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: copyleft-next-0.3.1 */
+/* Copyright 2023, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */
+
+/**
+ * @file arch.h
+ *
+ * Random tools common to riscv.
+ */
+
+#ifndef KMI_RISCV_ARCH_H
+#define KMI_RISCV_ARCH_H
+
+#include <kmi/vmem.h>
+
+/** Actual map of cpu id to hart id. */
+extern id_t __cpuid_to_hartid[MAX_CPUS];
+
+/**
+ * Map cpu id to hart id.
+ * Defined as a macro to allow for stuff like
+ * @code
+ * cpuid_to_hartid(0) = 20;
+ * @endcode
+ *
+ * @param x Hart ID.
+ */
+#define cpuid_to_hartid(x) __cpuid_to_hartid[x]
+
+/**
+ * Find the cpu id that corresponds to hart id.
+ *
+ * @param hart Hart to find corresponding cpu id for.
+ * @return Corresponding cpu id. 0 if not found, though this should maybe be a
+ * panic situation.
+ */
+id_t hartid_to_cpuid(id_t hart);
+
+/**
+ * Format branch and mode information into something that can be written to
+ * SATP.
+ *
+ * @param branch Top branch of virtual memory.
+ * @param mode Mode to use. Sv32/Sv39/etc.
+ * @return Corresponding SATP value.
+ */
+pm_t branch_to_satp(struct vmem *branch, enum mm_mode mode);
+
+#endif /* KMI_RISCV_ARCH_H */