lib: Don't use sbi_platform_hart_count() API
authorAnup Patel <anup.patel@wdc.com>
Sat, 14 Mar 2020 14:13:26 +0000 (19:43 +0530)
committerAnup Patel <anup@brainfault.org>
Thu, 19 Mar 2020 03:57:51 +0000 (09:27 +0530)
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 <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
lib/sbi/sbi_init.c
lib/sbi/sbi_scratch.c

index f75b904..1c2f6b9 100644 (file)
@@ -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);
index fe0856e..a756fa7 100644 (file)
@@ -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;