Lines Matching refs:bmp
18 int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num) in msi_bitmap_alloc_hwirqs() argument
23 spin_lock_irqsave(&bmp->lock, flags); in msi_bitmap_alloc_hwirqs()
25 offset = bitmap_find_next_zero_area(bmp->bitmap, bmp->irq_count, 0, in msi_bitmap_alloc_hwirqs()
27 if (offset > bmp->irq_count) in msi_bitmap_alloc_hwirqs()
30 bitmap_set(bmp->bitmap, offset, num); in msi_bitmap_alloc_hwirqs()
31 spin_unlock_irqrestore(&bmp->lock, flags); in msi_bitmap_alloc_hwirqs()
37 spin_unlock_irqrestore(&bmp->lock, flags); in msi_bitmap_alloc_hwirqs()
42 void msi_bitmap_free_hwirqs(struct msi_bitmap *bmp, unsigned int offset, in msi_bitmap_free_hwirqs() argument
50 spin_lock_irqsave(&bmp->lock, flags); in msi_bitmap_free_hwirqs()
51 bitmap_clear(bmp->bitmap, offset, num); in msi_bitmap_free_hwirqs()
52 spin_unlock_irqrestore(&bmp->lock, flags); in msi_bitmap_free_hwirqs()
56 void msi_bitmap_reserve_hwirq(struct msi_bitmap *bmp, unsigned int hwirq) in msi_bitmap_reserve_hwirq() argument
62 spin_lock_irqsave(&bmp->lock, flags); in msi_bitmap_reserve_hwirq()
63 bitmap_allocate_region(bmp->bitmap, hwirq, 0); in msi_bitmap_reserve_hwirq()
64 spin_unlock_irqrestore(&bmp->lock, flags); in msi_bitmap_reserve_hwirq()
78 int msi_bitmap_reserve_dt_hwirqs(struct msi_bitmap *bmp) in msi_bitmap_reserve_dt_hwirqs() argument
83 if (!bmp->of_node) in msi_bitmap_reserve_dt_hwirqs()
86 p = of_get_property(bmp->of_node, "msi-available-ranges", &len); in msi_bitmap_reserve_dt_hwirqs()
89 "found on %s\n", bmp->of_node->full_name); in msi_bitmap_reserve_dt_hwirqs()
95 " property on %s\n", bmp->of_node->full_name); in msi_bitmap_reserve_dt_hwirqs()
99 bitmap_allocate_region(bmp->bitmap, 0, get_count_order(bmp->irq_count)); in msi_bitmap_reserve_dt_hwirqs()
101 spin_lock(&bmp->lock); in msi_bitmap_reserve_dt_hwirqs()
107 bitmap_release_region(bmp->bitmap, *p + j, 0); in msi_bitmap_reserve_dt_hwirqs()
110 spin_unlock(&bmp->lock); in msi_bitmap_reserve_dt_hwirqs()
115 int __init_refok msi_bitmap_alloc(struct msi_bitmap *bmp, unsigned int irq_count, in msi_bitmap_alloc() argument
126 bmp->bitmap_from_slab = slab_is_available(); in msi_bitmap_alloc()
127 if (bmp->bitmap_from_slab) in msi_bitmap_alloc()
128 bmp->bitmap = kzalloc(size, GFP_KERNEL); in msi_bitmap_alloc()
130 bmp->bitmap = memblock_virt_alloc(size, 0); in msi_bitmap_alloc()
132 kmemleak_not_leak(bmp->bitmap); in msi_bitmap_alloc()
135 if (!bmp->bitmap) { in msi_bitmap_alloc()
141 spin_lock_init(&bmp->lock); in msi_bitmap_alloc()
142 bmp->of_node = of_node_get(of_node); in msi_bitmap_alloc()
143 bmp->irq_count = irq_count; in msi_bitmap_alloc()
148 void msi_bitmap_free(struct msi_bitmap *bmp) in msi_bitmap_free() argument
150 if (bmp->bitmap_from_slab) in msi_bitmap_free()
151 kfree(bmp->bitmap); in msi_bitmap_free()
152 of_node_put(bmp->of_node); in msi_bitmap_free()
153 bmp->bitmap = NULL; in msi_bitmap_free()
160 struct msi_bitmap bmp; in test_basics() local
164 WARN_ON(msi_bitmap_alloc(&bmp, 0, NULL) == 0); in test_basics()
167 WARN_ON(msi_bitmap_alloc(&bmp, size, NULL)); in test_basics()
170 WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size))); in test_basics()
171 bitmap_release_region(bmp.bitmap, 0, get_count_order(size)); in test_basics()
174 WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0); in test_basics()
177 WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size))); in test_basics()
178 bitmap_release_region(bmp.bitmap, 0, get_count_order(size)); in test_basics()
182 WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) < 0); in test_basics()
184 WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) >= 0); in test_basics()
187 WARN_ON(bitmap_find_free_region(bmp.bitmap, size, 0) >= 0); in test_basics()
190 msi_bitmap_free_hwirqs(&bmp, size / 2, 1); in test_basics()
191 WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) != size / 2); in test_basics()
194 msi_bitmap_free_hwirqs(&bmp, 3, size - 3); in test_basics()
197 rc = msi_bitmap_alloc_hwirqs(&bmp, 2); in test_basics()
199 rc = msi_bitmap_alloc_hwirqs(&bmp, 4); in test_basics()
201 rc = msi_bitmap_alloc_hwirqs(&bmp, 8); in test_basics()
203 rc = msi_bitmap_alloc_hwirqs(&bmp, 9); in test_basics()
205 rc = msi_bitmap_alloc_hwirqs(&bmp, 3); in test_basics()
207 rc = msi_bitmap_alloc_hwirqs(&bmp, 7); in test_basics()
209 rc = msi_bitmap_alloc_hwirqs(&bmp, 121); in test_basics()
212 msi_bitmap_free(&bmp); in test_basics()
215 WARN_ON(bmp.bitmap != NULL); in test_basics()
226 struct msi_bitmap bmp; in test_of_node() local
235 WARN_ON(msi_bitmap_alloc(&bmp, size, &of_node)); in test_of_node()
238 WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0); in test_of_node()
241 WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size))); in test_of_node()
242 bitmap_release_region(bmp.bitmap, 0, get_count_order(size)); in test_of_node()
255 WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp)); in test_of_node()
259 WARN_ON(!bitmap_equal(expected, bmp.bitmap, size)); in test_of_node()
261 msi_bitmap_free(&bmp); in test_of_node()
262 kfree(bmp.bitmap); in test_of_node()