[RFC PATCH v4 1/4] lib: sbi_domain: Add finalize callback for per-domain state
Rahul Pathak
rahul.pathak at oss.qualcomm.com
Sun Aug 23 19:09:49 PDT 2026
Per-domain state is registered via sbi_domain_state in state_setup()
but during that time the domain memory regions are not final.
Add optional state_finalize() callback which is called
from sbi_domain_finalize for each domain after all domains are
registered and their memory regions are final.
Signed-off-by: Rahul Pathak <rahul.pathak at oss.qualcomm.com>
---
include/sbi/sbi_domain_state.h | 22 ++++++++++++++++++++++
lib/sbi/sbi_domain.c | 16 ++++++++++++++++
lib/sbi/sbi_domain_state.c | 25 +++++++++++++++++++++++++
3 files changed, 63 insertions(+)
diff --git a/include/sbi/sbi_domain_state.h b/include/sbi/sbi_domain_state.h
index 72030380..6528a95b 100644
--- a/include/sbi/sbi_domain_state.h
+++ b/include/sbi/sbi_domain_state.h
@@ -40,6 +40,18 @@ struct sbi_domain_state {
/** Optional callback to setup domain state */
int (*state_setup)(struct sbi_domain *dom,
struct sbi_domain_state *state, void *state_ptr);
+ /**
+ * Optional callback to finalize domain state
+ *
+ * Called for each domain from sbi_domain_finalize() after all
+ * domains are registered and memory regions are final.
+ *
+ * State from the domain memory regions must be setup here instead
+ * of state_setup()
+ */
+ int (*state_finalize)(struct sbi_domain *dom,
+ struct sbi_domain_state *state, void *state_ptr);
+
/** Optional callback to cleanup domain state */
void (*state_cleanup)(struct sbi_domain *dom,
struct sbi_domain_state *state, void *state_ptr);
@@ -64,6 +76,16 @@ void *sbi_domain_state_ptr(struct sbi_domain *dom, struct sbi_domain_state *stat
*/
int sbi_domain_setup_state(struct sbi_domain *dom);
+/**
+ * Finalize all domain state 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_finalize_state(struct sbi_domain *dom);
+
/**
* Cleanup all domain state for a domain
* @param dom pointer to domain
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index 79d61c54..aa85d736 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -845,6 +845,7 @@ int sbi_domain_startup(struct sbi_scratch *scratch, u32 cold_hartid)
int sbi_domain_finalize(struct sbi_scratch *scratch)
{
int rc;
+ struct sbi_domain *dom;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
/* Sanity checks */
@@ -865,6 +866,21 @@ int sbi_domain_finalize(struct sbi_scratch *scratch)
*/
domain_finalized = true;
+ /*
+ * Finalize per-domain state of each domain. Now all domains
+ * are finalized already and their memory regions are final.
+ * State which is derived from the domain memory regions is
+ * set up below.
+ */
+ sbi_domain_for_each(dom) {
+ rc = sbi_domain_finalize_state(dom);
+ if (rc) {
+ sbi_printf("%s: domain state finalize failed for %s"
+ " (error %d)\n", __func__, dom->name, rc);
+ return rc;
+ }
+ }
+
return 0;
}
diff --git a/lib/sbi/sbi_domain_state.c b/lib/sbi/sbi_domain_state.c
index 2d1f30e3..f8ccab69 100644
--- a/lib/sbi/sbi_domain_state.c
+++ b/lib/sbi/sbi_domain_state.c
@@ -84,6 +84,31 @@ int sbi_domain_setup_state(struct sbi_domain *dom)
return 0;
}
+int sbi_domain_finalize_state(struct sbi_domain *dom)
+{
+ struct sbi_domain_state *state;
+ void *state_ptr;
+ int rc;
+
+ if (!dom)
+ return SBI_EINVAL;
+
+ sbi_list_for_each_entry(state, &state_list, head) {
+ if (!state->state_finalize)
+ continue;
+
+ state_ptr = sbi_domain_state_ptr(dom, state);
+ if (!state_ptr)
+ continue;
+
+ rc = state->state_finalize(dom, state, state_ptr);
+ if (rc)
+ return rc;
+ }
+
+ return 0;
+}
+
void sbi_domain_cleanup_state(struct sbi_domain *dom)
{
struct sbi_domain_state *state;
--
2.53.0
More information about the opensbi
mailing list