lib: sbi: Update sbi_domain_is_assigned_hart() to take a hart index

This removes redundant hartid to hartindex conversions from four call
sites and provides a net reduction in code size.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Samuel Holland
2024-08-30 08:49:14 -07:00
committed by Anup Patel
parent fe153c5516
commit 9f86524b58
6 changed files with 17 additions and 15 deletions

View File

@@ -220,10 +220,10 @@ extern struct sbi_dlist domain_list;
/** /**
* Check whether given HART is assigned to specified domain * Check whether given HART is assigned to specified domain
* @param dom pointer to domain * @param dom pointer to domain
* @param hartid the HART ID * @param hartindex the HART index
* @return true if HART is assigned to domain otherwise false * @return true if HART is assigned to domain otherwise false
*/ */
bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid); bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartindex);
/** /**
* Get the assigned HART mask for given domain * Get the assigned HART mask for given domain

View File

@@ -243,10 +243,9 @@ int sbi_dbtr_setup_shmem(const struct sbi_domain *dom, unsigned long smode,
unsigned long shmem_phys_lo, unsigned long shmem_phys_lo,
unsigned long shmem_phys_hi) unsigned long shmem_phys_hi)
{ {
u32 hartid = current_hartid();
struct sbi_dbtr_hart_triggers_state *hart_state; struct sbi_dbtr_hart_triggers_state *hart_state;
if (dom && !sbi_domain_is_assigned_hart(dom, hartid)) { if (dom && !sbi_domain_is_assigned_hart(dom, current_hartindex())) {
sbi_dprintf("%s: calling hart not assigned to this domain\n", sbi_dprintf("%s: calling hart not assigned to this domain\n",
__func__); __func__);
return SBI_ERR_DENIED; return SBI_ERR_DENIED;

View File

@@ -60,7 +60,7 @@ void sbi_update_hartindex_to_domain(u32 hartindex, struct sbi_domain *dom)
sbi_scratch_write_type(scratch, void *, domain_hart_ptr_offset, dom); sbi_scratch_write_type(scratch, void *, domain_hart_ptr_offset, dom);
} }
bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid) bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartindex)
{ {
bool ret; bool ret;
struct sbi_domain *tdom = (struct sbi_domain *)dom; struct sbi_domain *tdom = (struct sbi_domain *)dom;
@@ -69,7 +69,7 @@ bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid)
return false; return false;
spin_lock(&tdom->assigned_harts_lock); spin_lock(&tdom->assigned_harts_lock);
ret = sbi_hartmask_test_hartid(hartid, &tdom->assigned_harts); ret = sbi_hartmask_test_hartindex(hartindex, &tdom->assigned_harts);
spin_unlock(&tdom->assigned_harts_lock); spin_unlock(&tdom->assigned_harts_lock);
return ret; return ret;
@@ -446,7 +446,7 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix)
sbi_hartmask_for_each_hartindex(i, dom->possible_harts) { sbi_hartmask_for_each_hartindex(i, dom->possible_harts) {
j = sbi_hartindex_to_hartid(i); j = sbi_hartindex_to_hartid(i);
sbi_printf("%s%d%s", (k++) ? "," : "", sbi_printf("%s%d%s", (k++) ? "," : "",
j, sbi_domain_is_assigned_hart(dom, j) ? "*" : ""); j, sbi_domain_is_assigned_hart(dom, i) ? "*" : "");
} }
sbi_printf("\n"); sbi_printf("\n");

View File

@@ -77,7 +77,7 @@ int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid)
{ {
u32 hartindex = sbi_hartid_to_hartindex(hartid); u32 hartindex = sbi_hartid_to_hartindex(hartid);
if (!sbi_domain_is_assigned_hart(dom, hartid)) if (!sbi_domain_is_assigned_hart(dom, hartindex))
return SBI_EINVAL; return SBI_EINVAL;
return __sbi_hsm_hart_get_state(hartindex); return __sbi_hsm_hart_get_state(hartindex);
@@ -300,6 +300,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
const struct sbi_domain *dom, const struct sbi_domain *dom,
u32 hartid, ulong saddr, ulong smode, ulong arg1) u32 hartid, ulong saddr, ulong smode, ulong arg1)
{ {
u32 hartindex = sbi_hartid_to_hartindex(hartid);
unsigned long init_count, entry_count; unsigned long init_count, entry_count;
unsigned int hstate; unsigned int hstate;
struct sbi_scratch *rscratch; struct sbi_scratch *rscratch;
@@ -309,13 +310,13 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
/* For now, we only allow start mode to be S-mode or U-mode. */ /* For now, we only allow start mode to be S-mode or U-mode. */
if (smode != PRV_S && smode != PRV_U) if (smode != PRV_S && smode != PRV_U)
return SBI_EINVAL; return SBI_EINVAL;
if (dom && !sbi_domain_is_assigned_hart(dom, hartid)) if (dom && !sbi_domain_is_assigned_hart(dom, hartindex))
return SBI_EINVAL; return SBI_EINVAL;
if (dom && !sbi_domain_check_addr(dom, saddr, smode, if (dom && !sbi_domain_check_addr(dom, saddr, smode,
SBI_DOMAIN_EXECUTE)) SBI_DOMAIN_EXECUTE))
return SBI_EINVALID_ADDR; return SBI_EINVALID_ADDR;
rscratch = sbi_hartid_to_scratch(hartid); rscratch = sbi_hartindex_to_scratch(hartindex);
if (!rscratch) if (!rscratch)
return SBI_EINVAL; return SBI_EINVAL;
@@ -355,7 +356,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
(hsm_device_has_hart_secondary_boot() && !init_count)) { (hsm_device_has_hart_secondary_boot() && !init_count)) {
rc = hsm_device_hart_start(hartid, scratch->warmboot_addr); rc = hsm_device_hart_start(hartid, scratch->warmboot_addr);
} else { } else {
rc = sbi_ipi_raw_send(sbi_hartid_to_hartindex(hartid)); rc = sbi_ipi_raw_send(hartindex);
} }
if (!rc) if (!rc)

View File

@@ -323,7 +323,7 @@ static int sse_event_set_hart_id_check(struct sbi_sse_event *e,
if (!sse_event_is_global(e)) if (!sse_event_is_global(e))
return SBI_EBAD_RANGE; return SBI_EBAD_RANGE;
if (!sbi_domain_is_assigned_hart(hd, new_hartid)) if (!sbi_domain_is_assigned_hart(hd, sbi_hartid_to_hartindex(hartid)))
return SBI_EINVAL; return SBI_EINVAL;
hstate = sbi_hsm_hart_get_state(hd, hartid); hstate = sbi_hsm_hart_get_state(hd, hartid);
@@ -810,7 +810,8 @@ int sbi_sse_disable(uint32_t event_id)
int sbi_sse_inject_from_ecall(uint32_t event_id, unsigned long hartid, int sbi_sse_inject_from_ecall(uint32_t event_id, unsigned long hartid,
struct sbi_ecall_return *out) struct sbi_ecall_return *out)
{ {
if (!sbi_domain_is_assigned_hart(sbi_domain_thishart_ptr(), hartid)) if (!sbi_domain_is_assigned_hart(sbi_domain_thishart_ptr(),
sbi_hartid_to_hartindex(hartid)))
return SBI_EINVAL; return SBI_EINVAL;
return sse_inject_event(event_id, hartid); return sse_inject_event(event_id, hartid);

View File

@@ -110,7 +110,7 @@ void fdt_cpu_fixup(void *fdt)
struct sbi_domain *dom = sbi_domain_thishart_ptr(); struct sbi_domain *dom = sbi_domain_thishart_ptr();
int err, cpu_offset, cpus_offset, len; int err, cpu_offset, cpus_offset, len;
const char *mmu_type; const char *mmu_type;
u32 hartid; u32 hartid, hartindex;
err = fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + 32); err = fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + 32);
if (err < 0) if (err < 0)
@@ -134,8 +134,9 @@ void fdt_cpu_fixup(void *fdt)
* 2. MMU is not available for the HART * 2. MMU is not available for the HART
*/ */
hartindex = sbi_hartid_to_hartindex(hartid);
mmu_type = fdt_getprop(fdt, cpu_offset, "mmu-type", &len); mmu_type = fdt_getprop(fdt, cpu_offset, "mmu-type", &len);
if (!sbi_domain_is_assigned_hart(dom, hartid) || if (!sbi_domain_is_assigned_hart(dom, hartindex) ||
!mmu_type || !len) !mmu_type || !len)
fdt_setprop_string(fdt, cpu_offset, "status", fdt_setprop_string(fdt, cpu_offset, "status",
"disabled"); "disabled");