aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2020-03-02 16:50:01 +0530
committerAnup Patel <anup@brainfault.org>2020-03-11 15:30:00 +0530
commit71d2b837c46e7528ab03bd6489fec86100681f22 (patch)
tree570c2000c3340cd3a35a66f3560bf06d7c8a4817
parentd96316481dbc9a52e7e97c4cef70957507c2845f (diff)
lib: Move all coldboot wait APIs to sbi_init.c
The coldboot wait APIs are only used by sbi_init.c so no point in having coldboot related code in sbi_hart.c. As per-above rationale, we move all coldboot wait related APIs to sbi_init.c as static/local functions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
-rw-r--r--include/sbi/sbi_hart.h4
-rw-r--r--lib/sbi/sbi_hart.c70
-rw-r--r--lib/sbi/sbi_init.c72
3 files changed, 70 insertions, 76 deletions
diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
index d88c7de..2ec614d 100644
--- a/include/sbi/sbi_hart.h
+++ b/include/sbi/sbi_hart.h
@@ -41,10 +41,6 @@ void sbi_hart_unmark_available(u32 hartid);
struct sbi_scratch *sbi_hart_id_to_scratch(struct sbi_scratch *scratch,
u32 hartid);
-void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid);
-
-void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid);
-
u32 sbi_current_hartid(void);
#endif
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index c00e16a..9017db1 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -377,73 +377,3 @@ struct sbi_scratch *sbi_hart_id_to_scratch(struct sbi_scratch *scratch,
{
return ((h2s)scratch->hartid_to_scratch)(hartid);
}
-
-#define COLDBOOT_WAIT_BITMAP_SIZE __riscv_xlen
-static spinlock_t coldboot_lock = SPIN_LOCK_INITIALIZER;
-static unsigned long coldboot_done = 0;
-static unsigned long coldboot_wait_bitmap = 0;
-
-void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid)
-{
- unsigned long saved_mie, cmip;
- const struct sbi_platform *plat = sbi_platform_ptr(scratch);
-
- if ((sbi_platform_hart_count(plat) <= hartid) ||
- (COLDBOOT_WAIT_BITMAP_SIZE <= hartid))
- sbi_hart_hang();
-
- /* Save MIE CSR */
- saved_mie = csr_read(CSR_MIE);
-
- /* Set MSIE bit to receive IPI */
- csr_set(CSR_MIE, MIP_MSIP);
-
- /* Acquire coldboot lock */
- spin_lock(&coldboot_lock);
-
- /* Mark current HART as waiting */
- coldboot_wait_bitmap |= (1UL << hartid);
-
- /* Wait for coldboot to finish using WFI */
- while (!coldboot_done) {
- spin_unlock(&coldboot_lock);
- do {
- wfi();
- cmip = csr_read(CSR_MIP);
- } while (!(cmip & MIP_MSIP));
- spin_lock(&coldboot_lock);
- };
-
- /* Unmark current HART as waiting */
- coldboot_wait_bitmap &= ~(1UL << hartid);
-
- /* Release coldboot lock */
- spin_unlock(&coldboot_lock);
-
- /* Restore MIE CSR */
- csr_write(CSR_MIE, saved_mie);
-
- /* Clear current HART IPI */
- sbi_platform_ipi_clear(plat, hartid);
-}
-
-void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid)
-{
- const struct sbi_platform *plat = sbi_platform_ptr(scratch);
- int max_hart = sbi_platform_hart_count(plat);
-
- /* Acquire coldboot lock */
- spin_lock(&coldboot_lock);
-
- /* Mark coldboot done */
- coldboot_done = 1;
-
- /* Send an IPI to all HARTs waiting for coldboot */
- for (int i = 0; i < max_hart; i++) {
- if ((i != hartid) && (coldboot_wait_bitmap & (1UL << i)))
- sbi_platform_ipi_send(plat, i);
- }
-
- /* Release coldboot lock */
- spin_unlock(&coldboot_lock);
-}
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index 9a9e433..5179c00 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -9,6 +9,7 @@
#include <sbi/riscv_asm.h>
#include <sbi/riscv_atomic.h>
+#include <sbi/riscv_locks.h>
#include <sbi/sbi_console.h>
#include <sbi/sbi_ecall.h>
#include <sbi/sbi_hart.h>
@@ -74,6 +75,73 @@ static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid)
sbi_hart_pmp_dump(scratch);
}
+#define COLDBOOT_WAIT_BITMAP_SIZE __riscv_xlen
+static spinlock_t coldboot_lock = SPIN_LOCK_INITIALIZER;
+static unsigned long coldboot_done = 0;
+static unsigned long coldboot_wait_bitmap = 0;
+
+static void wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid)
+{
+ unsigned long saved_mie;
+ const struct sbi_platform *plat = sbi_platform_ptr(scratch);
+
+ if ((sbi_platform_hart_count(plat) <= hartid) ||
+ (COLDBOOT_WAIT_BITMAP_SIZE <= hartid))
+ sbi_hart_hang();
+
+ /* Save MIE CSR */
+ saved_mie = csr_read(CSR_MIE);
+
+ /* Set MSIE bit to receive IPI */
+ csr_set(CSR_MIE, MIP_MSIP);
+
+ /* Acquire coldboot lock */
+ spin_lock(&coldboot_lock);
+
+ /* Mark current HART as waiting */
+ coldboot_wait_bitmap |= (1UL << hartid);
+
+ /* Wait for coldboot to finish using WFI */
+ while (!coldboot_done) {
+ spin_unlock(&coldboot_lock);
+ wfi();
+ spin_lock(&coldboot_lock);
+ };
+
+ /* Unmark current HART as waiting */
+ coldboot_wait_bitmap &= ~(1UL << hartid);
+
+ /* Release coldboot lock */
+ spin_unlock(&coldboot_lock);
+
+ /* Restore MIE CSR */
+ csr_write(CSR_MIE, saved_mie);
+
+ /* Clear current HART IPI */
+ sbi_platform_ipi_clear(plat, hartid);
+}
+
+static void wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid)
+{
+ const struct sbi_platform *plat = sbi_platform_ptr(scratch);
+ int max_hart = sbi_platform_hart_count(plat);
+
+ /* Acquire coldboot lock */
+ spin_lock(&coldboot_lock);
+
+ /* Mark coldboot done */
+ coldboot_done = 1;
+
+ /* Send an IPI to all HARTs waiting for coldboot */
+ for (int i = 0; i < max_hart; i++) {
+ if ((i != hartid) && (coldboot_wait_bitmap & (1UL << i)))
+ sbi_platform_ipi_send(plat, i);
+ }
+
+ /* Release coldboot lock */
+ spin_unlock(&coldboot_lock);
+}
+
static unsigned long init_count_offset;
static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
@@ -130,7 +198,7 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
if (!(scratch->options & SBI_SCRATCH_NO_BOOT_PRINTS))
sbi_boot_prints(scratch, hartid);
- sbi_hart_wake_coldboot_harts(scratch, hartid);
+ wake_coldboot_harts(scratch, hartid);
sbi_hart_mark_available(hartid);
@@ -148,7 +216,7 @@ static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid)
unsigned long *init_count;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
- sbi_hart_wait_for_coldboot(scratch, hartid);
+ wait_for_coldboot(scratch, hartid);
if (!init_count_offset)
sbi_hart_hang();