Lines Matching refs:bitmap
39 int hns_roce_bitmap_alloc(struct hns_roce_bitmap *bitmap, unsigned long *obj) in hns_roce_bitmap_alloc() argument
43 spin_lock(&bitmap->lock); in hns_roce_bitmap_alloc()
44 *obj = find_next_zero_bit(bitmap->table, bitmap->max, bitmap->last); in hns_roce_bitmap_alloc()
45 if (*obj >= bitmap->max) { in hns_roce_bitmap_alloc()
46 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) in hns_roce_bitmap_alloc()
47 & bitmap->mask; in hns_roce_bitmap_alloc()
48 *obj = find_first_zero_bit(bitmap->table, bitmap->max); in hns_roce_bitmap_alloc()
51 if (*obj < bitmap->max) { in hns_roce_bitmap_alloc()
52 set_bit(*obj, bitmap->table); in hns_roce_bitmap_alloc()
53 bitmap->last = (*obj + 1); in hns_roce_bitmap_alloc()
54 if (bitmap->last == bitmap->max) in hns_roce_bitmap_alloc()
55 bitmap->last = 0; in hns_roce_bitmap_alloc()
56 *obj |= bitmap->top; in hns_roce_bitmap_alloc()
61 spin_unlock(&bitmap->lock); in hns_roce_bitmap_alloc()
66 void hns_roce_bitmap_free(struct hns_roce_bitmap *bitmap, unsigned long obj, in hns_roce_bitmap_free() argument
69 hns_roce_bitmap_free_range(bitmap, obj, 1, rr); in hns_roce_bitmap_free()
72 int hns_roce_bitmap_alloc_range(struct hns_roce_bitmap *bitmap, int cnt, in hns_roce_bitmap_alloc_range() argument
79 return hns_roce_bitmap_alloc(bitmap, obj); in hns_roce_bitmap_alloc_range()
81 spin_lock(&bitmap->lock); in hns_roce_bitmap_alloc_range()
83 *obj = bitmap_find_next_zero_area(bitmap->table, bitmap->max, in hns_roce_bitmap_alloc_range()
84 bitmap->last, cnt, align - 1); in hns_roce_bitmap_alloc_range()
85 if (*obj >= bitmap->max) { in hns_roce_bitmap_alloc_range()
86 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) in hns_roce_bitmap_alloc_range()
87 & bitmap->mask; in hns_roce_bitmap_alloc_range()
88 *obj = bitmap_find_next_zero_area(bitmap->table, bitmap->max, 0, in hns_roce_bitmap_alloc_range()
92 if (*obj < bitmap->max) { in hns_roce_bitmap_alloc_range()
94 set_bit(*obj + i, bitmap->table); in hns_roce_bitmap_alloc_range()
96 if (*obj == bitmap->last) { in hns_roce_bitmap_alloc_range()
97 bitmap->last = (*obj + cnt); in hns_roce_bitmap_alloc_range()
98 if (bitmap->last >= bitmap->max) in hns_roce_bitmap_alloc_range()
99 bitmap->last = 0; in hns_roce_bitmap_alloc_range()
101 *obj |= bitmap->top; in hns_roce_bitmap_alloc_range()
106 spin_unlock(&bitmap->lock); in hns_roce_bitmap_alloc_range()
111 void hns_roce_bitmap_free_range(struct hns_roce_bitmap *bitmap, in hns_roce_bitmap_free_range() argument
117 obj &= bitmap->max + bitmap->reserved_top - 1; in hns_roce_bitmap_free_range()
119 spin_lock(&bitmap->lock); in hns_roce_bitmap_free_range()
121 clear_bit(obj + i, bitmap->table); in hns_roce_bitmap_free_range()
124 bitmap->last = min(bitmap->last, obj); in hns_roce_bitmap_free_range()
125 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) in hns_roce_bitmap_free_range()
126 & bitmap->mask; in hns_roce_bitmap_free_range()
127 spin_unlock(&bitmap->lock); in hns_roce_bitmap_free_range()
130 int hns_roce_bitmap_init(struct hns_roce_bitmap *bitmap, u32 num, u32 mask, in hns_roce_bitmap_init() argument
138 bitmap->last = 0; in hns_roce_bitmap_init()
139 bitmap->top = 0; in hns_roce_bitmap_init()
140 bitmap->max = num - reserved_top; in hns_roce_bitmap_init()
141 bitmap->mask = mask; in hns_roce_bitmap_init()
142 bitmap->reserved_top = reserved_top; in hns_roce_bitmap_init()
143 spin_lock_init(&bitmap->lock); in hns_roce_bitmap_init()
144 bitmap->table = kcalloc(BITS_TO_LONGS(bitmap->max), sizeof(long), in hns_roce_bitmap_init()
146 if (!bitmap->table) in hns_roce_bitmap_init()
150 set_bit(i, bitmap->table); in hns_roce_bitmap_init()
155 void hns_roce_bitmap_cleanup(struct hns_roce_bitmap *bitmap) in hns_roce_bitmap_cleanup() argument
157 kfree(bitmap->table); in hns_roce_bitmap_cleanup()