diff options
author | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2013-06-25 08:17:57 -0400 |
---|---|---|
committer | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2013-08-22 06:20:02 -0400 |
commit | a9a6f0341df9a634a98aaf252c89962af77d1376 (patch) | |
tree | 92efad15aad3ce29bc86e97720966e06779e6cfb /drivers/s390 | |
parent | 0ea46b0e371e3ccc0ce666c4988a7961e4ffa8ec (diff) |
s390/airq: introduce adapter interrupt vector helper
The PCI code is the first user of adapter interrupts vectors.
Add a set of helpers to airq.c to separate the adatper interrupt
code from the PCI bits. The helpers allow for adapter interrupt
vectors of any size.
Reviewed-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'drivers/s390')
-rw-r--r-- | drivers/s390/cio/airq.c | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/drivers/s390/cio/airq.c b/drivers/s390/cio/airq.c index 91edbd7ee806..6ead6d076445 100644 --- a/drivers/s390/cio/airq.c +++ b/drivers/s390/cio/airq.c | |||
@@ -93,3 +93,156 @@ void do_adapter_IO(u8 isc) | |||
93 | airq->handler(airq); | 93 | airq->handler(airq); |
94 | rcu_read_unlock(); | 94 | rcu_read_unlock(); |
95 | } | 95 | } |
96 | |||
97 | /** | ||
98 | * airq_iv_create - create an interrupt vector | ||
99 | * @bits: number of bits in the interrupt vector | ||
100 | * @flags: allocation flags | ||
101 | * | ||
102 | * Returns a pointer to an interrupt vector structure | ||
103 | */ | ||
104 | struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags) | ||
105 | { | ||
106 | struct airq_iv *iv; | ||
107 | unsigned long size; | ||
108 | |||
109 | iv = kzalloc(sizeof(*iv), GFP_KERNEL); | ||
110 | if (!iv) | ||
111 | goto out; | ||
112 | iv->bits = bits; | ||
113 | size = BITS_TO_LONGS(bits) * sizeof(unsigned long); | ||
114 | iv->vector = kzalloc(size, GFP_KERNEL); | ||
115 | if (!iv->vector) | ||
116 | goto out_free; | ||
117 | if (flags & AIRQ_IV_ALLOC) { | ||
118 | iv->avail = kmalloc(size, GFP_KERNEL); | ||
119 | if (!iv->avail) | ||
120 | goto out_free; | ||
121 | memset(iv->avail, 0xff, size); | ||
122 | iv->end = 0; | ||
123 | } else | ||
124 | iv->end = bits; | ||
125 | if (flags & AIRQ_IV_BITLOCK) { | ||
126 | iv->bitlock = kzalloc(size, GFP_KERNEL); | ||
127 | if (!iv->bitlock) | ||
128 | goto out_free; | ||
129 | } | ||
130 | if (flags & AIRQ_IV_PTR) { | ||
131 | size = bits * sizeof(unsigned long); | ||
132 | iv->ptr = kzalloc(size, GFP_KERNEL); | ||
133 | if (!iv->ptr) | ||
134 | goto out_free; | ||
135 | } | ||
136 | if (flags & AIRQ_IV_DATA) { | ||
137 | size = bits * sizeof(unsigned int); | ||
138 | iv->data = kzalloc(size, GFP_KERNEL); | ||
139 | if (!iv->data) | ||
140 | goto out_free; | ||
141 | } | ||
142 | spin_lock_init(&iv->lock); | ||
143 | return iv; | ||
144 | |||
145 | out_free: | ||
146 | kfree(iv->ptr); | ||
147 | kfree(iv->bitlock); | ||
148 | kfree(iv->avail); | ||
149 | kfree(iv->vector); | ||
150 | kfree(iv); | ||
151 | out: | ||
152 | return NULL; | ||
153 | } | ||
154 | EXPORT_SYMBOL(airq_iv_create); | ||
155 | |||
156 | /** | ||
157 | * airq_iv_release - release an interrupt vector | ||
158 | * @iv: pointer to interrupt vector structure | ||
159 | */ | ||
160 | void airq_iv_release(struct airq_iv *iv) | ||
161 | { | ||
162 | kfree(iv->data); | ||
163 | kfree(iv->ptr); | ||
164 | kfree(iv->bitlock); | ||
165 | kfree(iv->vector); | ||
166 | kfree(iv->avail); | ||
167 | kfree(iv); | ||
168 | } | ||
169 | EXPORT_SYMBOL(airq_iv_release); | ||
170 | |||
171 | /** | ||
172 | * airq_iv_alloc_bit - allocate an irq bit from an interrupt vector | ||
173 | * @iv: pointer to an interrupt vector structure | ||
174 | * | ||
175 | * Returns the bit number of the allocated irq, or -1UL if no bit | ||
176 | * is available or the AIRQ_IV_ALLOC flag has not been specified | ||
177 | */ | ||
178 | unsigned long airq_iv_alloc_bit(struct airq_iv *iv) | ||
179 | { | ||
180 | const unsigned long be_to_le = BITS_PER_LONG - 1; | ||
181 | unsigned long bit; | ||
182 | |||
183 | if (!iv->avail) | ||
184 | return -1UL; | ||
185 | spin_lock(&iv->lock); | ||
186 | bit = find_first_bit_left(iv->avail, iv->bits); | ||
187 | if (bit < iv->bits) { | ||
188 | clear_bit(bit ^ be_to_le, iv->avail); | ||
189 | if (bit >= iv->end) | ||
190 | iv->end = bit + 1; | ||
191 | } else | ||
192 | bit = -1UL; | ||
193 | spin_unlock(&iv->lock); | ||
194 | return bit; | ||
195 | |||
196 | } | ||
197 | EXPORT_SYMBOL(airq_iv_alloc_bit); | ||
198 | |||
199 | /** | ||
200 | * airq_iv_free_bit - free an irq bit of an interrupt vector | ||
201 | * @iv: pointer to interrupt vector structure | ||
202 | * @bit: number of the irq bit to free | ||
203 | */ | ||
204 | void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit) | ||
205 | { | ||
206 | const unsigned long be_to_le = BITS_PER_LONG - 1; | ||
207 | |||
208 | if (!iv->avail) | ||
209 | return; | ||
210 | spin_lock(&iv->lock); | ||
211 | /* Clear (possibly left over) interrupt bit */ | ||
212 | clear_bit(bit ^ be_to_le, iv->vector); | ||
213 | /* Make the bit position available again */ | ||
214 | set_bit(bit ^ be_to_le, iv->avail); | ||
215 | if (bit == iv->end - 1) { | ||
216 | /* Find new end of bit-field */ | ||
217 | while (--iv->end > 0) | ||
218 | if (!test_bit((iv->end - 1) ^ be_to_le, iv->avail)) | ||
219 | break; | ||
220 | } | ||
221 | spin_unlock(&iv->lock); | ||
222 | } | ||
223 | EXPORT_SYMBOL(airq_iv_free_bit); | ||
224 | |||
225 | /** | ||
226 | * airq_iv_scan - scan interrupt vector for non-zero bits | ||
227 | * @iv: pointer to interrupt vector structure | ||
228 | * @start: bit number to start the search | ||
229 | * @end: bit number to end the search | ||
230 | * | ||
231 | * Returns the bit number of the next non-zero interrupt bit, or | ||
232 | * -1UL if the scan completed without finding any more any non-zero bits. | ||
233 | */ | ||
234 | unsigned long airq_iv_scan(struct airq_iv *iv, unsigned long start, | ||
235 | unsigned long end) | ||
236 | { | ||
237 | const unsigned long be_to_le = BITS_PER_LONG - 1; | ||
238 | unsigned long bit; | ||
239 | |||
240 | /* Find non-zero bit starting from 'ivs->next'. */ | ||
241 | bit = find_next_bit_left(iv->vector, end, start); | ||
242 | if (bit >= end) | ||
243 | return -1UL; | ||
244 | /* Clear interrupt bit (find left uses big-endian bit numbers) */ | ||
245 | clear_bit(bit ^ be_to_le, iv->vector); | ||
246 | return bit; | ||
247 | } | ||
248 | EXPORT_SYMBOL(airq_iv_scan); | ||