diff options
author | Anup Patel <apatel@ventanamicro.com> | 2022-09-12 09:50:43 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2023-09-24 11:39:21 +0530 |
commit | d1e4dff45b2d3ce2c88d09e98ae5795d323b2267 (patch) | |
tree | 70054674c35f9249b60af95a6642c65ff4564561 /include/sbi | |
parent | 130e65dd9d44c11ef3a3048eb9a491d33e5f14b8 (diff) | |
download | opensbi-d1e4dff45b2d3ce2c88d09e98ae5795d323b2267.zip opensbi-d1e4dff45b2d3ce2c88d09e98ae5795d323b2267.tar.gz opensbi-d1e4dff45b2d3ce2c88d09e98ae5795d323b2267.tar.bz2 |
lib: sbi: Introduce HART index in sbi_scratch
We introduce HART index and related helper functions in sbi_scratch
where HART index is contiguous and each HART index maps to a physical
HART id such that 0 <= HART index and HART index < SBI_HARTMASK_MAX_BITS.
The HART index to HART id mapping follows the index2id mapping provided
by the platform. If the platform does not provide index2id mapping then
identity mapping is assumed.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Diffstat (limited to 'include/sbi')
-rw-r--r-- | include/sbi/sbi_scratch.h | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index 4801492..9a4dce1 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -202,12 +202,47 @@ do { \ = (__type)(__ptr); \ } while (0) -/** HART id to scratch table */ -extern struct sbi_scratch *hartid_to_scratch_table[]; +/** Last HART index having a sbi_scratch pointer */ +extern u32 last_hartindex_having_scratch; + +/** Get last HART index having a sbi_scratch pointer */ +#define sbi_scratch_last_hartindex() last_hartindex_having_scratch + +/** Check whether a particular HART index is valid or not */ +#define sbi_hartindex_valid(__hartindex) \ +(((__hartindex) <= sbi_scratch_last_hartindex()) ? true : false) + +/** HART index to HART id table */ +extern u32 hartindex_to_hartid_table[]; + +/** Get sbi_scratch from HART index */ +#define sbi_hartindex_to_hartid(__hartindex) \ +({ \ + ((__hartindex) <= sbi_scratch_last_hartindex()) ?\ + hartindex_to_hartid_table[__hartindex] : -1U; \ +}) + +/** HART index to scratch table */ +extern struct sbi_scratch *hartindex_to_scratch_table[]; + +/** Get sbi_scratch from HART index */ +#define sbi_hartindex_to_scratch(__hartindex) \ +({ \ + ((__hartindex) <= sbi_scratch_last_hartindex()) ?\ + hartindex_to_scratch_table[__hartindex] : NULL;\ +}) + +/** + * Get logical index for given HART id + * @param hartid physical HART id + * @returns value between 0 to SBI_HARTMASK_MAX_BITS upon success and + * SBI_HARTMASK_MAX_BITS upon failure. + */ +u32 sbi_hartid_to_hartindex(u32 hartid); /** Get sbi_scratch from HART id */ #define sbi_hartid_to_scratch(__hartid) \ - hartid_to_scratch_table[__hartid] + sbi_hartindex_to_scratch(sbi_hartid_to_hartindex(__hartid)) /** Last HART id having a sbi_scratch pointer */ extern u32 last_hartid_having_scratch; @@ -215,6 +250,10 @@ extern u32 last_hartid_having_scratch; /** Get last HART id having a sbi_scratch pointer */ #define sbi_scratch_last_hartid() last_hartid_having_scratch +/** Check whether particular HART id is valid or not */ +#define sbi_hartid_valid(__hartid) \ + sbi_hartindex_valid(sbi_hartid_to_hartindex(__hartid)) + #endif #endif |