mirror of
https://github.com/Fishwaldo/opensbi.git
synced 2025-07-07 13:39:00 +00:00
lib: sbi: Maximize the use of HART index in sbi_domain
Let us maximize the use of HART index in sbi_domain because hartindex based hartmask access and sbi_scratch lookup is faster. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
This commit is contained in:
parent
22d6ff8675
commit
112daa2e64
2 changed files with 33 additions and 29 deletions
|
@ -201,12 +201,12 @@ struct sbi_domain {
|
||||||
/** The root domain instance */
|
/** The root domain instance */
|
||||||
extern struct sbi_domain root;
|
extern struct sbi_domain root;
|
||||||
|
|
||||||
/** Get pointer to sbi_domain from HART id */
|
/** Get pointer to sbi_domain from HART index */
|
||||||
struct sbi_domain *sbi_hartid_to_domain(u32 hartid);
|
struct sbi_domain *sbi_hartindex_to_domain(u32 hartindex);
|
||||||
|
|
||||||
/** Get pointer to sbi_domain for current HART */
|
/** Get pointer to sbi_domain for current HART */
|
||||||
#define sbi_domain_thishart_ptr() \
|
#define sbi_domain_thishart_ptr() \
|
||||||
sbi_hartid_to_domain(current_hartid())
|
sbi_hartindex_to_domain(sbi_hartid_to_hartindex(current_hartid()))
|
||||||
|
|
||||||
/** Index to domain table */
|
/** Index to domain table */
|
||||||
extern struct sbi_domain *domidx_to_domain_table[];
|
extern struct sbi_domain *domidx_to_domain_table[];
|
||||||
|
|
|
@ -40,22 +40,22 @@ struct sbi_domain root = {
|
||||||
|
|
||||||
static unsigned long domain_hart_ptr_offset;
|
static unsigned long domain_hart_ptr_offset;
|
||||||
|
|
||||||
struct sbi_domain *sbi_hartid_to_domain(u32 hartid)
|
struct sbi_domain *sbi_hartindex_to_domain(u32 hartindex)
|
||||||
{
|
{
|
||||||
struct sbi_scratch *scratch;
|
struct sbi_scratch *scratch;
|
||||||
|
|
||||||
scratch = sbi_hartid_to_scratch(hartid);
|
scratch = sbi_hartindex_to_scratch(hartindex);
|
||||||
if (!scratch || !domain_hart_ptr_offset)
|
if (!scratch || !domain_hart_ptr_offset)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return sbi_scratch_read_type(scratch, void *, domain_hart_ptr_offset);
|
return sbi_scratch_read_type(scratch, void *, domain_hart_ptr_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_hartid_to_domain(u32 hartid, struct sbi_domain *dom)
|
static void update_hartindex_to_domain(u32 hartindex, struct sbi_domain *dom)
|
||||||
{
|
{
|
||||||
struct sbi_scratch *scratch;
|
struct sbi_scratch *scratch;
|
||||||
|
|
||||||
scratch = sbi_hartid_to_scratch(hartid);
|
scratch = sbi_hartindex_to_scratch(hartindex);
|
||||||
if (!scratch)
|
if (!scratch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -268,10 +268,11 @@ static int sanitize_domain(const struct sbi_platform *plat,
|
||||||
__func__, dom->name);
|
__func__, dom->name);
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
}
|
}
|
||||||
sbi_hartmask_for_each_hart(i, j, dom->possible_harts) {
|
sbi_hartmask_for_each_hartindex(i, dom->possible_harts) {
|
||||||
if (!sbi_hartid_valid(i)) {
|
if (!sbi_hartindex_valid(i)) {
|
||||||
sbi_printf("%s: %s possible HART mask has invalid "
|
sbi_printf("%s: %s possible HART mask has invalid "
|
||||||
"hart %d\n", __func__, dom->name, i);
|
"hart %d\n", __func__,
|
||||||
|
dom->name, sbi_hartindex_to_hartid(i));
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,9 +405,11 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix)
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
sbi_printf("Domain%d HARTs %s: ", dom->index, suffix);
|
sbi_printf("Domain%d HARTs %s: ", dom->index, suffix);
|
||||||
sbi_hartmask_for_each_hart(i, j, dom->possible_harts)
|
sbi_hartmask_for_each_hartindex(i, dom->possible_harts) {
|
||||||
|
j = sbi_hartindex_to_hartid(i);
|
||||||
sbi_printf("%s%d%s", (k++) ? "," : "",
|
sbi_printf("%s%d%s", (k++) ? "," : "",
|
||||||
i, sbi_domain_is_assigned_hart(dom, i) ? "*" : "");
|
j, sbi_domain_is_assigned_hart(dom, j) ? "*" : "");
|
||||||
|
}
|
||||||
sbi_printf("\n");
|
sbi_printf("\n");
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -487,7 +490,7 @@ void sbi_domain_dump_all(const char *suffix)
|
||||||
int sbi_domain_register(struct sbi_domain *dom,
|
int sbi_domain_register(struct sbi_domain *dom,
|
||||||
const struct sbi_hartmask *assign_mask)
|
const struct sbi_hartmask *assign_mask)
|
||||||
{
|
{
|
||||||
u32 i, j;
|
u32 i;
|
||||||
int rc;
|
int rc;
|
||||||
struct sbi_domain *tdom;
|
struct sbi_domain *tdom;
|
||||||
u32 cold_hartid = current_hartid();
|
u32 cold_hartid = current_hartid();
|
||||||
|
@ -530,22 +533,22 @@ int sbi_domain_register(struct sbi_domain *dom,
|
||||||
sbi_hartmask_clear_all(&dom->assigned_harts);
|
sbi_hartmask_clear_all(&dom->assigned_harts);
|
||||||
|
|
||||||
/* Assign domain to HART if HART is a possible HART */
|
/* Assign domain to HART if HART is a possible HART */
|
||||||
sbi_hartmask_for_each_hart(i, j, assign_mask) {
|
sbi_hartmask_for_each_hartindex(i, assign_mask) {
|
||||||
if (!sbi_hartmask_test_hartid(i, dom->possible_harts))
|
if (!sbi_hartmask_test_hartindex(i, dom->possible_harts))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tdom = sbi_hartid_to_domain(i);
|
tdom = sbi_hartindex_to_domain(i);
|
||||||
if (tdom)
|
if (tdom)
|
||||||
sbi_hartmask_clear_hartid(i,
|
sbi_hartmask_clear_hartindex(i,
|
||||||
&tdom->assigned_harts);
|
&tdom->assigned_harts);
|
||||||
update_hartid_to_domain(i, dom);
|
update_hartindex_to_domain(i, dom);
|
||||||
sbi_hartmask_set_hartid(i, &dom->assigned_harts);
|
sbi_hartmask_set_hartindex(i, &dom->assigned_harts);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If cold boot HART is assigned to this domain then
|
* If cold boot HART is assigned to this domain then
|
||||||
* override boot HART of this domain.
|
* override boot HART of this domain.
|
||||||
*/
|
*/
|
||||||
if (i == cold_hartid &&
|
if (sbi_hartindex_to_hartid(i) == cold_hartid &&
|
||||||
dom->boot_hartid != cold_hartid) {
|
dom->boot_hartid != cold_hartid) {
|
||||||
sbi_printf("Domain%d Boot HARTID forced to"
|
sbi_printf("Domain%d Boot HARTID forced to"
|
||||||
" %d\n", dom->index, cold_hartid);
|
" %d\n", dom->index, cold_hartid);
|
||||||
|
@ -665,36 +668,37 @@ int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid)
|
||||||
|
|
||||||
/* Startup boot HART of domains */
|
/* Startup boot HART of domains */
|
||||||
sbi_domain_for_each(i, dom) {
|
sbi_domain_for_each(i, dom) {
|
||||||
/* Domain boot HART */
|
/* Domain boot HART index */
|
||||||
dhart = dom->boot_hartid;
|
dhart = sbi_hartid_to_hartindex(dom->boot_hartid);
|
||||||
|
|
||||||
/* Ignore of boot HART is off limits */
|
/* Ignore of boot HART is off limits */
|
||||||
if (SBI_HARTMASK_MAX_BITS <= dhart)
|
if (!sbi_hartindex_valid(dhart))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Ignore if boot HART not possible for this domain */
|
/* Ignore if boot HART not possible for this domain */
|
||||||
if (!sbi_hartmask_test_hartid(dhart, dom->possible_harts))
|
if (!sbi_hartmask_test_hartindex(dhart, dom->possible_harts))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Ignore if boot HART assigned different domain */
|
/* Ignore if boot HART assigned different domain */
|
||||||
if (sbi_hartid_to_domain(dhart) != dom ||
|
if (sbi_hartindex_to_domain(dhart) != dom ||
|
||||||
!sbi_hartmask_test_hartid(dhart, &dom->assigned_harts))
|
!sbi_hartmask_test_hartindex(dhart, &dom->assigned_harts))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Startup boot HART of domain */
|
/* Startup boot HART of domain */
|
||||||
if (dhart == cold_hartid) {
|
if (dom->boot_hartid == cold_hartid) {
|
||||||
scratch->next_addr = dom->next_addr;
|
scratch->next_addr = dom->next_addr;
|
||||||
scratch->next_mode = dom->next_mode;
|
scratch->next_mode = dom->next_mode;
|
||||||
scratch->next_arg1 = dom->next_arg1;
|
scratch->next_arg1 = dom->next_arg1;
|
||||||
} else {
|
} else {
|
||||||
rc = sbi_hsm_hart_start(scratch, NULL, dhart,
|
rc = sbi_hsm_hart_start(scratch, NULL,
|
||||||
|
dom->boot_hartid,
|
||||||
dom->next_addr,
|
dom->next_addr,
|
||||||
dom->next_mode,
|
dom->next_mode,
|
||||||
dom->next_arg1);
|
dom->next_arg1);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
sbi_printf("%s: failed to start boot HART %d"
|
sbi_printf("%s: failed to start boot HART %d"
|
||||||
" for %s (error %d)\n", __func__,
|
" for %s (error %d)\n", __func__,
|
||||||
dhart, dom->name, rc);
|
dom->boot_hartid, dom->name, rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue