aboutsummaryrefslogtreecommitdiff
path: root/include/sbi
diff options
context:
space:
mode:
authorXiang W <wxjstz@126.com>2023-08-31 11:39:30 +0800
committerAnup Patel <anup@brainfault.org>2023-09-24 11:39:32 +0530
commit296e70d69da74b09426e4f565306f26e9a6c79f8 (patch)
tree729628bd513ea62ef4059076a5a09751631781ca /include/sbi
parente6125c3c4f53ba0c1029b06e17f38f3c982d9815 (diff)
downloadopensbi-296e70d69da74b09426e4f565306f26e9a6c79f8.zip
opensbi-296e70d69da74b09426e4f565306f26e9a6c79f8.tar.gz
opensbi-296e70d69da74b09426e4f565306f26e9a6c79f8.tar.bz2
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>
Diffstat (limited to 'include/sbi')
-rw-r--r--include/sbi/sbi_hartmask.h88
1 files changed, 71 insertions, 17 deletions
diff --git a/include/sbi/sbi_hartmask.h b/include/sbi/sbi_hartmask.h
index f1cef0c..105653e 100644
--- a/include/sbi/sbi_hartmask.h
+++ b/include/sbi/sbi_hartmask.h
@@ -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,40 +45,71 @@ 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)
+{
+ sbi_hartmask_set_hartindex(sbi_hartid_to_hartindex(h), m);
+}
+
+/**
+ * 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 (h < SBI_HARTMASK_MAX_BITS)
- __set_bit(h, m->bits);
+ if (i < SBI_HARTMASK_MAX_BITS)
+ __clear_bit(i, m->bits);
}
/**
- * Clear a HART in hartmask
+ * 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
- * @param h HART id to test
+ * Test a HART index in hartmask
+ * @param i HART index 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_hartindex(u32 i,
+ const struct sbi_hartmask *m)
{
- if (h < SBI_HARTMASK_MAX_BITS)
- return __test_bit(h, m->bits);
+ 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_hartid(u32 h, const struct sbi_hartmask *m)
+{
+ return sbi_hartmask_test_hartindex(sbi_hartid_to_hartindex(h), m);
+}
+
+/**
* Set all HARTs in a hartmask
* @param dstp the hartmask pointer
*/
@@ -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