diff options
author | Anup Patel <anup.patel@wdc.com> | 2020-03-15 09:09:25 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2020-03-19 07:00:01 +0300 |
commit | c51f02cf143b081c2a81717393a0e6cef2ce2521 (patch) | |
tree | eeff8cd451d20bfa543df626e1713a59803e6fb4 /include | |
parent | 75eec9dd3f04febd7df8e5ee3fb90c236e50ded3 (diff) | |
download | opensbi-c51f02cf143b081c2a81717393a0e6cef2ce2521.tar.xz |
include: sbi_platform: Introduce HART index to HART id table
A platform can have discontinuous and/or sparse HART ids so we
cannot always assume a set of HARTs with continuous HART ids.
This patch adds support for discontinuous and sparse HART ids by
introducing HART index to HART id table. This table has platform
hart_count entries and it maps HART index to HART id.
The HART index to HART id table has only two restrictions:
1. HART index < sbi_platform hart_count
2. HART id < SBI_HARTMASK_MAX_BITS
Example1:
Let's say we have a platform with 2 HART ids 11 and 22, for such a
a platform:
hart_count = 2
hart_index2id[0] = 11
hart_index2id[1] = 22
Example2:
Let's say we have a platform with 5 HARTs ids 0, 1, 2, 3, and 4
but out of these HART with id 0 is not usable so for such a platform:
hart_count = 5
hart_index2id[0] = -1U
hart_index2id[1] = 1
hart_index2id[2] = 2
hart_index2id[3] = 3
hart_index2id[4] = 4
OR
hart_count = 4
hart_index2id[0] = 1
hart_index2id[1] = 2
hart_index2id[2] = 3
hart_index2id[3] = 4
With HART index to HART id table in place, the hart_disabled()
callback is now redundant so we remove it as well.
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/sbi/sbi_platform.h | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 0264732..c47ab46 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -33,6 +33,8 @@ #define SBI_PLATFORM_OPS_OFFSET (0x58) /** Offset of firmware_context in struct sbi_platform */ #define SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET (0x58 + __SIZEOF_POINTER__) +/** Offset of hart_index2id in struct sbi_platform */ +#define SBI_PLATFORM_HART_INDEX2ID_OFFSET (0x58 + (__SIZEOF_POINTER__ * 2)) #define SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT (1UL << 12) @@ -136,9 +138,6 @@ struct sbi_platform_operations { /** Exit platform timer for current HART */ void (*timer_exit)(void); - /** Check whether given hart is disabled */ - bool (*hart_disabled)(u32 hartid); - /** Bringup the given hart from previous stage **/ int (*hart_start)(u32 hartid, ulong saddr, ulong priv); /** @@ -190,6 +189,22 @@ struct sbi_platform { unsigned long platform_ops_addr; /** Pointer to system firmware specific context */ unsigned long firmware_context; + /** + * HART index to HART id table + * + * For used HART index <abc>: + * hart_index2id[<abc>] = some HART id + * For unused HART index <abc>: + * hart_index2id[<abc>] = -1U + * + * If hart_index2id == NULL then we assume identity mapping + * hart_index2id[<abc>] = <abc> + * + * We have only two restrictions: + * 1. HART index < sbi_platform hart_count + * 2. HART id < SBI_HARTMASK_MAX_BITS + */ + const u32 *hart_index2id; } __packed; /** Get pointer to sbi_platform for sbi_scratch pointer */ @@ -282,22 +297,46 @@ static inline u32 sbi_platform_hart_stack_size(const struct sbi_platform *plat) } /** - * Check whether the given HART is disabled + * Get HART index for the given HART * * @param plat pointer to struct sbi_platform * @param hartid HART ID * - * @return TRUE if HART is disabled and FALSE otherwise + * @return 0 <= value < hart_count for valid HART otherwise -1U */ -static inline bool sbi_platform_hart_disabled(const struct sbi_platform *plat, - u32 hartid) +static inline u32 sbi_platform_hart_index(const struct sbi_platform *plat, + u32 hartid) { - if (plat) { - if (sbi_platform_hart_count(plat) <= hartid) - return TRUE; - if (sbi_platform_ops(plat)->hart_disabled) - return sbi_platform_ops(plat)->hart_disabled(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; +} + +/** + * 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; } |