forked from Mirrors/opensbi
lib: sbi: Extend sbi_hartmask to support both hartid and hartindex
Currently, the sbi_hartmask is indexed by hartid which puts a limit on hartid to be less than SBI_HARTMASK_MAX_BITS. We extend the sbi_hartmask implementation to use hartindex and support updating sbi_hartmask using hartid. This removes the limit on hartid and existing code works largely unmodified. Signed-off-by: Xiang W <wxjstz@126.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#define __SBI_HARTMASK_H__
|
||||
|
||||
#include <sbi/sbi_bitmap.h>
|
||||
#include <sbi/sbi_scratch.h>
|
||||
|
||||
/**
|
||||
* Maximum number of bits in a hartmask
|
||||
@@ -32,7 +33,10 @@ struct sbi_hartmask {
|
||||
|
||||
/** Initialize hartmask to zero except a particular HART id */
|
||||
#define SBI_HARTMASK_INIT_EXCEPT(__m, __h) \
|
||||
bitmap_zero_except(((__m)->bits), (__h), SBI_HARTMASK_MAX_BITS)
|
||||
do { \
|
||||
u32 __i = sbi_hartid_to_hartindex(__h); \
|
||||
bitmap_zero_except(((__m)->bits), __i, SBI_HARTMASK_MAX_BITS); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Get underlying bitmap of hartmask
|
||||
@@ -41,37 +45,68 @@ struct sbi_hartmask {
|
||||
#define sbi_hartmask_bits(__m) ((__m)->bits)
|
||||
|
||||
/**
|
||||
* Set a HART in hartmask
|
||||
* Set a HART index in hartmask
|
||||
* @param i HART index to set
|
||||
* @param m the hartmask pointer
|
||||
*/
|
||||
static inline void sbi_hartmask_set_hartindex(u32 i, struct sbi_hartmask *m)
|
||||
{
|
||||
if (i < SBI_HARTMASK_MAX_BITS)
|
||||
__set_bit(i, m->bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a HART id in hartmask
|
||||
* @param h HART id to set
|
||||
* @param m the hartmask pointer
|
||||
*/
|
||||
static inline void sbi_hartmask_set_hart(u32 h, struct sbi_hartmask *m)
|
||||
static inline void sbi_hartmask_set_hartid(u32 h, struct sbi_hartmask *m)
|
||||
{
|
||||
if (h < SBI_HARTMASK_MAX_BITS)
|
||||
__set_bit(h, m->bits);
|
||||
sbi_hartmask_set_hartindex(sbi_hartid_to_hartindex(h), m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a HART in hartmask
|
||||
* Clear a HART index in hartmask
|
||||
* @param i HART index to clear
|
||||
* @param m the hartmask pointer
|
||||
*/
|
||||
static inline void sbi_hartmask_clear_hartindex(u32 i, struct sbi_hartmask *m)
|
||||
{
|
||||
if (i < SBI_HARTMASK_MAX_BITS)
|
||||
__clear_bit(i, m->bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a HART id in hartmask
|
||||
* @param h HART id to clear
|
||||
* @param m the hartmask pointer
|
||||
*/
|
||||
static inline void sbi_hartmask_clear_hart(u32 h, struct sbi_hartmask *m)
|
||||
static inline void sbi_hartmask_clear_hartid(u32 h, struct sbi_hartmask *m)
|
||||
{
|
||||
if (h < SBI_HARTMASK_MAX_BITS)
|
||||
__clear_bit(h, m->bits);
|
||||
sbi_hartmask_clear_hartindex(sbi_hartid_to_hartindex(h), m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a HART in hartmask
|
||||
* Test a HART index in hartmask
|
||||
* @param i HART index to test
|
||||
* @param m the hartmask pointer
|
||||
*/
|
||||
static inline int sbi_hartmask_test_hartindex(u32 i,
|
||||
const struct sbi_hartmask *m)
|
||||
{
|
||||
if (i < SBI_HARTMASK_MAX_BITS)
|
||||
return __test_bit(i, m->bits);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a HART id in hartmask
|
||||
* @param h HART id to test
|
||||
* @param m the hartmask pointer
|
||||
*/
|
||||
static inline int sbi_hartmask_test_hart(u32 h, const struct sbi_hartmask *m)
|
||||
static inline int sbi_hartmask_test_hartid(u32 h, const struct sbi_hartmask *m)
|
||||
{
|
||||
if (h < SBI_HARTMASK_MAX_BITS)
|
||||
return __test_bit(h, m->bits);
|
||||
return 0;
|
||||
return sbi_hartmask_test_hartindex(sbi_hartid_to_hartindex(h), m);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,8 +169,27 @@ static inline void sbi_hartmask_xor(struct sbi_hartmask *dstp,
|
||||
sbi_hartmask_bits(src2p), SBI_HARTMASK_MAX_BITS);
|
||||
}
|
||||
|
||||
/** Iterate over each HART in hartmask */
|
||||
#define sbi_hartmask_for_each_hart(__h, __m) \
|
||||
for_each_set_bit(__h, (__m)->bits, SBI_HARTMASK_MAX_BITS)
|
||||
/**
|
||||
* Iterate over each HART in hartmask
|
||||
* __h hart id
|
||||
* __i hart index
|
||||
* __m hartmask
|
||||
*/
|
||||
#define sbi_hartmask_for_each_hart(__h, __i, __m) \
|
||||
for((__i) = find_first_bit((__m)->bits, SBI_HARTMASK_MAX_BITS), \
|
||||
(__h) = sbi_hartindex_to_hartid(__i); \
|
||||
(__i) < SBI_HARTMASK_MAX_BITS; \
|
||||
(__i) = find_next_bit((__m)->bits, SBI_HARTMASK_MAX_BITS, (__i) + 1), \
|
||||
(__h) = sbi_hartindex_to_hartid(__i))
|
||||
|
||||
/**
|
||||
* Iterate over each HART index in hartmask
|
||||
* __i hart index
|
||||
* __m hartmask
|
||||
*/
|
||||
#define sbi_hartmask_for_each_hartindex(__i, __m) \
|
||||
for((__i) = find_first_bit((__m)->bits, SBI_HARTMASK_MAX_BITS); \
|
||||
(__i) < SBI_HARTMASK_MAX_BITS; \
|
||||
(__i) = find_next_bit((__m)->bits, SBI_HARTMASK_MAX_BITS, (__i) + 1))
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user