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