Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/airq: add support for irq ranges

Add airq_iv_alloc and airq_iv_free to allocate and free consecutive
ranges of irqs from the interrupt vector.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

authored by

Martin Schwidefsky and committed by
Christian Borntraeger
84ec96a6 2e021043

+53 -27
+12 -2
arch/s390/include/asm/airq.h
··· 44 44 45 45 struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags); 46 46 void airq_iv_release(struct airq_iv *iv); 47 - unsigned long airq_iv_alloc_bit(struct airq_iv *iv); 48 - void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit); 47 + unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num); 48 + void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num); 49 49 unsigned long airq_iv_scan(struct airq_iv *iv, unsigned long start, 50 50 unsigned long end); 51 + 52 + static inline unsigned long airq_iv_alloc_bit(struct airq_iv *iv) 53 + { 54 + return airq_iv_alloc(iv, 1); 55 + } 56 + 57 + static inline void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit) 58 + { 59 + airq_iv_free(iv, bit, 1); 60 + } 51 61 52 62 static inline unsigned long airq_iv_end(struct airq_iv *iv) 53 63 {
+41 -25
drivers/s390/cio/airq.c
··· 186 186 EXPORT_SYMBOL(airq_iv_release); 187 187 188 188 /** 189 - * airq_iv_alloc_bit - allocate an irq bit from an interrupt vector 189 + * airq_iv_alloc - allocate irq bits from an interrupt vector 190 190 * @iv: pointer to an interrupt vector structure 191 + * @num: number of consecutive irq bits to allocate 191 192 * 192 - * Returns the bit number of the allocated irq, or -1UL if no bit 193 - * is available or the AIRQ_IV_ALLOC flag has not been specified 193 + * Returns the bit number of the first irq in the allocated block of irqs, 194 + * or -1UL if no bit is available or the AIRQ_IV_ALLOC flag has not been 195 + * specified 194 196 */ 195 - unsigned long airq_iv_alloc_bit(struct airq_iv *iv) 197 + unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num) 196 198 { 197 - unsigned long bit; 199 + unsigned long bit, i; 198 200 199 - if (!iv->avail) 201 + if (!iv->avail || num == 0) 200 202 return -1UL; 201 203 spin_lock(&iv->lock); 202 204 bit = find_first_bit_inv(iv->avail, iv->bits); 203 - if (bit < iv->bits) { 204 - clear_bit_inv(bit, iv->avail); 205 - if (bit >= iv->end) 206 - iv->end = bit + 1; 207 - } else 205 + while (bit + num <= iv->bits) { 206 + for (i = 1; i < num; i++) 207 + if (!test_bit_inv(bit + i, iv->avail)) 208 + break; 209 + if (i >= num) { 210 + /* Found a suitable block of irqs */ 211 + for (i = 0; i < num; i++) 212 + clear_bit_inv(bit + i, iv->avail); 213 + if (bit + num >= iv->end) 214 + iv->end = bit + num + 1; 215 + break; 216 + } 217 + bit = find_next_bit_inv(iv->avail, iv->bits, bit + i + 1); 218 + } 219 + if (bit + num > iv->bits) 208 220 bit = -1UL; 209 221 spin_unlock(&iv->lock); 210 222 return bit; 211 223 212 224 } 213 - EXPORT_SYMBOL(airq_iv_alloc_bit); 225 + EXPORT_SYMBOL(airq_iv_alloc); 214 226 215 227 /** 216 - * airq_iv_free_bit - free an irq bit of an interrupt vector 228 + * airq_iv_free - free irq bits of an interrupt vector 217 229 * @iv: pointer to interrupt vector structure 218 - * @bit: number of the irq bit to free 230 + * @bit: number of the first irq bit to free 231 + * @num: number of consecutive irq bits to free 219 232 */ 220 - void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit) 233 + void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num) 221 234 { 222 - if (!iv->avail) 235 + unsigned long i; 236 + 237 + if (!iv->avail || num == 0) 223 238 return; 224 239 spin_lock(&iv->lock); 225 - /* Clear (possibly left over) interrupt bit */ 226 - clear_bit_inv(bit, iv->vector); 227 - /* Make the bit position available again */ 228 - set_bit_inv(bit, iv->avail); 229 - if (bit == iv->end - 1) { 240 + for (i = 0; i < num; i++) { 241 + /* Clear (possibly left over) interrupt bit */ 242 + clear_bit_inv(bit + i, iv->vector); 243 + /* Make the bit positions available again */ 244 + set_bit_inv(bit + i, iv->avail); 245 + } 246 + if (bit + num >= iv->end) { 230 247 /* Find new end of bit-field */ 231 - while (--iv->end > 0) 232 - if (!test_bit_inv(iv->end - 1, iv->avail)) 233 - break; 248 + while (iv->end > 0 && !test_bit_inv(iv->end - 1, iv->avail)) 249 + iv->end--; 234 250 } 235 251 spin_unlock(&iv->lock); 236 252 } 237 - EXPORT_SYMBOL(airq_iv_free_bit); 253 + EXPORT_SYMBOL(airq_iv_free); 238 254 239 255 /** 240 256 * airq_iv_scan - scan interrupt vector for non-zero bits