1*745e3ed8SKirill A. Shutemov #include <linux/bitmap.h> 2*745e3ed8SKirill A. Shutemov __bitmap_set(unsigned long * map,unsigned int start,int len)3*745e3ed8SKirill A. Shutemovvoid __bitmap_set(unsigned long *map, unsigned int start, int len) 4*745e3ed8SKirill A. Shutemov { 5*745e3ed8SKirill A. Shutemov unsigned long *p = map + BIT_WORD(start); 6*745e3ed8SKirill A. Shutemov const unsigned int size = start + len; 7*745e3ed8SKirill A. Shutemov int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); 8*745e3ed8SKirill A. Shutemov unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); 9*745e3ed8SKirill A. Shutemov 10*745e3ed8SKirill A. Shutemov while (len - bits_to_set >= 0) { 11*745e3ed8SKirill A. Shutemov *p |= mask_to_set; 12*745e3ed8SKirill A. Shutemov len -= bits_to_set; 13*745e3ed8SKirill A. Shutemov bits_to_set = BITS_PER_LONG; 14*745e3ed8SKirill A. Shutemov mask_to_set = ~0UL; 15*745e3ed8SKirill A. Shutemov p++; 16*745e3ed8SKirill A. Shutemov } 17*745e3ed8SKirill A. Shutemov if (len) { 18*745e3ed8SKirill A. Shutemov mask_to_set &= BITMAP_LAST_WORD_MASK(size); 19*745e3ed8SKirill A. Shutemov *p |= mask_to_set; 20*745e3ed8SKirill A. Shutemov } 21*745e3ed8SKirill A. Shutemov } 22*745e3ed8SKirill A. Shutemov __bitmap_clear(unsigned long * map,unsigned int start,int len)23*745e3ed8SKirill A. Shutemovvoid __bitmap_clear(unsigned long *map, unsigned int start, int len) 24*745e3ed8SKirill A. Shutemov { 25*745e3ed8SKirill A. Shutemov unsigned long *p = map + BIT_WORD(start); 26*745e3ed8SKirill A. Shutemov const unsigned int size = start + len; 27*745e3ed8SKirill A. Shutemov int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); 28*745e3ed8SKirill A. Shutemov unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); 29*745e3ed8SKirill A. Shutemov 30*745e3ed8SKirill A. Shutemov while (len - bits_to_clear >= 0) { 31*745e3ed8SKirill A. Shutemov *p &= ~mask_to_clear; 32*745e3ed8SKirill A. Shutemov len -= bits_to_clear; 33*745e3ed8SKirill A. Shutemov bits_to_clear = BITS_PER_LONG; 34*745e3ed8SKirill A. Shutemov mask_to_clear = ~0UL; 35*745e3ed8SKirill A. Shutemov p++; 36*745e3ed8SKirill A. Shutemov } 37*745e3ed8SKirill A. Shutemov if (len) { 38*745e3ed8SKirill A. Shutemov mask_to_clear &= BITMAP_LAST_WORD_MASK(size); 39*745e3ed8SKirill A. Shutemov *p &= ~mask_to_clear; 40*745e3ed8SKirill A. Shutemov } 41*745e3ed8SKirill A. Shutemov } 42