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

This removes some hartindex conversions in sbi_system_suspend(), but is
mostly intended to support refactoring sbi_hsm_hart_interruptible_mask()
to work exclusively with struct sbi_hartmask.

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:12 -07:00
committed by Anup Patel
parent 97b8038916
commit ebe0f31446
3 changed files with 13 additions and 10 deletions

View File

@@ -72,7 +72,7 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type,
ulong raddr, ulong rmode, ulong arg1); ulong raddr, ulong rmode, ulong arg1);
bool sbi_hsm_hart_change_state(struct sbi_scratch *scratch, long oldstate, bool sbi_hsm_hart_change_state(struct sbi_scratch *scratch, long oldstate,
long newstate); long newstate);
int __sbi_hsm_hart_get_state(u32 hartid); int __sbi_hsm_hart_get_state(u32 hartindex);
int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid); int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid);
int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom, int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom,
ulong hbase, ulong *out_hmask); ulong hbase, ulong *out_hmask);

View File

@@ -60,12 +60,12 @@ bool sbi_hsm_hart_change_state(struct sbi_scratch *scratch, long oldstate,
return __sbi_hsm_hart_change_state(hdata, oldstate, newstate); return __sbi_hsm_hart_change_state(hdata, oldstate, newstate);
} }
int __sbi_hsm_hart_get_state(u32 hartid) int __sbi_hsm_hart_get_state(u32 hartindex)
{ {
struct sbi_hsm_data *hdata; struct sbi_hsm_data *hdata;
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 SBI_EINVAL; return SBI_EINVAL;
@@ -75,10 +75,12 @@ int __sbi_hsm_hart_get_state(u32 hartid)
int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid) int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid)
{ {
u32 hartindex = sbi_hartid_to_hartindex(hartid);
if (!sbi_domain_is_assigned_hart(dom, hartid)) if (!sbi_domain_is_assigned_hart(dom, hartid))
return SBI_EINVAL; return SBI_EINVAL;
return __sbi_hsm_hart_get_state(hartid); return __sbi_hsm_hart_get_state(hartindex);
} }
/* /*
@@ -120,6 +122,7 @@ int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom,
{ {
int hstate; int hstate;
ulong i, hmask, dmask; ulong i, hmask, dmask;
u32 hartindex;
*out_hmask = 0; *out_hmask = 0;
if (!sbi_hartid_valid(hbase)) if (!sbi_hartid_valid(hbase))
@@ -131,7 +134,8 @@ int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom,
if (!(dmask & hmask)) if (!(dmask & hmask))
continue; continue;
hstate = __sbi_hsm_hart_get_state(hbase + i); hartindex = sbi_hartid_to_hartindex(hbase + i);
hstate = __sbi_hsm_hart_get_state(hartindex);
if (hstate == SBI_HSM_STATE_STARTED || if (hstate == SBI_HSM_STATE_STARTED ||
hstate == SBI_HSM_STATE_SUSPENDED || hstate == SBI_HSM_STATE_SUSPENDED ||
hstate == SBI_HSM_STATE_RESUME_PENDING) hstate == SBI_HSM_STATE_RESUME_PENDING)

View File

@@ -142,9 +142,9 @@ int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque)
struct sbi_domain *dom = sbi_domain_thishart_ptr(); struct sbi_domain *dom = sbi_domain_thishart_ptr();
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr; void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr;
unsigned int hartid = current_hartid(); unsigned int hartindex = current_hartindex();
unsigned long prev_mode; unsigned long prev_mode;
unsigned long i, j; unsigned long i;
int ret; int ret;
if (!dom || !dom->system_suspend_allowed) if (!dom || !dom->system_suspend_allowed)
@@ -163,9 +163,8 @@ int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque)
return SBI_EFAIL; return SBI_EFAIL;
spin_lock(&dom->assigned_harts_lock); spin_lock(&dom->assigned_harts_lock);
sbi_hartmask_for_each_hartindex(j, &dom->assigned_harts) { sbi_hartmask_for_each_hartindex(i, &dom->assigned_harts) {
i = sbi_hartindex_to_hartid(j); if (i == hartindex)
if (i == hartid)
continue; continue;
if (__sbi_hsm_hart_get_state(i) != SBI_HSM_STATE_STOPPED) { if (__sbi_hsm_hart_get_state(i) != SBI_HSM_STATE_STOPPED) {
spin_unlock(&dom->assigned_harts_lock); spin_unlock(&dom->assigned_harts_lock);