summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-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 f1cef0c2..105653e1 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