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