summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnup Patel <[email protected]>2024-09-23 10:00:51 +0530
committerAnup Patel <[email protected]>2024-10-25 23:00:07 +0530
commit81d79913a0c23d7acc38ade7e8d8e3d48a388a3f (patch)
treec8798d746b8bcf0b79b332c2052b5caaf2b184a2 /include
parent65d4e9be95294c04a9a6b1be9215e9d571aba479 (diff)
lib: sbi: Introduce domain data
Different parts of OpenSBI require their own per-domain data so introduce domain data (or sbi_domain_data) which can be registered by any part of OpenSBI. Using the domain data, the domain framework will create a data pointer for every domain which can be used to maintain some per-domain state. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Yu Chien Peter Lin <[email protected]>
Diffstat (limited to 'include')
-rw-r--r--include/sbi/sbi_domain.h3
-rw-r--r--include/sbi/sbi_domain_data.h93
2 files changed, 96 insertions, 0 deletions
diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
index fc349820..cf09344f 100644
--- a/include/sbi/sbi_domain.h
+++ b/include/sbi/sbi_domain.h
@@ -15,6 +15,7 @@
#include <sbi/sbi_types.h>
#include <sbi/sbi_hartmask.h>
#include <sbi/sbi_domain_context.h>
+#include <sbi/sbi_domain_data.h>
struct sbi_scratch;
@@ -163,6 +164,8 @@ struct sbi_domain_memregion {
struct sbi_domain {
/** Node in linked list of domains */
struct sbi_dlist node;
+ /** Internal state of per-domain data */
+ struct sbi_domain_data_priv data_priv;
/** Logical index of this domain */
u32 index;
/** HARTs assigned to this domain */
diff --git a/include/sbi/sbi_domain_data.h b/include/sbi/sbi_domain_data.h
new file mode 100644
index 00000000..7eeafdce
--- /dev/null
+++ b/include/sbi/sbi_domain_data.h
@@ -0,0 +1,93 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ */
+
+#ifndef __SBI_DOMAIN_DATA_H__
+#define __SBI_DOMAIN_DATA_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi/sbi_list.h>
+
+struct sbi_domain;
+
+/** Maximum domain data per-domain */
+#define SBI_DOMAIN_MAX_DATA_PTRS 32
+
+/** Representation of per-domain data */
+struct sbi_domain_data_priv {
+ /** Array of domain data pointers indexed by domain data identifier */
+ void *idx_to_data_ptr[SBI_DOMAIN_MAX_DATA_PTRS];
+};
+
+/** Representation of a domain data */
+struct sbi_domain_data {
+ /**
+ * Head is used for maintaining data list
+ *
+ * Note: initialized by domain framework
+ */
+ struct sbi_dlist head;
+ /**
+ * Identifier which used to locate per-domain data
+ *
+ * Note: initialized by domain framework
+ */
+ unsigned long data_idx;
+ /** Size of per-domain data */
+ unsigned long data_size;
+ /** Optional callback to setup domain data */
+ int (*data_setup)(struct sbi_domain *dom,
+ struct sbi_domain_data *data, void *data_ptr);
+ /** Optional callback to cleanup domain data */
+ void (*data_cleanup)(struct sbi_domain *dom,
+ struct sbi_domain_data *data, void *data_ptr);
+};
+
+/**
+ * Get per-domain data pointer for a given domain
+ * @param dom pointer to domain
+ * @param data pointer to domain data
+ *
+ * @return per-domain data pointer
+ */
+void *sbi_domain_data_ptr(struct sbi_domain *dom, struct sbi_domain_data *data);
+
+/**
+ * Setup all domain data for a domain
+ * @param dom pointer to domain
+ *
+ * @return 0 on success and negative error code on failure
+ *
+ * Note: This function is used internally within domain framework.
+ */
+int sbi_domain_setup_data(struct sbi_domain *dom);
+
+/**
+ * Cleanup all domain data for a domain
+ * @param dom pointer to domain
+ *
+ * Note: This function is used internally within domain framework.
+ */
+void sbi_domain_cleanup_data(struct sbi_domain *dom);
+
+/**
+ * Register a domain data
+ * @param hndl pointer to domain data
+ *
+ * @return 0 on success and negative error code on failure
+ *
+ * Note: This function must be used only in cold boot path.
+ */
+int sbi_domain_register_data(struct sbi_domain_data *data);
+
+/**
+ * Unregister a domain data
+ * @param hndl pointer to domain data
+ *
+ * Note: This function must be used only in cold boot path.
+ */
+void sbi_domain_unregister_data(struct sbi_domain_data *data);
+
+#endif