diff options
Diffstat (limited to 'sys/compat/linuxkpi/common/include/linux/bitops.h')
-rw-r--r-- | sys/compat/linuxkpi/common/include/linux/bitops.h | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/bitops.h b/sys/compat/linuxkpi/common/include/linux/bitops.h index b12050a..9e1fa2b 100644 --- a/sys/compat/linuxkpi/common/include/linux/bitops.h +++ b/sys/compat/linuxkpi/common/include/linux/bitops.h @@ -46,7 +46,7 @@ #define BITS_TO_LONGS(n) howmany((n), BITS_PER_LONG) #define BIT_MASK(nr) (1UL << ((nr) & (BITS_PER_LONG - 1))) #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) -#define GENMASK(lo, hi) (((2UL << ((hi) - (lo))) - 1UL) << (lo)) +#define GENMASK(h, l) (((~0UL) >> (BITS_PER_LONG - (h) - 1)) & ((~0UL) << (l))) #define BITS_PER_BYTE 8 static inline int @@ -73,6 +73,12 @@ __flsl(long mask) return (flsl(mask) - 1); } +static inline uint32_t +ror32(uint32_t word, unsigned int shift) +{ + + return ((word >> shift) | (word << (32 - shift))); +} #define ffz(mask) __ffs(~(mask)) @@ -87,7 +93,7 @@ static inline int get_count_order(unsigned int count) } static inline unsigned long -find_first_bit(unsigned long *addr, unsigned long size) +find_first_bit(const unsigned long *addr, unsigned long size) { long mask; int bit; @@ -109,7 +115,7 @@ find_first_bit(unsigned long *addr, unsigned long size) } static inline unsigned long -find_first_zero_bit(unsigned long *addr, unsigned long size) +find_first_zero_bit(const unsigned long *addr, unsigned long size) { long mask; int bit; @@ -131,7 +137,7 @@ find_first_zero_bit(unsigned long *addr, unsigned long size) } static inline unsigned long -find_last_bit(unsigned long *addr, unsigned long size) +find_last_bit(const unsigned long *addr, unsigned long size) { long mask; int offs; @@ -157,7 +163,7 @@ find_last_bit(unsigned long *addr, unsigned long size) } static inline unsigned long -find_next_bit(unsigned long *addr, unsigned long size, unsigned long offset) +find_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { long mask; int offs; @@ -196,7 +202,7 @@ find_next_bit(unsigned long *addr, unsigned long size, unsigned long offset) } static inline unsigned long -find_next_zero_bit(unsigned long *addr, unsigned long size, +find_next_zero_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { long mask; @@ -300,23 +306,23 @@ bitmap_empty(unsigned long *addr, int size) } #define __set_bit(i, a) \ - atomic_set_long(&((volatile long *)(a))[BIT_WORD(i)], BIT_MASK(i)) + atomic_set_long(&((volatile unsigned long *)(a))[BIT_WORD(i)], BIT_MASK(i)) #define set_bit(i, a) \ - atomic_set_long(&((volatile long *)(a))[BIT_WORD(i)], BIT_MASK(i)) + atomic_set_long(&((volatile unsigned long *)(a))[BIT_WORD(i)], BIT_MASK(i)) #define __clear_bit(i, a) \ - atomic_clear_long(&((volatile long *)(a))[BIT_WORD(i)], BIT_MASK(i)) + atomic_clear_long(&((volatile unsigned long *)(a))[BIT_WORD(i)], BIT_MASK(i)) #define clear_bit(i, a) \ - atomic_clear_long(&((volatile long *)(a))[BIT_WORD(i)], BIT_MASK(i)) + atomic_clear_long(&((volatile unsigned long *)(a))[BIT_WORD(i)], BIT_MASK(i)) #define test_bit(i, a) \ - !!(atomic_load_acq_long(&((volatile long *)(a))[BIT_WORD(i)]) & \ + !!(atomic_load_acq_long(&((volatile unsigned long *)(a))[BIT_WORD(i)]) & \ BIT_MASK(i)) -static inline long -test_and_clear_bit(long bit, long *var) +static inline int +test_and_clear_bit(long bit, volatile unsigned long *var) { long val; @@ -324,14 +330,14 @@ test_and_clear_bit(long bit, long *var) bit %= BITS_PER_LONG; bit = (1UL << bit); do { - val = *(volatile long *)var; + val = *var; } while (atomic_cmpset_long(var, val, val & ~bit) == 0); return !!(val & bit); } -static inline long -test_and_set_bit(long bit, long *var) +static inline int +test_and_set_bit(long bit, volatile unsigned long *var) { long val; @@ -339,7 +345,7 @@ test_and_set_bit(long bit, long *var) bit %= BITS_PER_LONG; bit = (1UL << bit); do { - val = *(volatile long *)var; + val = *var; } while (atomic_cmpset_long(var, val, val | bit) == 0); return !!(val & bit); @@ -393,7 +399,8 @@ enum { REG_OP_RELEASE, }; -static int __reg_op(unsigned long *bitmap, int pos, int order, int reg_op) +static inline int +__reg_op(unsigned long *bitmap, int pos, int order, int reg_op) { int nbits_reg; int index; |