summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2018-12-21 07:39:33 +0300
committerAnup Patel <anup@brainfault.org>2018-12-21 07:39:33 +0300
commit6f02b6938f8e607d38ee8de5a59581d554af0d3f (patch)
treeedcac6ee2fd3eff80d9d9fedd40070e24ed8c453 /lib
parentb023176c17e655f9371df65f6fddc0c1bcbb1fc7 (diff)
downloadopensbi-6f02b6938f8e607d38ee8de5a59581d554af0d3f.tar.xz
lib: Introduce bitmap to track HARTs waiting for coldboot
On QEMU Virt, max supported HARTs are 8 but number of HARTs actually depend on "-smp" command-line parameter passed to QEMU. This creates problems in sbi_hart_wake_coldboot_harts() because when number of HARTs are less than 8. To tackle this, we introduce a bitmap to track HARTs waiting for coldboot to finish. We wake only those HARTs who have set their bit in coldboot bitmap. Signed-off-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi_hart.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c
index fd6d4d4..5b26aea 100644
--- a/lib/sbi_hart.c
+++ b/lib/sbi_hart.c
@@ -263,7 +263,9 @@ struct sbi_scratch *sbi_hart_id_to_scratch(struct sbi_scratch *scratch,
return ((h2s)scratch->hartid_to_scratch)(hartid);
}
-#define NO_HOTPLUG_BITMAP_SIZE __riscv_xlen
+#define COLDBOOT_WAIT_BITMAP_SIZE __riscv_xlen
+static spinlock_t coldboot_wait_bitmap_lock = SPIN_LOCK_INITIALIZER;
+static unsigned long coldboot_wait_bitmap = 0;
void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid)
{
@@ -271,13 +273,20 @@ void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid)
struct sbi_platform *plat = sbi_platform_ptr(scratch);
if ((sbi_platform_hart_count(plat) <= hartid) ||
- (NO_HOTPLUG_BITMAP_SIZE <= hartid))
+ (COLDBOOT_WAIT_BITMAP_SIZE <= hartid))
sbi_hart_hang();
do {
+ spin_lock(&coldboot_wait_bitmap_lock);
+ coldboot_wait_bitmap |= (1UL << hartid);
+ spin_unlock(&coldboot_wait_bitmap_lock);
+
wfi();
mipval = csr_read(mip);
- /* Make sure the hart woke because of ipi */
- } while (!(mipval && MIP_MSIP) );
+
+ spin_lock(&coldboot_wait_bitmap_lock);
+ coldboot_wait_bitmap &= ~(1UL << hartid);
+ spin_unlock(&coldboot_wait_bitmap_lock);
+ } while (!(mipval && MIP_MSIP));
csr_clear(mip, MIP_MSIP);
}
@@ -289,7 +298,9 @@ void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid)
for(int i = 0; i < max_hart ; i++) {
/* send an IPI to every other hart */
- if (i != hartid)
+ spin_lock(&coldboot_wait_bitmap_lock);
+ if ((i != hartid) && (coldboot_wait_bitmap & (1UL << i)))
sbi_platform_ipi_inject(plat, i, hartid);
+ spin_unlock(&coldboot_wait_bitmap_lock);
}
}