Lines Matching refs:alloc

40 u32 mthca_alloc(struct mthca_alloc *alloc)  in mthca_alloc()  argument
45 spin_lock_irqsave(&alloc->lock, flags); in mthca_alloc()
47 obj = find_next_zero_bit(alloc->table, alloc->max, alloc->last); in mthca_alloc()
48 if (obj >= alloc->max) { in mthca_alloc()
49 alloc->top = (alloc->top + alloc->max) & alloc->mask; in mthca_alloc()
50 obj = find_first_zero_bit(alloc->table, alloc->max); in mthca_alloc()
53 if (obj < alloc->max) { in mthca_alloc()
54 set_bit(obj, alloc->table); in mthca_alloc()
55 obj |= alloc->top; in mthca_alloc()
59 spin_unlock_irqrestore(&alloc->lock, flags); in mthca_alloc()
64 void mthca_free(struct mthca_alloc *alloc, u32 obj) in mthca_free() argument
68 obj &= alloc->max - 1; in mthca_free()
70 spin_lock_irqsave(&alloc->lock, flags); in mthca_free()
72 clear_bit(obj, alloc->table); in mthca_free()
73 alloc->last = min(alloc->last, obj); in mthca_free()
74 alloc->top = (alloc->top + alloc->max) & alloc->mask; in mthca_free()
76 spin_unlock_irqrestore(&alloc->lock, flags); in mthca_free()
79 int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask, in mthca_alloc_init() argument
88 alloc->last = 0; in mthca_alloc_init()
89 alloc->top = 0; in mthca_alloc_init()
90 alloc->max = num; in mthca_alloc_init()
91 alloc->mask = mask; in mthca_alloc_init()
92 spin_lock_init(&alloc->lock); in mthca_alloc_init()
93 alloc->table = kmalloc(BITS_TO_LONGS(num) * sizeof (long), in mthca_alloc_init()
95 if (!alloc->table) in mthca_alloc_init()
98 bitmap_zero(alloc->table, num); in mthca_alloc_init()
100 set_bit(i, alloc->table); in mthca_alloc_init()
105 void mthca_alloc_cleanup(struct mthca_alloc *alloc) in mthca_alloc_cleanup() argument
107 kfree(alloc->table); in mthca_alloc_cleanup()