lib: sbi_domain: Rename per-domain data to per-domain state

The per-domain sbi_domain_data hold each domain
associated state like hart context in sbi_domain_context,
mpxy state in sbi_mpxy, and others like each domain backed
by the corresponding MPT (SMMPT).
DATA reads as a generic name, while every use stores state.
Rename functions and macros appropriately. There are no
functional changes.

Signed-off-by: Rahul Pathak <rahul.pathak@oss.qualcomm.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260820121309.2551296-3-rahul.pathak@oss.qualcomm.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Rahul Pathak
2026-09-05 12:53:15 +05:30
committed by Anup Patel
parent 35af7c8c7e
commit 3593a5facc
9 changed files with 261 additions and 261 deletions
+3 -3
View File
@@ -15,7 +15,7 @@
#include <sbi/sbi_types.h> #include <sbi/sbi_types.h>
#include <sbi/sbi_hartmask.h> #include <sbi/sbi_hartmask.h>
#include <sbi/sbi_domain_context.h> #include <sbi/sbi_domain_context.h>
#include <sbi/sbi_domain_data.h> #include <sbi/sbi_domain_state.h>
struct sbi_scratch; struct sbi_scratch;
@@ -189,8 +189,8 @@ static inline bool sbi_domain_memregion_is_subset(
struct sbi_domain { struct sbi_domain {
/** Node in linked list of domains */ /** Node in linked list of domains */
struct sbi_dlist node; struct sbi_dlist node;
/** Internal state of per-domain data */ /** Internal per-domain state areas */
struct sbi_domain_data_priv data_priv; struct sbi_domain_state_priv state_priv;
/** Logical index of this domain */ /** Logical index of this domain */
u32 index; u32 index;
/** HARTs assigned to this domain */ /** HARTs assigned to this domain */
-93
View File
@@ -1,93 +0,0 @@
/*
* 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
+93
View File
@@ -0,0 +1,93 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2024 Ventana Micro Systems Inc.
*/
#ifndef __SBI_DOMAIN_STATE_H__
#define __SBI_DOMAIN_STATE_H__
#include <sbi/sbi_types.h>
#include <sbi/sbi_list.h>
struct sbi_domain;
/** Maximum number of per-domain state areas */
#define SBI_DOMAIN_MAX_STATE_PTRS 32
/** Internal per-domain state areas */
struct sbi_domain_state_priv {
/** Array of per-domain state pointers indexed by state identifier */
void *idx_to_state_ptr[SBI_DOMAIN_MAX_STATE_PTRS];
};
/** Representation of a domain state */
struct sbi_domain_state {
/**
* Head is used for maintaining state list
*
* Note: initialized by domain framework
*/
struct sbi_dlist head;
/**
* Identifier which used to locate per-domain state
*
* Note: initialized by domain framework
*/
unsigned long state_idx;
/** Size of per-domain state */
unsigned long state_size;
/** Optional callback to setup domain state */
int (*state_setup)(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);
};
/**
* Get per-domain state pointer for a given domain
* @param dom pointer to domain
* @param state pointer to domain state
*
* @return per-domain state pointer
*/
void *sbi_domain_state_ptr(struct sbi_domain *dom, struct sbi_domain_state *state);
/**
* Setup 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_setup_state(struct sbi_domain *dom);
/**
* Cleanup all domain state for a domain
* @param dom pointer to domain
*
* Note: This function is used internally within domain framework.
*/
void sbi_domain_cleanup_state(struct sbi_domain *dom);
/**
* Register a domain state
* @param hndl pointer to domain state
*
* @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_state(struct sbi_domain_state *state);
/**
* Unregister a domain state
* @param hndl pointer to domain state
*
* Note: This function must be used only in cold boot path.
*/
void sbi_domain_unregister_state(struct sbi_domain_state *state);
#endif
+1 -1
View File
@@ -68,7 +68,7 @@ libsbi-objs-y += sbi_bitmap.o
libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_bitops.o
libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_console.o
libsbi-objs-y += sbi_domain_context.o libsbi-objs-y += sbi_domain_context.o
libsbi-objs-y += sbi_domain_data.o libsbi-objs-y += sbi_domain_state.o
libsbi-objs-y += sbi_domain.o libsbi-objs-y += sbi_domain.o
libsbi-objs-y += sbi_double_trap.o libsbi-objs-y += sbi_double_trap.o
libsbi-objs-y += sbi_emulate_csr.o libsbi-objs-y += sbi_emulate_csr.o
+3 -3
View File
@@ -687,10 +687,10 @@ int sbi_domain_register(struct sbi_domain *dom,
} }
} }
/* Setup data for the discovered domain */ /* Setup state for the discovered domain */
rc = sbi_domain_setup_data(dom); rc = sbi_domain_setup_state(dom);
if (rc) { if (rc) {
sbi_printf("%s: domain data setup failed for %s (error %d)\n", sbi_printf("%s: domain state setup failed for %s (error %d)\n",
__func__, dom->name, rc); __func__, dom->name, rc);
sbi_list_del(&dom->node); sbi_list_del(&dom->node);
return rc; return rc;
+7 -7
View File
@@ -64,14 +64,14 @@ struct hart_context {
bool initialized; bool initialized;
}; };
static struct sbi_domain_data dcpriv; static struct sbi_domain_state dcstate;
static inline struct hart_context *hart_context_get(struct sbi_domain *dom, static inline struct hart_context *hart_context_get(struct sbi_domain *dom,
u32 hartindex) u32 hartindex)
{ {
struct hart_context **dom_hartindex_to_context_table; struct hart_context **dom_hartindex_to_context_table;
dom_hartindex_to_context_table = sbi_domain_data_ptr(dom, &dcpriv); dom_hartindex_to_context_table = sbi_domain_state_ptr(dom, &dcstate);
if (!dom_hartindex_to_context_table || !sbi_hartindex_valid(hartindex)) if (!dom_hartindex_to_context_table || !sbi_hartindex_valid(hartindex))
return NULL; return NULL;
@@ -83,7 +83,7 @@ static void hart_context_set(struct sbi_domain *dom, u32 hartindex,
{ {
struct hart_context **dom_hartindex_to_context_table; struct hart_context **dom_hartindex_to_context_table;
dom_hartindex_to_context_table = sbi_domain_data_ptr(dom, &dcpriv); dom_hartindex_to_context_table = sbi_domain_state_ptr(dom, &dcstate);
if (!dom_hartindex_to_context_table || !sbi_hartindex_valid(hartindex)) if (!dom_hartindex_to_context_table || !sbi_hartindex_valid(hartindex))
return; return;
@@ -314,15 +314,15 @@ int sbi_domain_context_init(void)
/** /**
* Allocate per-domain and per-hart context data. * Allocate per-domain and per-hart context data.
* The data type is "struct hart_context **" whose memory space will be * The data type is "struct hart_context **" whose memory space will be
* dynamically allocated by domain_setup_data_one(). Calculate needed * dynamically allocated by domain_setup_state_one(). Calculate needed
* size of memory space here. * size of memory space here.
*/ */
dcpriv.data_size = sizeof(struct hart_context *) * sbi_hart_count(); dcstate.state_size = sizeof(struct hart_context *) * sbi_hart_count();
return sbi_domain_register_data(&dcpriv); return sbi_domain_register_state(&dcstate);
} }
void sbi_domain_context_deinit(void) void sbi_domain_context_deinit(void)
{ {
sbi_domain_unregister_data(&dcpriv); sbi_domain_unregister_state(&dcstate);
} }
-138
View File
@@ -1,138 +0,0 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2024 Ventana Micro Systems Inc.
*/
#include <sbi/sbi_bitmap.h>
#include <sbi/sbi_domain.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_heap.h>
static SBI_LIST_HEAD(data_list);
static DECLARE_BITMAP(data_idx_bmap, SBI_DOMAIN_MAX_DATA_PTRS);
void *sbi_domain_data_ptr(struct sbi_domain *dom, struct sbi_domain_data *data)
{
if (dom && data && data->data_idx < SBI_DOMAIN_MAX_DATA_PTRS)
return dom->data_priv.idx_to_data_ptr[data->data_idx];
return NULL;
}
static int domain_setup_data_one(struct sbi_domain *dom,
struct sbi_domain_data *data)
{
struct sbi_domain_data_priv *priv = &dom->data_priv;
void *data_ptr;
int rc;
if (priv->idx_to_data_ptr[data->data_idx])
return SBI_EALREADY;
data_ptr = sbi_zalloc(data->data_size);
if (!data_ptr) {
sbi_domain_cleanup_data(dom);
return SBI_ENOMEM;
}
if (data->data_setup) {
rc = data->data_setup(dom, data, data_ptr);
if (rc) {
sbi_free(data_ptr);
return rc;
}
}
priv->idx_to_data_ptr[data->data_idx] = data_ptr;
return 0;
}
static void domain_cleanup_data_one(struct sbi_domain *dom,
struct sbi_domain_data *data)
{
struct sbi_domain_data_priv *priv = &dom->data_priv;
void *data_ptr;
data_ptr = priv->idx_to_data_ptr[data->data_idx];
if (!data_ptr)
return;
if (data->data_cleanup)
data->data_cleanup(dom, data, data_ptr);
sbi_free(data_ptr);
priv->idx_to_data_ptr[data->data_idx] = NULL;
}
int sbi_domain_setup_data(struct sbi_domain *dom)
{
struct sbi_domain_data *data;
int rc;
if (!dom)
return SBI_EINVAL;
sbi_list_for_each_entry(data, &data_list, head) {
rc = domain_setup_data_one(dom, data);
if (rc) {
sbi_domain_cleanup_data(dom);
return rc;
}
}
return 0;
}
void sbi_domain_cleanup_data(struct sbi_domain *dom)
{
struct sbi_domain_data *data;
if (!dom)
return;
sbi_list_for_each_entry(data, &data_list, head)
domain_cleanup_data_one(dom, data);
}
int sbi_domain_register_data(struct sbi_domain_data *data)
{
struct sbi_domain *dom;
u32 data_idx;
int rc;
if (!data || !data->data_size)
return SBI_EINVAL;
for (data_idx = 0; data_idx < SBI_DOMAIN_MAX_DATA_PTRS; data_idx++) {
if (!bitmap_test(data_idx_bmap, data_idx))
break;
}
if (SBI_DOMAIN_MAX_DATA_PTRS <= data_idx)
return SBI_ENOSPC;
bitmap_set(data_idx_bmap, data_idx, 1);
data->data_idx = data_idx;
sbi_list_add_tail(&data->head, &data_list);
sbi_domain_for_each(dom) {
rc = domain_setup_data_one(dom, data);
if (rc) {
sbi_domain_unregister_data(data);
return rc;
}
}
return 0;
}
void sbi_domain_unregister_data(struct sbi_domain_data *data)
{
struct sbi_domain *dom;
sbi_domain_for_each(dom)
domain_cleanup_data_one(dom, data);
sbi_list_del(&data->head);
bitmap_clear(data_idx_bmap, data->data_idx, 1);
}
+138
View File
@@ -0,0 +1,138 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2024 Ventana Micro Systems Inc.
*/
#include <sbi/sbi_bitmap.h>
#include <sbi/sbi_domain.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_heap.h>
static SBI_LIST_HEAD(state_list);
static DECLARE_BITMAP(state_idx_bmap, SBI_DOMAIN_MAX_STATE_PTRS);
void *sbi_domain_state_ptr(struct sbi_domain *dom, struct sbi_domain_state *state)
{
if (dom && state && state->state_idx < SBI_DOMAIN_MAX_STATE_PTRS)
return dom->state_priv.idx_to_state_ptr[state->state_idx];
return NULL;
}
static int domain_setup_state_one(struct sbi_domain *dom,
struct sbi_domain_state *state)
{
struct sbi_domain_state_priv *priv = &dom->state_priv;
void *state_ptr;
int rc;
if (priv->idx_to_state_ptr[state->state_idx])
return SBI_EALREADY;
state_ptr = sbi_zalloc(state->state_size);
if (!state_ptr) {
sbi_domain_cleanup_state(dom);
return SBI_ENOMEM;
}
if (state->state_setup) {
rc = state->state_setup(dom, state, state_ptr);
if (rc) {
sbi_free(state_ptr);
return rc;
}
}
priv->idx_to_state_ptr[state->state_idx] = state_ptr;
return 0;
}
static void domain_cleanup_state_one(struct sbi_domain *dom,
struct sbi_domain_state *state)
{
struct sbi_domain_state_priv *priv = &dom->state_priv;
void *state_ptr;
state_ptr = priv->idx_to_state_ptr[state->state_idx];
if (!state_ptr)
return;
if (state->state_cleanup)
state->state_cleanup(dom, state, state_ptr);
sbi_free(state_ptr);
priv->idx_to_state_ptr[state->state_idx] = NULL;
}
int sbi_domain_setup_state(struct sbi_domain *dom)
{
struct sbi_domain_state *state;
int rc;
if (!dom)
return SBI_EINVAL;
sbi_list_for_each_entry(state, &state_list, head) {
rc = domain_setup_state_one(dom, state);
if (rc) {
sbi_domain_cleanup_state(dom);
return rc;
}
}
return 0;
}
void sbi_domain_cleanup_state(struct sbi_domain *dom)
{
struct sbi_domain_state *state;
if (!dom)
return;
sbi_list_for_each_entry(state, &state_list, head)
domain_cleanup_state_one(dom, state);
}
int sbi_domain_register_state(struct sbi_domain_state *state)
{
struct sbi_domain *dom;
u32 state_idx;
int rc;
if (!state || !state->state_size)
return SBI_EINVAL;
for (state_idx = 0; state_idx < SBI_DOMAIN_MAX_STATE_PTRS; state_idx++) {
if (!bitmap_test(state_idx_bmap, state_idx))
break;
}
if (SBI_DOMAIN_MAX_STATE_PTRS <= state_idx)
return SBI_ENOSPC;
bitmap_set(state_idx_bmap, state_idx, 1);
state->state_idx = state_idx;
sbi_list_add_tail(&state->head, &state_list);
sbi_domain_for_each(dom) {
rc = domain_setup_state_one(dom, state);
if (rc) {
sbi_domain_unregister_state(state);
return rc;
}
}
return 0;
}
void sbi_domain_unregister_state(struct sbi_domain_state *state)
{
struct sbi_domain *dom;
sbi_domain_for_each(dom)
domain_cleanup_state_one(dom, state);
sbi_list_del(&state->head);
bitmap_clear(state_idx_bmap, state->state_idx, 1);
}
+16 -16
View File
@@ -267,11 +267,11 @@ int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel)
} }
/** Setup per domain MPXY state data */ /** Setup per domain MPXY state data */
static int domain_mpxy_state_data_setup(struct sbi_domain *dom, static int domain_mpxy_state_setup(struct sbi_domain *dom,
struct sbi_domain_data *data, struct sbi_domain_state *state,
void *data_ptr) void *state_ptr)
{ {
struct mpxy_state **dom_hartindex_to_mpxy_state_table = data_ptr; struct mpxy_state **dom_hartindex_to_mpxy_state_table = state_ptr;
struct mpxy_state *ms; struct mpxy_state *ms;
u32 i; u32 i;
@@ -296,20 +296,20 @@ static int domain_mpxy_state_data_setup(struct sbi_domain *dom,
} }
/** Cleanup per domain MPXY state data */ /** Cleanup per domain MPXY state data */
static void domain_mpxy_state_data_cleanup(struct sbi_domain *dom, static void domain_mpxy_state_cleanup(struct sbi_domain *dom,
struct sbi_domain_data *data, struct sbi_domain_state *state,
void *data_ptr) void *state_ptr)
{ {
struct mpxy_state **dom_hartindex_to_mpxy_state_table = data_ptr; struct mpxy_state **dom_hartindex_to_mpxy_state_table = state_ptr;
u32 i; u32 i;
sbi_hartmask_for_each_hartindex(i, dom->possible_harts) sbi_hartmask_for_each_hartindex(i, dom->possible_harts)
sbi_free(dom_hartindex_to_mpxy_state_table[i]); sbi_free(dom_hartindex_to_mpxy_state_table[i]);
} }
static struct sbi_domain_data dmspriv = { static struct sbi_domain_state dmstate = {
.data_setup = domain_mpxy_state_data_setup, .state_setup = domain_mpxy_state_setup,
.data_cleanup = domain_mpxy_state_data_cleanup, .state_cleanup = domain_mpxy_state_cleanup,
}; };
/** /**
@@ -324,7 +324,7 @@ static struct mpxy_state *sbi_domain_get_mpxy_state(struct sbi_domain *dom,
{ {
struct mpxy_state **dom_hartindex_to_mpxy_state_table; struct mpxy_state **dom_hartindex_to_mpxy_state_table;
dom_hartindex_to_mpxy_state_table = sbi_domain_data_ptr(dom, &dmspriv); dom_hartindex_to_mpxy_state_table = sbi_domain_state_ptr(dom, &dmstate);
if (!dom_hartindex_to_mpxy_state_table || if (!dom_hartindex_to_mpxy_state_table ||
!sbi_hartindex_valid(hartindex)) !sbi_hartindex_valid(hartindex))
return NULL; return NULL;
@@ -339,12 +339,12 @@ int sbi_mpxy_init(struct sbi_scratch *scratch)
/** /**
* Allocate per-domain and per-hart MPXY state data. * Allocate per-domain and per-hart MPXY state data.
* The data type is "struct mpxy_state **" whose memory space will be * The data type is "struct mpxy_state **" whose memory space will be
* dynamically allocated by domain_setup_data_one() and * dynamically allocated by domain_setup_state_one() and
* domain_mpxy_state_data_setup(). Calculate needed size of memory space * domain_mpxy_state_setup(). Calculate needed size of memory space
* here. * here.
*/ */
dmspriv.data_size = sizeof(struct mpxy_state *) * sbi_hart_count(); dmstate.state_size = sizeof(struct mpxy_state *) * sbi_hart_count();
ret = sbi_domain_register_data(&dmspriv); ret = sbi_domain_register_state(&dmstate);
if (ret) if (ret)
return ret; return ret;