* Alloc unique interrupt number (resource handle) for interrupt source. * * There could be various strategies how to allocate free interrupt number * (resource handle) for new interrupt source. * * 1. Handles are always allocated forward, so handles are not recycled * immediately. However, if only one free handle left which is reused * constantly... */
| 399 | * constantly... |
| 400 | */ |
| 401 | static inline int |
| 402 | isrc_alloc_irq(struct intr_irqsrc *isrc) |
| 403 | { |
| 404 | u_int maxirqs, irq; |
| 405 | |
| 406 | mtx_assert(&isrc_table_lock, MA_OWNED); |
| 407 | |
| 408 | maxirqs = intr_nirq; |
| 409 | if (irq_next_free >= maxirqs) |
| 410 | return (ENOSPC); |
| 411 | |
| 412 | for (irq = irq_next_free; irq < maxirqs; irq++) { |
| 413 | if (irq_sources[irq] == NULL) |
| 414 | goto found; |
| 415 | } |
| 416 | for (irq = 0; irq < irq_next_free; irq++) { |
| 417 | if (irq_sources[irq] == NULL) |
| 418 | goto found; |
| 419 | } |
| 420 | |
| 421 | irq_next_free = maxirqs; |
| 422 | return (ENOSPC); |
| 423 | |
| 424 | found: |
| 425 | isrc->isrc_irq = irq; |
| 426 | irq_sources[irq] = isrc; |
| 427 | |
| 428 | irq_next_free = irq + 1; |
| 429 | if (irq_next_free >= maxirqs) |
| 430 | irq_next_free = 0; |
| 431 | return (0); |
| 432 | } |
| 433 | |
| 434 | /* |
| 435 | * Free unique interrupt number (resource handle) from interrupt source. |
no test coverage detected