From 75eec9dd3f04febd7df8e5ee3fb90c236e50ded3 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Sat, 14 Mar 2020 19:43:26 +0530 Subject: [PATCH] lib: Don't use sbi_platform_hart_count() API We don't need to use sbi_platform_hart_count() in sbi_init and sbi_scratch because checking sbi_platform_hart_disabled() or return value of sbi_hartid_to_scratch() is sufficient. Signed-off-by: Anup Patel Reviewed-by: Bin Meng Reviewed-by: Atish Patra --- lib/sbi/sbi_init.c | 9 ++------- lib/sbi/sbi_scratch.c | 9 +++------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index f75b904..1c2f6b9 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -59,8 +59,6 @@ static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid) /* Platform details */ sbi_printf("Platform Name : %s\n", sbi_platform_name(plat)); sbi_printf("Platform HART Features : RV%d%s\n", xlen, str); - sbi_printf("Platform Max HARTs : %d\n", - sbi_platform_hart_count(plat)); sbi_printf("Current Hart : %u\n", hartid); /* Firmware details */ sbi_printf("Firmware Base : 0x%lx\n", scratch->fw_start); @@ -119,7 +117,6 @@ static void wait_for_coldboot(struct sbi_scratch *scratch, u32 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); @@ -128,7 +125,7 @@ static void wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid) coldboot_done = 1; /* Send an IPI to all HARTs waiting for coldboot */ - for (int i = 0; i < max_hart; i++) { + for (int i = 0; i < SBI_HARTMASK_MAX_BITS; i++) { if ((i != hartid) && sbi_hartmask_test_hart(i, &coldboot_wait_hmask)) sbi_platform_ipi_send(plat, i); @@ -282,7 +279,6 @@ void __noreturn sbi_init(struct sbi_scratch *scratch) const struct sbi_platform *plat = sbi_platform_ptr(scratch); if ((SBI_HARTMASK_MAX_BITS <= hartid) || - (sbi_platform_hart_count(plat) <= hartid) || sbi_platform_hart_disabled(plat, hartid)) sbi_hart_hang(); @@ -300,8 +296,7 @@ unsigned long sbi_init_count(u32 hartid) struct sbi_scratch *scratch; unsigned long *init_count; - if (sbi_platform_hart_count(sbi_platform_thishart_ptr()) <= hartid || - !init_count_offset) + if (!init_count_offset) return 0; scratch = sbi_hartid_to_scratch(hartid); diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c index fe0856e..a756fa7 100644 --- a/lib/sbi/sbi_scratch.c +++ b/lib/sbi/sbi_scratch.c @@ -26,7 +26,7 @@ int sbi_scratch_init(struct sbi_scratch *scratch) u32 i; const struct sbi_platform *plat = sbi_platform_ptr(scratch); - for (i = 0; i < sbi_platform_hart_count(plat); i++) { + for (i = 0; i < SBI_HARTMASK_MAX_BITS; i++) { if (sbi_platform_hart_disabled(plat, i)) continue; hartid_to_scratch_table[i] = @@ -41,8 +41,7 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size, const char *owner) u32 i; void *ptr; unsigned long ret = 0; - struct sbi_scratch *scratch, *rscratch; - const struct sbi_platform *plat; + struct sbi_scratch *rscratch; /* * We have a simple brain-dead allocator which never expects @@ -71,9 +70,7 @@ done: spin_unlock(&extra_lock); if (ret) { - scratch = sbi_scratch_thishart_ptr(); - plat = sbi_platform_ptr(scratch); - for (i = 0; i < sbi_platform_hart_count(plat); i++) { + for (i = 0; i < SBI_HARTMASK_MAX_BITS; i++) { rscratch = sbi_hartid_to_scratch(i); if (!rscratch) continue; -- 2.7.4