aboutsummaryrefslogtreecommitdiff
path: root/include/sbi
diff options
context:
space:
mode:
authorQingyu Shang <2931013282@sjtu.edu.cn>2024-03-06 19:15:58 +0800
committerAnup Patel <anup@brainfault.org>2024-03-10 10:26:42 +0530
commite11025c52d70c8a6042965d5f368ae9d14bd80d6 (patch)
tree322132ea186c12f6c7da08c0fc1855df8f741ba3 /include/sbi
parent87d8fe78653e77de33cc12b9df07fc3a202f7d49 (diff)
downloadopensbi-e11025c52d70c8a6042965d5f368ae9d14bd80d6.zip
opensbi-e11025c52d70c8a6042965d5f368ae9d14bd80d6.tar.gz
opensbi-e11025c52d70c8a6042965d5f368ae9d14bd80d6.tar.bz2
lib: sbi: Add initial domain context management support
The domain context management component in OpenSBI provides basic CPU context management routines for existing OpenSBI domain. As domain extension, it was initially designed to facilitate the suspension and resumption of domains, enabling secure domains to efficiently share CPU resources. The patch also provides an addition to the OpenSBI domain to provide updates on hart-domain assignment and declarations of contexts within the domain. Signed-off-by: Qingyu Shang <2931013282@sjtu.edu.cn> Reviewed-by: Yu Chien Peter Lin <peterlin@andestech.com> Tested-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'include/sbi')
-rw-r--r--include/sbi/sbi_domain.h6
-rwxr-xr-xinclude/sbi/sbi_domain_context.h77
2 files changed, 83 insertions, 0 deletions
diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
index c88dbac..4706cfc 100644
--- a/include/sbi/sbi_domain.h
+++ b/include/sbi/sbi_domain.h
@@ -12,6 +12,7 @@
#include <sbi/sbi_types.h>
#include <sbi/sbi_hartmask.h>
+#include <sbi/sbi_domain_context.h>
struct sbi_scratch;
@@ -176,6 +177,8 @@ struct sbi_domain {
char name[64];
/** Possible HARTs in this domain */
const struct sbi_hartmask *possible_harts;
+ /** Contexts for possible HARTs indexed by hartindex */
+ struct sbi_context *hartindex_to_context_table[SBI_HARTMASK_MAX_BITS];
/** Array of memory regions terminated by a region with order zero */
struct sbi_domain_memregion *regions;
/** HART id of the HART booting this domain */
@@ -200,6 +203,9 @@ extern struct sbi_domain root;
/** Get pointer to sbi_domain from HART index */
struct sbi_domain *sbi_hartindex_to_domain(u32 hartindex);
+/** Update HART local pointer to point to specified domain */
+void sbi_update_hartindex_to_domain(u32 hartindex, struct sbi_domain *dom);
+
/** Get pointer to sbi_domain for current HART */
#define sbi_domain_thishart_ptr() \
sbi_hartindex_to_domain(sbi_hartid_to_hartindex(current_hartid()))
diff --git a/include/sbi/sbi_domain_context.h b/include/sbi/sbi_domain_context.h
new file mode 100755
index 0000000..edba764
--- /dev/null
+++ b/include/sbi/sbi_domain_context.h
@@ -0,0 +1,77 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) IPADS@SJTU 2023. All rights reserved.
+ */
+
+#ifndef __SBI_DOMAIN_CONTEXT_H__
+#define __SBI_DOMAIN_CONTEXT_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi/sbi_trap.h>
+#include <sbi/sbi_domain.h>
+
+/** Context representation for a hart within a domain */
+struct sbi_context {
+ /** Trap-related states such as GPRs, mepc, and mstatus */
+ struct sbi_trap_regs regs;
+
+ /** Supervisor status register */
+ unsigned long sstatus;
+ /** Supervisor interrupt enable register */
+ unsigned long sie;
+ /** Supervisor trap vector base address register */
+ unsigned long stvec;
+ /** Supervisor scratch register for temporary storage */
+ unsigned long sscratch;
+ /** Supervisor exception program counter register */
+ unsigned long sepc;
+ /** Supervisor cause register */
+ unsigned long scause;
+ /** Supervisor trap value register */
+ unsigned long stval;
+ /** Supervisor interrupt pending register */
+ unsigned long sip;
+ /** Supervisor address translation and protection register */
+ unsigned long satp;
+ /** Counter-enable register */
+ unsigned long scounteren;
+ /** Supervisor environment configuration register */
+ unsigned long senvcfg;
+
+ /** Reference to the owning domain */
+ struct sbi_domain *dom;
+ /** Previous context (caller) to jump to during context exits */
+ struct sbi_context *prev_ctx;
+ /** Is context initialized and runnable */
+ bool initialized;
+};
+
+/** Get the context pointer for a given hart index and domain */
+#define sbi_hartindex_to_domain_context(__hartindex, __d) \
+ (__d)->hartindex_to_context_table[__hartindex]
+
+/** Macro to obtain the current hart's context pointer */
+#define sbi_domain_context_thishart_ptr() \
+ sbi_hartindex_to_domain_context( \
+ sbi_hartid_to_hartindex(current_hartid()), \
+ sbi_domain_thishart_ptr())
+
+/**
+ * Enter a specific domain context synchronously
+ * @param dom pointer to domain
+ *
+ * @return 0 on success and negative error code on failure
+ */
+int sbi_domain_context_enter(struct sbi_domain *dom);
+
+/**
+ * Exit the current domain context, and then return to the caller
+ * of sbi_domain_context_enter or attempt to start the next domain
+ * context to be initialized
+ *
+ * @return 0 on success and negative error code on failure
+ */
+int sbi_domain_context_exit(void);
+
+#endif // __SBI_DOMAIN_CONTEXT_H__