diff options
| author | Samuel Holland <samuel.holland@sifive.com> | 2025-02-20 10:42:29 -0800 |
|---|---|---|
| committer | Anup Patel <anup@brainfault.org> | 2025-03-24 17:56:08 +0530 |
| commit | 757f7acafdd25e0ff71a444bbe9f670bc33a3b7f (patch) | |
| tree | 259fa5f4515274474399e3624859e248e5fc89a2 /include | |
| parent | 6b97950cf5d51afcfd8d059a0d8baa15601e55ab (diff) | |
| download | opensbi-757f7acafdd25e0ff71a444bbe9f670bc33a3b7f.tar.gz opensbi-757f7acafdd25e0ff71a444bbe9f670bc33a3b7f.tar.bz2 opensbi-757f7acafdd25e0ff71a444bbe9f670bc33a3b7f.zip | |
lib: sbi_scratch: Add sbi_hart_count() and for_each_hartindex()
There is currently no helper for iterating through the harts in a
system, and code must choose between sbi_scratch_last_hartindex() and
sbi_platform_hart_count() for the loop condition.
sbi_scratch_last_hartindex() has unusual semantics, leading to the
likelihood of off-by-one errors, and sbi_platform_hart_count() is
provided by the platform and so may not be properly bounded.
Add a new helper which definitively reports the number of harts managed
by this OpenSBI instance, i.e. the number of valid hart indexes, and a
convenient iterator macro.
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/sbi/sbi_scratch.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index 1ec1710e..293625f1 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -210,15 +210,21 @@ do { \ #define current_hartindex() \ (sbi_scratch_thishart_ptr()->hartindex) -/** Last HART index having a sbi_scratch pointer */ -extern u32 last_hartindex_having_scratch; +/** Number of harts managed by this OpenSBI instance */ +extern u32 sbi_scratch_hart_count; + +/** Get the number of harts managed by this OpenSBI instance */ +#define sbi_hart_count() sbi_scratch_hart_count + +/** Iterate over the harts managed by this OpenSBI instance */ +#define sbi_for_each_hartindex(__var) \ + for (u32 __var = 0; __var < sbi_hart_count(); ++__var) /** Get last HART index having a sbi_scratch pointer */ -#define sbi_scratch_last_hartindex() last_hartindex_having_scratch +#define sbi_scratch_last_hartindex() (sbi_hart_count() - 1) /** Check whether a particular HART index is valid or not */ -#define sbi_hartindex_valid(__hartindex) \ -(((__hartindex) <= sbi_scratch_last_hartindex()) ? true : false) +#define sbi_hartindex_valid(__hartindex) ((__hartindex) < sbi_hart_count()) /** HART index to HART id table */ extern u32 hartindex_to_hartid_table[]; |
