Deleted Added
full compact
5c5
< * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
---
> * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
31a32,35
> #include <sys/types.h>
> #include <sys/systm.h>
>
> #define BIT(nr) (1UL << (nr))
37c41,42
< #define BIT_MASK(n) (~0UL >> (BITS_PER_LONG - (n)))
---
> #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
> #define BITMAP_LAST_WORD_MASK(n) (~0UL >> (BITS_PER_LONG - (n)))
38a44
> #define BIT_MASK(nr) (1UL << ((nr) & (BITS_PER_LONG - 1)))
40c46
<
---
> #define GENMASK(lo, hi) (((2UL << ((hi) - (lo))) - 1UL) << (lo))
93c99
< mask = (*addr) & BIT_MASK(size);
---
> mask = (*addr) & BITMAP_LAST_WORD_MASK(size);
115c121
< mask = ~(*addr) & BIT_MASK(size);
---
> mask = ~(*addr) & BITMAP_LAST_WORD_MASK(size);
137c143
< mask = (*addr) & BIT_MASK(offs);
---
> mask = (*addr) & BITMAP_LAST_WORD_MASK(offs);
165c171
< mask = (*addr) & ~BIT_MASK(offs);
---
> mask = (*addr) & ~BITMAP_LAST_WORD_MASK(offs);
180c186
< mask = (*addr) & BIT_MASK(size);
---
> mask = (*addr) & BITMAP_LAST_WORD_MASK(size);
205c211
< mask = ~(*addr) & ~BIT_MASK(offs);
---
> mask = ~(*addr) & ~BITMAP_LAST_WORD_MASK(offs);
220c226
< mask = ~(*addr) & BIT_MASK(size);
---
> mask = ~(*addr) & BITMAP_LAST_WORD_MASK(size);
248c254
< addr[size / BITS_PER_LONG] = BIT_MASK(tail);
---
> addr[size / BITS_PER_LONG] = BITMAP_LAST_WORD_MASK(tail);
254c260
< long mask;
---
> unsigned long mask;
265c271
< mask = BIT_MASK(tail);
---
> mask = BITMAP_LAST_WORD_MASK(tail);
275c281
< long mask;
---
> unsigned long mask;
286c292
< mask = BIT_MASK(tail);
---
> mask = BITMAP_LAST_WORD_MASK(tail);
293,294d298
< #define NBLONG (NBBY * sizeof(long))
<
296c300
< atomic_set_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG))
---
> atomic_set_long(&((volatile long *)(a))[BIT_WORD(i)], BIT_MASK(i))
299c303
< atomic_set_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG))
---
> atomic_set_long(&((volatile long *)(a))[BIT_WORD(i)], BIT_MASK(i))
302c306
< atomic_clear_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG))
---
> atomic_clear_long(&((volatile long *)(a))[BIT_WORD(i)], BIT_MASK(i))
305c309
< atomic_clear_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG))
---
> atomic_clear_long(&((volatile long *)(a))[BIT_WORD(i)], BIT_MASK(i))
308,309c312,313
< !!(atomic_load_acq_long(&((volatile long *)(a))[(i)/NBLONG]) & \
< (1UL << ((i) % NBLONG)))
---
> !!(atomic_load_acq_long(&((volatile long *)(a))[BIT_WORD(i)]) & \
> BIT_MASK(i))
316,317c320,321
< var += bit / (sizeof(long) * NBBY);
< bit %= sizeof(long) * NBBY;
---
> var += BIT_WORD(bit);
> bit %= BITS_PER_LONG;
331,332c335,336
< var += bit / (sizeof(long) * NBBY);
< bit %= sizeof(long) * NBBY;
---
> var += BIT_WORD(bit);
> bit %= BITS_PER_LONG;
341,349d344
<
< #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
< #define BITMAP_LAST_WORD_MASK(nbits) \
< ( \
< ((nbits) % BITS_PER_LONG) ? \
< (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \
< )
<
<
393,395c388,390
< REG_OP_ISFREE, /* true if region is all zero bits */
< REG_OP_ALLOC, /* set all bits in region */
< REG_OP_RELEASE, /* clear all bits in region */
---
> REG_OP_ISFREE,
> REG_OP_ALLOC,
> REG_OP_RELEASE,
400,407c395,402
< int nbits_reg; /* number of bits in region */
< int index; /* index first long of region in bitmap */
< int offset; /* bit offset region in bitmap[index] */
< int nlongs_reg; /* num longs spanned by region in bitmap */
< int nbitsinlong; /* num bits of region in each spanned long */
< unsigned long mask; /* bitmask for one long of region */
< int i; /* scans bitmap by longs */
< int ret = 0; /* return value */
---
> int nbits_reg;
> int index;
> int offset;
> int nlongs_reg;
> int nbitsinlong;
> unsigned long mask;
> int i;
> int ret = 0;
409,412d403
< /*
< * Either nlongs_reg == 1 (for small orders that fit in one long)
< * or (offset == 0 && mask == ~0UL) (for larger multiword orders.)
< */
419,422d409
< /*
< * Can't do "mask = (1UL << nbitsinlong) - 1", as that
< * overflows if nbitsinlong == BITS_PER_LONG.
< */
433c420
< ret = 1; /* all bits in region free (zero) */
---
> ret = 1;
450,463d436
< /**
< * bitmap_find_free_region - find a contiguous aligned mem region
< * @bitmap: array of unsigned longs corresponding to the bitmap
< * @bits: number of bits in the bitmap
< * @order: region size (log base 2 of number of bits) to find
< *
< * Find a region of free (zero) bits in a @bitmap of @bits bits and
< * allocate them (set them to one). Only consider regions of length
< * a power (@order) of two, aligned to that power of two, which
< * makes the search algorithm much faster.
< *
< * Return the bit offset in bitmap of the allocated region,
< * or -errno on failure.
< */
467c440,441
< int pos, end; /* scans bitmap by regions of size order */
---
> int pos;
> int end;
478,489d451
< /**
< * bitmap_allocate_region - allocate bitmap region
< * @bitmap: array of unsigned longs corresponding to the bitmap
< * @pos: beginning of bit region to allocate
< * @order: region size (log base 2 of number of bits) to allocate
< *
< * Allocate (set bits in) a specified region of a bitmap.
< *
< * Return 0 on success, or %-EBUSY if specified region wasn't
< * free (not all bits were zero).
< */
<
499,509d460
< /**
< * bitmap_release_region - release allocated bitmap region
< * @bitmap: array of unsigned longs corresponding to the bitmap
< * @pos: beginning of bit region to release
< * @order: region size (log base 2 of number of bits) to release
< *
< * This is the complement to __bitmap_find_free_region() and releases
< * the found region (by clearing it in the bitmap).
< *
< * No return value.
< */