^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Support for adapter interruptions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM Corp. 1999, 2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author(s): Ingo Adlung <adlung@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Cornelia Huck <cornelia.huck@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Arnd Bergmann <arndb@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/dmapool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/airq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/isc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/cio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "cio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "cio_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "ioasm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static DEFINE_SPINLOCK(airq_lists_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static struct hlist_head airq_lists[MAX_ISC+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static struct dma_pool *airq_iv_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * register_adapter_interrupt() - register adapter interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * @airq: pointer to adapter interrupt descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Returns 0 on success, or -EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int register_adapter_interrupt(struct airq_struct *airq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) char dbf_txt[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (!airq->handler || airq->isc > MAX_ISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!airq->lsi_ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) airq->lsi_ptr = kzalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (!airq->lsi_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) airq->flags |= AIRQ_PTR_ALLOCATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (!airq->lsi_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) airq->lsi_mask = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) snprintf(dbf_txt, sizeof(dbf_txt), "rairq:%p", airq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) CIO_TRACE_EVENT(4, dbf_txt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) isc_register(airq->isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) spin_lock(&airq_lists_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) hlist_add_head_rcu(&airq->list, &airq_lists[airq->isc]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) spin_unlock(&airq_lists_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) EXPORT_SYMBOL(register_adapter_interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * unregister_adapter_interrupt - unregister adapter interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @airq: pointer to adapter interrupt descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) void unregister_adapter_interrupt(struct airq_struct *airq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) char dbf_txt[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (hlist_unhashed(&airq->list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) snprintf(dbf_txt, sizeof(dbf_txt), "urairq:%p", airq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) CIO_TRACE_EVENT(4, dbf_txt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) spin_lock(&airq_lists_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) hlist_del_rcu(&airq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) spin_unlock(&airq_lists_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) isc_unregister(airq->isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (airq->flags & AIRQ_PTR_ALLOCATED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) kfree(airq->lsi_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) airq->lsi_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) airq->flags &= ~AIRQ_PTR_ALLOCATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) EXPORT_SYMBOL(unregister_adapter_interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static irqreturn_t do_airq_interrupt(int irq, void *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct tpi_info *tpi_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct airq_struct *airq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) set_cpu_flag(CIF_NOHZ_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) tpi_info = (struct tpi_info *) &get_irq_regs()->int_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) trace_s390_cio_adapter_int(tpi_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) head = &airq_lists[tpi_info->isc];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) hlist_for_each_entry_rcu(airq, head, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if ((*airq->lsi_ptr & airq->lsi_mask) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) airq->handler(airq, !tpi_info->directed_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void __init init_airq_interrupts(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) irq_set_chip_and_handler(THIN_INTERRUPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) &dummy_irq_chip, handle_percpu_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (request_irq(THIN_INTERRUPT, do_airq_interrupt, 0, "AIO", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) panic("Failed to register AIO interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static inline unsigned long iv_size(unsigned long bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return BITS_TO_LONGS(bits) * sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * airq_iv_create - create an interrupt vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * @bits: number of bits in the interrupt vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * @flags: allocation flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * Returns a pointer to an interrupt vector structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct airq_iv *iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) iv = kzalloc(sizeof(*iv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (!iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) iv->bits = bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) iv->flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) size = iv_size(bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (flags & AIRQ_IV_CACHELINE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if ((cache_line_size() * BITS_PER_BYTE) < bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) || !airq_iv_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) iv->vector = dma_pool_zalloc(airq_iv_cache, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) &iv->vector_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!iv->vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) iv->vector = cio_dma_zalloc(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!iv->vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (flags & AIRQ_IV_ALLOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) iv->avail = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!iv->avail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) memset(iv->avail, 0xff, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) iv->end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) iv->end = bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (flags & AIRQ_IV_BITLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) iv->bitlock = kzalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (!iv->bitlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (flags & AIRQ_IV_PTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) size = bits * sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) iv->ptr = kzalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!iv->ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (flags & AIRQ_IV_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) size = bits * sizeof(unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) iv->data = kzalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (!iv->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) spin_lock_init(&iv->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) kfree(iv->ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) kfree(iv->bitlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) kfree(iv->avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (iv->flags & AIRQ_IV_CACHELINE && iv->vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) dma_pool_free(airq_iv_cache, iv->vector, iv->vector_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) cio_dma_free(iv->vector, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) kfree(iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) EXPORT_SYMBOL(airq_iv_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * airq_iv_release - release an interrupt vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * @iv: pointer to interrupt vector structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) void airq_iv_release(struct airq_iv *iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) kfree(iv->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) kfree(iv->ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) kfree(iv->bitlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (iv->flags & AIRQ_IV_CACHELINE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) dma_pool_free(airq_iv_cache, iv->vector, iv->vector_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) cio_dma_free(iv->vector, iv_size(iv->bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) kfree(iv->avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) kfree(iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) EXPORT_SYMBOL(airq_iv_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * airq_iv_alloc - allocate irq bits from an interrupt vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * @iv: pointer to an interrupt vector structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * @num: number of consecutive irq bits to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * Returns the bit number of the first irq in the allocated block of irqs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * or -1UL if no bit is available or the AIRQ_IV_ALLOC flag has not been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) unsigned long bit, i, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!iv->avail || num == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return -1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) spin_lock_irqsave(&iv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) bit = find_first_bit_inv(iv->avail, iv->bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) while (bit + num <= iv->bits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) for (i = 1; i < num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (!test_bit_inv(bit + i, iv->avail))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (i >= num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* Found a suitable block of irqs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) for (i = 0; i < num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) clear_bit_inv(bit + i, iv->avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (bit + num >= iv->end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) iv->end = bit + num + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) bit = find_next_bit_inv(iv->avail, iv->bits, bit + i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (bit + num > iv->bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) bit = -1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) spin_unlock_irqrestore(&iv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) EXPORT_SYMBOL(airq_iv_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * airq_iv_free - free irq bits of an interrupt vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * @iv: pointer to interrupt vector structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * @bit: number of the first irq bit to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * @num: number of consecutive irq bits to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) unsigned long i, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (!iv->avail || num == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) spin_lock_irqsave(&iv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) for (i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Clear (possibly left over) interrupt bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) clear_bit_inv(bit + i, iv->vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Make the bit positions available again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) set_bit_inv(bit + i, iv->avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (bit + num >= iv->end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* Find new end of bit-field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) while (iv->end > 0 && !test_bit_inv(iv->end - 1, iv->avail))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) iv->end--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) spin_unlock_irqrestore(&iv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) EXPORT_SYMBOL(airq_iv_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * airq_iv_scan - scan interrupt vector for non-zero bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * @iv: pointer to interrupt vector structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * @start: bit number to start the search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * @end: bit number to end the search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Returns the bit number of the next non-zero interrupt bit, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * -1UL if the scan completed without finding any more any non-zero bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) unsigned long airq_iv_scan(struct airq_iv *iv, unsigned long start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) unsigned long bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* Find non-zero bit starting from 'ivs->next'. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) bit = find_next_bit_inv(iv->vector, end, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (bit >= end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return -1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) clear_bit_inv(bit, iv->vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) EXPORT_SYMBOL(airq_iv_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) int __init airq_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) airq_iv_cache = dma_pool_create("airq_iv_cache", cio_get_dma_css_dev(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) cache_line_size(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) cache_line_size(), PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (!airq_iv_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }