lib: sbi: Remove sbi_platform_hart_index/invalid() functions
authorAnup Patel <apatel@ventanamicro.com>
Fri, 1 Sep 2023 09:13:34 +0000 (14:43 +0530)
committerAnup Patel <anup@brainfault.org>
Sun, 24 Sep 2023 06:09:30 +0000 (11:39 +0530)
The hartid to hartindex mapping is now tracked in sbi_scratch so we
don't need sbi_platform_hart_index() and sbi_platform_hart_invalid()
functions hence let us remove them.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
include/sbi/sbi_platform.h
lib/sbi/sbi_domain.c
lib/sbi/sbi_init.c
lib/sbi/sbi_platform.c

index e6a4a3170a231d00baf8e83d302271e57b7834c5..389203b02a4dbaa077b6b7d42e1be83b6c5cb719 100644 (file)
@@ -262,16 +262,6 @@ _Static_assert(
 #define sbi_platform_has_mfaults_delegation(__p) \
        ((__p)->features & SBI_PLATFORM_HAS_MFAULTS_DELEGATION)
 
-/**
- * Get HART index for the given HART
- *
- * @param plat pointer to struct sbi_platform
- * @param hartid HART ID
- *
- * @return 0 <= value < hart_count for valid HART otherwise -1U
- */
-u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid);
-
 /**
  * Get the platform features in string format
  *
@@ -371,24 +361,6 @@ static inline u32 sbi_platform_hart_stack_size(const struct sbi_platform *plat)
        return 0;
 }
 
-/**
- * Check whether given HART is invalid
- *
- * @param plat pointer to struct sbi_platform
- * @param hartid HART ID
- *
- * @return true if HART is invalid and false otherwise
- */
-static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
-                                            u32 hartid)
-{
-       if (!plat)
-               return true;
-       if (plat->hart_count <= sbi_platform_hart_index(plat, hartid))
-               return true;
-       return false;
-}
-
 /**
  * Check whether given HART is allowed to do cold boot
  *
index acd0f74c301c087dd596da4cb076500beed10445..77d6ca4319364202d91065a51a44f7fbd3734b8b 100644 (file)
@@ -277,7 +277,7 @@ static int sanitize_domain(const struct sbi_platform *plat,
                return SBI_EINVAL;
        }
        sbi_hartmask_for_each_hart(i, dom->possible_harts) {
-               if (sbi_platform_hart_invalid(plat, i)) {
+               if (!sbi_hartid_valid(i)) {
                        sbi_printf("%s: %s possible HART mask has invalid "
                                   "hart %d\n", __func__, dom->name, i);
                        return SBI_EINVAL;
@@ -723,7 +723,6 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
        int rc;
        struct sbi_hartmask *root_hmask;
        struct sbi_domain_memregion *root_memregs;
-       const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 
        if (scratch->fw_rw_offset == 0 ||
            (scratch->fw_rw_offset & (scratch->fw_rw_offset - 1)) != 0) {
@@ -798,7 +797,7 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
 
        /* Root domain possible and assigned HARTs */
        for (i = 0; i < SBI_HARTMASK_MAX_BITS; i++) {
-               if (sbi_platform_hart_invalid(plat, i))
+               if (!sbi_hartid_valid(i))
                        continue;
                sbi_hartmask_set_hart(i, root_hmask);
        }
index 252b41ace41e3c051e0746d67404a5158e63ce8d..07be3d246c8ac90b9e7d10f0e0b0f97e6944229b 100644 (file)
@@ -520,13 +520,19 @@ static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0);
  */
 void __noreturn sbi_init(struct sbi_scratch *scratch)
 {
+       u32 i, h;
+       bool hartid_valid               = false;
        bool next_mode_supported        = false;
        bool coldboot                   = false;
        u32 hartid                      = current_hartid();
        const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 
-       if ((SBI_HARTMASK_MAX_BITS <= hartid) ||
-           sbi_platform_hart_invalid(plat, hartid))
+       for (i = 0; i < plat->hart_count; i++) {
+               h = (plat->hart_index2id) ? plat->hart_index2id[i] : i;
+               if (h == hartid)
+                       hartid_valid = true;
+       }
+       if (SBI_HARTMASK_MAX_BITS <= hartid || !hartid_valid)
                sbi_hart_hang();
 
        switch (scratch->next_mode) {
@@ -623,7 +629,7 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch)
        u32 hartid                      = current_hartid();
        const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 
-       if (sbi_platform_hart_invalid(plat, hartid))
+       if (!sbi_hartid_valid(hartid))
                sbi_hart_hang();
 
        sbi_platform_early_exit(plat);
index 445a8c1631ba9727a634199f0455c4bb26e06b93..43fc88af90630c25ffcc6c77a350d66ecf788c2c 100644 (file)
@@ -71,20 +71,3 @@ done:
        else
                sbi_strncpy(features_str, "none", nfstr);
 }
-
-u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid)
-{
-       u32 i;
-
-       if (!plat)
-               return -1U;
-       if (plat->hart_index2id) {
-               for (i = 0; i < plat->hart_count; i++) {
-                       if (plat->hart_index2id[i] == hartid)
-                               return i;
-               }
-               return -1U;
-       }
-
-       return hartid;
-}