#define sbi_hartid_to_scratch(__hartid) \
sbi_hartindex_to_scratch(sbi_hartid_to_hartindex(__hartid))
-/** Last HART id having a sbi_scratch pointer */
-extern u32 last_hartid_having_scratch;
-
-/** Get last HART id having a sbi_scratch pointer */
-#define sbi_scratch_last_hartid() last_hartid_having_scratch
-
/** Check whether particular HART id is valid or not */
#define sbi_hartid_valid(__hartid) \
sbi_hartindex_valid(sbi_hartid_to_hartindex(__hartid))
{
int hstate;
ulong i, hmask, dmask;
- ulong hend = sbi_scratch_last_hartid() + 1;
*out_hmask = 0;
- if (hend <= hbase)
+ if (!sbi_hartid_valid(hbase))
return SBI_EINVAL;
- if (BITS_PER_LONG < (hend - hbase))
- hend = hbase + BITS_PER_LONG;
dmask = sbi_domain_get_assigned_hartmask(dom, hbase);
- for (i = hbase; i < hend; i++) {
- hmask = 1UL << (i - hbase);
- if (dmask & hmask) {
- hstate = __sbi_hsm_hart_get_state(i);
- if (hstate == SBI_HSM_STATE_STARTED ||
- hstate == SBI_HSM_STATE_SUSPENDED)
- *out_hmask |= hmask;
- }
+ for (i = 0; i < BITS_PER_LONG; i++) {
+ hmask = 1UL << i;
+ if (!(dmask & hmask))
+ continue;
+
+ hstate = __sbi_hsm_hart_get_state(hbase + i);
+ if (hstate == SBI_HSM_STATE_STARTED ||
+ hstate == SBI_HSM_STATE_SUSPENDED)
+ *out_hmask |= hmask;
}
return 0;
return SBI_ENOMEM;
/* Initialize hart state data for every hart */
- for (i = 0; i <= sbi_scratch_last_hartid(); i++) {
- rscratch = sbi_hartid_to_scratch(i);
+ for (i = 0; i <= sbi_scratch_last_hartindex(); i++) {
+ rscratch = sbi_hartindex_to_scratch(i);
if (!rscratch)
continue;
hdata = sbi_scratch_offset_ptr(rscratch,
hart_data_offset);
ATOMIC_INIT(&hdata->state,
- (i == hartid) ?
+ (sbi_hartindex_to_hartid(i) == hartid) ?
SBI_HSM_STATE_START_PENDING :
SBI_HSM_STATE_STOPPED);
ATOMIC_INIT(&hdata->start_ticket, 0);
static void wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid)
{
+ u32 i, hartindex = sbi_hartid_to_hartindex(hartid);
+
/* Mark coldboot done */
__smp_store_release(&coldboot_done, 1);
spin_lock(&coldboot_lock);
/* Send an IPI to all HARTs waiting for coldboot */
- for (u32 i = 0; i <= sbi_scratch_last_hartid(); i++) {
- if ((i != hartid) &&
- sbi_hartmask_test_hartid(i, &coldboot_wait_hmask))
- sbi_ipi_raw_send(sbi_hartid_to_hartindex(i));
+ sbi_hartmask_for_each_hartindex(i, &coldboot_wait_hmask) {
+ if (i == hartindex)
+ continue;
+ sbi_ipi_raw_send(i);
}
/* Release coldboot lock */
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_string.h>
-u32 last_hartid_having_scratch = SBI_HARTMASK_MAX_BITS - 1;
u32 last_hartindex_having_scratch = 0;
u32 hartindex_to_hartid_table[SBI_HARTMASK_MAX_BITS + 1] = { -1U };
struct sbi_scratch *hartindex_to_scratch_table[SBI_HARTMASK_MAX_BITS + 1] = { 0 };
hartindex_to_hartid_table[i] = h;
hartindex_to_scratch_table[i] =
((hartid2scratch)scratch->hartid_to_scratch)(h, i);
- last_hartid_having_scratch = h;
}
last_hartindex_having_scratch = plat->hart_count - 1;