diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2015-08-20 14:54:19 +1000 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2015-08-28 12:37:40 +1000 |
commit | 8e73dd1a57708df5ee6f22e635b56ffeb566fd54 (patch) | |
tree | 89a09558a589def9c93be6b9dd0caa6df1ca42af /lib | |
parent | 6658b6d6e4f8287adb0b2e5434e488eb55b38420 (diff) | |
download | nouveau-8e73dd1a57708df5ee6f22e635b56ffeb566fd54.tar.gz |
fifo: convert user classes to new-style nvkm_object
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/include/nvif/os.h | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/lib/include/nvif/os.h b/lib/include/nvif/os.h index 3c482cfe1..f718aef70 100644 --- a/lib/include/nvif/os.h +++ b/lib/include/nvif/os.h @@ -207,10 +207,16 @@ hweight32(u32 v) { return i; } +#define BITS_PER_LONG (sizeof(unsigned long) * 8) +#define BITS_TO_LONGS(b) DIV_ROUND_UP((b), BITS_PER_LONG) +#define DECLARE_BITMAP(n,b) unsigned long n[BITS_TO_LONGS(b)] +#define BITMAP_POS(b) ((b) / BITS_PER_LONG) +#define BITMAP_BIT(b) ((b) % BITS_PER_LONG) + static inline int test_bit(int bit, volatile unsigned long *ptr) { - return !!(*ptr & (1 << bit)); + return !!(ptr[BITMAP_POS(bit)] & (1UL << BITMAP_BIT(bit))); } static inline int @@ -247,6 +253,44 @@ set_bit(int bit, volatile unsigned long *ptr) test_and_set_bit(bit, ptr); } +static inline void +__clear_bit(long bit, volatile unsigned long *addr) +{ + addr[BITMAP_POS(bit)] &= ~(1UL << BITMAP_BIT(bit)); +} + +static inline void +__set_bit(long bit, volatile unsigned long *addr) +{ + addr[BITMAP_POS(bit)] |= (1UL << BITMAP_BIT(bit)); +} + +static inline long +find_first_zero_bit(volatile unsigned long *addr, int bits) +{ + int bit; + for (bit = 0; bit < bits; bit++) { + if (!test_bit(bit, addr)) + break; + } + return bit; +} + +static inline void +bitmap_fill(unsigned long *addr, unsigned int bits) +{ + int bit; + for (bit = 0; bit < bits; bit++) + __set_bit(bit, addr); +} + +static inline void +bitmap_clear(unsigned long *addr, unsigned int pos, unsigned int bits) +{ + while (bits--) + __clear_bit(pos++, addr); +} + /****************************************************************************** * atomics *****************************************************************************/ |