Lines Matching +full:num +full:- +full:irqs
1 // SPDX-License-Identifier: GPL-2.0
35 * register_adapter_interrupt() - register adapter interrupt handler
38 * Returns 0 on success, or -EINVAL.
44 if (!airq->handler || airq->isc > MAX_ISC) in register_adapter_interrupt()
45 return -EINVAL; in register_adapter_interrupt()
46 if (!airq->lsi_ptr) { in register_adapter_interrupt()
47 airq->lsi_ptr = cio_dma_zalloc(1); in register_adapter_interrupt()
48 if (!airq->lsi_ptr) in register_adapter_interrupt()
49 return -ENOMEM; in register_adapter_interrupt()
50 airq->flags |= AIRQ_PTR_ALLOCATED; in register_adapter_interrupt()
54 isc_register(airq->isc); in register_adapter_interrupt()
56 hlist_add_head_rcu(&airq->list, &airq_lists[airq->isc]); in register_adapter_interrupt()
63 * unregister_adapter_interrupt - unregister adapter interrupt handler
70 if (hlist_unhashed(&airq->list)) in unregister_adapter_interrupt()
75 hlist_del_rcu(&airq->list); in unregister_adapter_interrupt()
78 isc_unregister(airq->isc); in unregister_adapter_interrupt()
79 if (airq->flags & AIRQ_PTR_ALLOCATED) { in unregister_adapter_interrupt()
80 cio_dma_free(airq->lsi_ptr, 1); in unregister_adapter_interrupt()
81 airq->lsi_ptr = NULL; in unregister_adapter_interrupt()
82 airq->flags &= ~AIRQ_PTR_ALLOCATED; in unregister_adapter_interrupt()
93 tpi_info = &get_irq_regs()->tpi_info; in do_airq_interrupt()
95 head = &airq_lists[tpi_info->isc]; in do_airq_interrupt()
98 if (*airq->lsi_ptr != 0) in do_airq_interrupt()
99 airq->handler(airq, tpi_info); in do_airq_interrupt()
119 * airq_iv_create - create an interrupt vector
135 iv->bits = bits; in airq_iv_create()
136 iv->flags = flags; in airq_iv_create()
144 iv->vector = dma_pool_zalloc(airq_iv_cache, GFP_KERNEL, in airq_iv_create()
145 &iv->vector_dma); in airq_iv_create()
146 if (!iv->vector) in airq_iv_create()
149 iv->vector = vec; in airq_iv_create()
151 iv->vector = cio_dma_zalloc(size); in airq_iv_create()
152 if (!iv->vector) in airq_iv_create()
156 iv->avail = kmalloc(size, GFP_KERNEL); in airq_iv_create()
157 if (!iv->avail) in airq_iv_create()
159 memset(iv->avail, 0xff, size); in airq_iv_create()
160 iv->end = 0; in airq_iv_create()
162 iv->end = bits; in airq_iv_create()
164 iv->bitlock = kzalloc(size, GFP_KERNEL); in airq_iv_create()
165 if (!iv->bitlock) in airq_iv_create()
170 iv->ptr = kzalloc(size, GFP_KERNEL); in airq_iv_create()
171 if (!iv->ptr) in airq_iv_create()
176 iv->data = kzalloc(size, GFP_KERNEL); in airq_iv_create()
177 if (!iv->data) in airq_iv_create()
180 spin_lock_init(&iv->lock); in airq_iv_create()
184 kfree(iv->ptr); in airq_iv_create()
185 kfree(iv->bitlock); in airq_iv_create()
186 kfree(iv->avail); in airq_iv_create()
187 if (iv->flags & AIRQ_IV_CACHELINE && iv->vector) in airq_iv_create()
188 dma_pool_free(airq_iv_cache, iv->vector, iv->vector_dma); in airq_iv_create()
189 else if (!(iv->flags & AIRQ_IV_GUESTVEC)) in airq_iv_create()
190 cio_dma_free(iv->vector, size); in airq_iv_create()
198 * airq_iv_release - release an interrupt vector
203 kfree(iv->data); in airq_iv_release()
204 kfree(iv->ptr); in airq_iv_release()
205 kfree(iv->bitlock); in airq_iv_release()
206 if (iv->flags & AIRQ_IV_CACHELINE) in airq_iv_release()
207 dma_pool_free(airq_iv_cache, iv->vector, iv->vector_dma); in airq_iv_release()
208 else if (!(iv->flags & AIRQ_IV_GUESTVEC)) in airq_iv_release()
209 cio_dma_free(iv->vector, iv_size(iv->bits)); in airq_iv_release()
210 kfree(iv->avail); in airq_iv_release()
216 * airq_iv_alloc - allocate irq bits from an interrupt vector
218 * @num: number of consecutive irq bits to allocate
220 * Returns the bit number of the first irq in the allocated block of irqs,
221 * or -1UL if no bit is available or the AIRQ_IV_ALLOC flag has not been
224 unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num) in airq_iv_alloc() argument
228 if (!iv->avail || num == 0) in airq_iv_alloc()
229 return -1UL; in airq_iv_alloc()
230 spin_lock_irqsave(&iv->lock, flags); in airq_iv_alloc()
231 bit = find_first_bit_inv(iv->avail, iv->bits); in airq_iv_alloc()
232 while (bit + num <= iv->bits) { in airq_iv_alloc()
233 for (i = 1; i < num; i++) in airq_iv_alloc()
234 if (!test_bit_inv(bit + i, iv->avail)) in airq_iv_alloc()
236 if (i >= num) { in airq_iv_alloc()
237 /* Found a suitable block of irqs */ in airq_iv_alloc()
238 for (i = 0; i < num; i++) in airq_iv_alloc()
239 clear_bit_inv(bit + i, iv->avail); in airq_iv_alloc()
240 if (bit + num >= iv->end) in airq_iv_alloc()
241 iv->end = bit + num + 1; in airq_iv_alloc()
244 bit = find_next_bit_inv(iv->avail, iv->bits, bit + i + 1); in airq_iv_alloc()
246 if (bit + num > iv->bits) in airq_iv_alloc()
247 bit = -1UL; in airq_iv_alloc()
248 spin_unlock_irqrestore(&iv->lock, flags); in airq_iv_alloc()
254 * airq_iv_free - free irq bits of an interrupt vector
257 * @num: number of consecutive irq bits to free
259 void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num) in airq_iv_free() argument
263 if (!iv->avail || num == 0) in airq_iv_free()
265 spin_lock_irqsave(&iv->lock, flags); in airq_iv_free()
266 for (i = 0; i < num; i++) { in airq_iv_free()
268 clear_bit_inv(bit + i, iv->vector); in airq_iv_free()
270 set_bit_inv(bit + i, iv->avail); in airq_iv_free()
272 if (bit + num >= iv->end) { in airq_iv_free()
273 /* Find new end of bit-field */ in airq_iv_free()
274 while (iv->end > 0 && !test_bit_inv(iv->end - 1, iv->avail)) in airq_iv_free()
275 iv->end--; in airq_iv_free()
277 spin_unlock_irqrestore(&iv->lock, flags); in airq_iv_free()
282 * airq_iv_scan - scan interrupt vector for non-zero bits
287 * Returns the bit number of the next non-zero interrupt bit, or
288 * -1UL if the scan completed without finding any more any non-zero bits.
295 /* Find non-zero bit starting from 'ivs->next'. */ in airq_iv_scan()
296 bit = find_next_bit_inv(iv->vector, end, start); in airq_iv_scan()
298 return -1UL; in airq_iv_scan()
299 clear_bit_inv(bit, iv->vector); in airq_iv_scan()
310 return -ENOMEM; in airq_init()