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
86 alloc->last = 0; in mthca_alloc_init()
87 alloc->top = 0; in mthca_alloc_init()
88 alloc->max = num; in mthca_alloc_init()
89 alloc->mask = mask; in mthca_alloc_init()
90 spin_lock_init(&alloc->lock); in mthca_alloc_init()
91 alloc->table = bitmap_zalloc(num, GFP_KERNEL); in mthca_alloc_init()
92 if (!alloc->table) in mthca_alloc_init()
95 bitmap_set(alloc->table, 0, reserved); in mthca_alloc_init()
100 void mthca_alloc_cleanup(struct mthca_alloc *alloc) in mthca_alloc_cleanup() argument
102 bitmap_free(alloc->table); in mthca_alloc_cleanup()