ep93xx_intr.c revision 1.4 1 1.4 joff /* $NetBSD: ep93xx_intr.c,v 1.4 2005/08/14 03:10:16 joff Exp $ */
2 1.1 joff
3 1.1 joff /*
4 1.1 joff * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1 joff * All rights reserved.
6 1.1 joff *
7 1.1 joff * This code is derived from software contributed to The NetBSD Foundation
8 1.1 joff * by Jesse Off
9 1.1 joff *
10 1.1 joff * This code is derived from software contributed to The NetBSD Foundation
11 1.1 joff * by Ichiro FUKUHARA and Naoto Shimazaki.
12 1.1 joff *
13 1.1 joff * Redistribution and use in source and binary forms, with or without
14 1.1 joff * modification, are permitted provided that the following conditions
15 1.1 joff * are met:
16 1.1 joff * 1. Redistributions of source code must retain the above copyright
17 1.1 joff * notice, this list of conditions and the following disclaimer.
18 1.1 joff * 2. Redistributions in binary form must reproduce the above copyright
19 1.1 joff * notice, this list of conditions and the following disclaimer in the
20 1.1 joff * documentation and/or other materials provided with the distribution.
21 1.1 joff * 3. All advertising materials mentioning features or use of this software
22 1.1 joff * must display the following acknowledgement:
23 1.1 joff * This product includes software developed by the NetBSD
24 1.1 joff * Foundation, Inc. and its contributors.
25 1.1 joff * 4. Neither the name of The NetBSD Foundation nor the names of its
26 1.1 joff * contributors may be used to endorse or promote products derived
27 1.1 joff * from this software without specific prior written permission.
28 1.1 joff *
29 1.1 joff * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30 1.1 joff * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 1.1 joff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 1.1 joff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33 1.1 joff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 1.1 joff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 1.1 joff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 1.1 joff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 1.1 joff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 1.1 joff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 1.1 joff * POSSIBILITY OF SUCH DAMAGE.
40 1.1 joff */
41 1.1 joff
42 1.1 joff #include <sys/cdefs.h>
43 1.4 joff __KERNEL_RCSID(0, "$NetBSD: ep93xx_intr.c,v 1.4 2005/08/14 03:10:16 joff Exp $");
44 1.1 joff
45 1.1 joff /*
46 1.1 joff * Interrupt support for the Cirrus Logic EP93XX
47 1.1 joff */
48 1.1 joff
49 1.1 joff #include <sys/param.h>
50 1.1 joff #include <sys/systm.h>
51 1.1 joff #include <sys/malloc.h>
52 1.1 joff #include <sys/termios.h>
53 1.1 joff
54 1.1 joff #include <uvm/uvm_extern.h>
55 1.1 joff
56 1.1 joff #include <machine/bus.h>
57 1.1 joff #include <machine/intr.h>
58 1.1 joff
59 1.1 joff #include <arm/cpufunc.h>
60 1.1 joff
61 1.1 joff #include <arm/ep93xx/ep93xxreg.h>
62 1.1 joff #include <arm/ep93xx/ep93xxvar.h>
63 1.1 joff
64 1.1 joff /* Interrupt handler queues. */
65 1.1 joff struct intrq intrq[NIRQ];
66 1.1 joff
67 1.1 joff /* Interrupts to mask at each level. */
68 1.1 joff static u_int32_t vic1_imask[NIPL];
69 1.1 joff static u_int32_t vic2_imask[NIPL];
70 1.1 joff
71 1.1 joff /* Current interrupt priority level. */
72 1.1 joff __volatile int current_spl_level;
73 1.1 joff __volatile int hardware_spl_level;
74 1.1 joff
75 1.1 joff /* Software copy of the IRQs we have enabled. */
76 1.1 joff __volatile u_int32_t vic1_intr_enabled;
77 1.1 joff __volatile u_int32_t vic2_intr_enabled;
78 1.1 joff
79 1.1 joff /* Interrupts pending. */
80 1.1 joff static __volatile int ipending;
81 1.1 joff
82 1.1 joff /*
83 1.1 joff * Map a software interrupt queue index (to the unused bits in the
84 1.1 joff * VIC1 register -- XXX will need to revisit this if those bits are
85 1.1 joff * ever used in future steppings).
86 1.1 joff */
87 1.1 joff static const u_int32_t si_to_irqbit[SI_NQUEUES] = {
88 1.1 joff EP93XX_INTR_bit30, /* SI_SOFT */
89 1.1 joff EP93XX_INTR_bit29, /* SI_SOFTCLOCK */
90 1.1 joff EP93XX_INTR_bit28, /* SI_SOFTNET */
91 1.1 joff EP93XX_INTR_bit27, /* SI_SOFTSERIAL */
92 1.1 joff };
93 1.1 joff
94 1.1 joff #define INT_SWMASK \
95 1.1 joff ((1U << EP93XX_INTR_bit30) | (1U << EP93XX_INTR_bit29) | \
96 1.1 joff (1U << EP93XX_INTR_bit28) | (1U << EP93XX_INTR_bit27))
97 1.1 joff
98 1.1 joff #define SI_TO_IRQBIT(si) (1U << si_to_irqbit[(si)])
99 1.1 joff
100 1.1 joff /*
101 1.1 joff * Map a software interrupt queue to an interrupt priority level.
102 1.1 joff */
103 1.1 joff static const int si_to_ipl[SI_NQUEUES] = {
104 1.1 joff IPL_SOFT, /* SI_SOFT */
105 1.1 joff IPL_SOFTCLOCK, /* SI_SOFTCLOCK */
106 1.1 joff IPL_SOFTNET, /* SI_SOFTNET */
107 1.1 joff IPL_SOFTSERIAL, /* SI_SOFTSERIAL */
108 1.1 joff };
109 1.1 joff
110 1.1 joff void ep93xx_intr_dispatch(struct irqframe *frame);
111 1.1 joff
112 1.1 joff #define VIC1REG(reg) *((volatile u_int32_t*) (EP93XX_AHB_VBASE + \
113 1.1 joff EP93XX_AHB_VIC1 + (reg)))
114 1.1 joff #define VIC2REG(reg) *((volatile u_int32_t*) (EP93XX_AHB_VBASE + \
115 1.1 joff EP93XX_AHB_VIC2 + (reg)))
116 1.1 joff
117 1.1 joff static void
118 1.1 joff ep93xx_set_intrmask(u_int32_t vic1_irqs, u_int32_t vic2_irqs)
119 1.1 joff {
120 1.1 joff VIC1REG(EP93XX_VIC_IntEnClear) = vic1_irqs;
121 1.1 joff VIC1REG(EP93XX_VIC_IntEnable) = vic1_intr_enabled & ~vic1_irqs;
122 1.1 joff VIC2REG(EP93XX_VIC_IntEnClear) = vic2_irqs;
123 1.1 joff VIC2REG(EP93XX_VIC_IntEnable) = vic2_intr_enabled & ~vic2_irqs;
124 1.1 joff }
125 1.1 joff
126 1.1 joff static void
127 1.1 joff ep93xx_enable_irq(int irq)
128 1.1 joff {
129 1.1 joff if (irq < VIC_NIRQ) {
130 1.1 joff vic1_intr_enabled |= (1U << irq);
131 1.1 joff VIC1REG(EP93XX_VIC_IntEnable) = (1U << irq);
132 1.1 joff } else {
133 1.1 joff vic2_intr_enabled |= (1U << (irq - VIC_NIRQ));
134 1.1 joff VIC2REG(EP93XX_VIC_IntEnable) = (1U << (irq - VIC_NIRQ));
135 1.1 joff }
136 1.1 joff }
137 1.1 joff
138 1.1 joff static __inline void
139 1.1 joff ep93xx_disable_irq(int irq)
140 1.1 joff {
141 1.1 joff if (irq < VIC_NIRQ) {
142 1.1 joff vic1_intr_enabled &= ~(1U << irq);
143 1.1 joff VIC1REG(EP93XX_VIC_IntEnClear) = (1U << irq);
144 1.1 joff } else {
145 1.1 joff vic2_intr_enabled &= ~(1U << (irq - VIC_NIRQ));
146 1.1 joff VIC2REG(EP93XX_VIC_IntEnClear) = (1U << (irq - VIC_NIRQ));
147 1.1 joff }
148 1.1 joff }
149 1.1 joff
150 1.1 joff /*
151 1.1 joff * NOTE: This routine must be called with interrupts disabled in the CPSR.
152 1.1 joff */
153 1.1 joff static void
154 1.1 joff ep93xx_intr_calculate_masks(void)
155 1.1 joff {
156 1.1 joff struct intrq *iq;
157 1.1 joff struct intrhand *ih;
158 1.1 joff int irq, ipl;
159 1.1 joff
160 1.1 joff /* First, figure out which IPLs each IRQ has. */
161 1.1 joff for (irq = 0; irq < NIRQ; irq++) {
162 1.1 joff int levels = 0;
163 1.1 joff iq = &intrq[irq];
164 1.1 joff ep93xx_disable_irq(irq);
165 1.1 joff for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
166 1.1 joff ih = TAILQ_NEXT(ih, ih_list))
167 1.1 joff levels |= (1U << ih->ih_ipl);
168 1.1 joff iq->iq_levels = levels;
169 1.1 joff }
170 1.1 joff
171 1.1 joff /* Next, figure out which IRQs are used by each IPL. */
172 1.1 joff for (ipl = 0; ipl < NIPL; ipl++) {
173 1.1 joff int vic1_irqs = 0;
174 1.1 joff int vic2_irqs = 0;
175 1.1 joff for (irq = 0; irq < VIC_NIRQ; irq++) {
176 1.1 joff if (intrq[irq].iq_levels & (1U << ipl))
177 1.1 joff vic1_irqs |= (1U << irq);
178 1.1 joff }
179 1.1 joff vic1_imask[ipl] = vic1_irqs;
180 1.1 joff for (irq = 0; irq < VIC_NIRQ; irq++) {
181 1.1 joff if (intrq[irq + VIC_NIRQ].iq_levels & (1U << ipl))
182 1.1 joff vic2_irqs |= (1U << irq);
183 1.1 joff }
184 1.1 joff vic2_imask[ipl] = vic2_irqs;
185 1.1 joff }
186 1.1 joff
187 1.1 joff vic1_imask[IPL_NONE] = 0;
188 1.1 joff vic2_imask[IPL_NONE] = 0;
189 1.1 joff
190 1.1 joff /*
191 1.1 joff * Initialize the soft interrupt masks to block themselves.
192 1.1 joff */
193 1.1 joff vic1_imask[IPL_SOFT] = SI_TO_IRQBIT(SI_SOFT);
194 1.1 joff vic1_imask[IPL_SOFTCLOCK] = SI_TO_IRQBIT(SI_SOFTCLOCK);
195 1.1 joff vic1_imask[IPL_SOFTNET] = SI_TO_IRQBIT(SI_SOFTNET);
196 1.1 joff vic1_imask[IPL_SOFTSERIAL] = SI_TO_IRQBIT(SI_SOFTSERIAL);
197 1.1 joff
198 1.1 joff /*
199 1.1 joff * splsoftclock() is the only interface that users of the
200 1.1 joff * generic software interrupt facility have to block their
201 1.1 joff * soft intrs, so splsoftclock() must also block IPL_SOFT.
202 1.1 joff */
203 1.1 joff vic1_imask[IPL_SOFTCLOCK] |= vic1_imask[IPL_SOFT];
204 1.1 joff vic2_imask[IPL_SOFTCLOCK] |= vic2_imask[IPL_SOFT];
205 1.1 joff
206 1.1 joff /*
207 1.1 joff * splsoftnet() must also block splsoftclock(), since we don't
208 1.1 joff * want timer-driven network events to occur while we're
209 1.1 joff * processing incoming packets.
210 1.1 joff */
211 1.1 joff vic1_imask[IPL_SOFTNET] |= vic1_imask[IPL_SOFTCLOCK];
212 1.1 joff vic2_imask[IPL_SOFTNET] |= vic2_imask[IPL_SOFTCLOCK];
213 1.1 joff
214 1.1 joff /*
215 1.1 joff * Enforce a heirarchy that gives "slow" device (or devices with
216 1.1 joff * limited input buffer space/"real-time" requirements) a better
217 1.1 joff * chance at not dropping data.
218 1.1 joff */
219 1.1 joff vic1_imask[IPL_BIO] |= vic1_imask[IPL_SOFTNET];
220 1.1 joff vic2_imask[IPL_BIO] |= vic2_imask[IPL_SOFTNET];
221 1.1 joff vic1_imask[IPL_NET] |= vic1_imask[IPL_BIO];
222 1.1 joff vic2_imask[IPL_NET] |= vic2_imask[IPL_BIO];
223 1.1 joff vic1_imask[IPL_SOFTSERIAL] |= vic1_imask[IPL_NET];
224 1.1 joff vic2_imask[IPL_SOFTSERIAL] |= vic2_imask[IPL_NET];
225 1.1 joff vic1_imask[IPL_TTY] |= vic1_imask[IPL_SOFTSERIAL];
226 1.1 joff vic2_imask[IPL_TTY] |= vic2_imask[IPL_SOFTSERIAL];
227 1.1 joff
228 1.1 joff /*
229 1.1 joff * splvm() blocks all interrupts that use the kernel memory
230 1.1 joff * allocation facilities.
231 1.1 joff */
232 1.1 joff vic1_imask[IPL_VM] |= vic1_imask[IPL_TTY];
233 1.1 joff vic2_imask[IPL_VM] |= vic2_imask[IPL_TTY];
234 1.1 joff
235 1.1 joff /*
236 1.1 joff * Audio devices are not allowed to perform memory allocation
237 1.1 joff * in their interrupt routines, and they have fairly "real-time"
238 1.1 joff * requirements, so give them a high interrupt priority.
239 1.1 joff */
240 1.1 joff vic1_imask[IPL_AUDIO] |= vic1_imask[IPL_VM];
241 1.1 joff vic2_imask[IPL_AUDIO] |= vic2_imask[IPL_VM];
242 1.1 joff
243 1.1 joff /*
244 1.1 joff * splclock() must block anything that uses the scheduler.
245 1.1 joff */
246 1.1 joff vic1_imask[IPL_CLOCK] |= vic1_imask[IPL_AUDIO];
247 1.1 joff vic2_imask[IPL_CLOCK] |= vic2_imask[IPL_AUDIO];
248 1.1 joff
249 1.1 joff /*
250 1.1 joff * No separate statclock on the EP93xx.
251 1.1 joff */
252 1.1 joff vic1_imask[IPL_STATCLOCK] |= vic1_imask[IPL_CLOCK];
253 1.1 joff vic2_imask[IPL_STATCLOCK] |= vic2_imask[IPL_CLOCK];
254 1.1 joff
255 1.1 joff /*
256 1.1 joff * serial uarts have small buffers that need low-latency servicing
257 1.1 joff */
258 1.1 joff vic1_imask[IPL_SERIAL] |= vic1_imask[IPL_STATCLOCK];
259 1.1 joff vic2_imask[IPL_SERIAL] |= vic2_imask[IPL_STATCLOCK];
260 1.1 joff
261 1.1 joff /*
262 1.1 joff * splhigh() must block "everything".
263 1.1 joff */
264 1.1 joff vic1_imask[IPL_HIGH] |= vic1_imask[IPL_SERIAL];
265 1.1 joff vic2_imask[IPL_HIGH] |= vic2_imask[IPL_SERIAL];
266 1.1 joff
267 1.1 joff /*
268 1.1 joff * Now compute which IRQs must be blocked when servicing any
269 1.1 joff * given IRQ.
270 1.1 joff */
271 1.1 joff for (irq = 0; irq < NIRQ; irq++) {
272 1.1 joff int vic1_irqs;
273 1.1 joff int vic2_irqs;
274 1.1 joff
275 1.1 joff if (irq < VIC_NIRQ) {
276 1.1 joff vic1_irqs = (1U << irq);
277 1.1 joff vic2_irqs = 0;
278 1.1 joff } else {
279 1.1 joff vic1_irqs = 0;
280 1.1 joff vic2_irqs = (1U << (irq - VIC_NIRQ));
281 1.1 joff }
282 1.1 joff iq = &intrq[irq];
283 1.1 joff if (TAILQ_FIRST(&iq->iq_list) != NULL)
284 1.1 joff ep93xx_enable_irq(irq);
285 1.1 joff for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
286 1.1 joff ih = TAILQ_NEXT(ih, ih_list)) {
287 1.1 joff vic1_irqs |= vic1_imask[ih->ih_ipl];
288 1.1 joff vic2_irqs |= vic2_imask[ih->ih_ipl];
289 1.1 joff }
290 1.1 joff iq->iq_vic1_mask = vic1_irqs;
291 1.1 joff iq->iq_vic2_mask = vic2_irqs;
292 1.1 joff }
293 1.1 joff }
294 1.1 joff
295 1.1 joff static void
296 1.1 joff ep93xx_do_pending(void)
297 1.1 joff {
298 1.1 joff static __cpu_simple_lock_t processing = __SIMPLELOCK_UNLOCKED;
299 1.1 joff int new;
300 1.2 joff u_int oldirqstate, oldirqstate2;
301 1.1 joff
302 1.1 joff if (__cpu_simple_lock_try(&processing) == 0)
303 1.1 joff return;
304 1.1 joff
305 1.1 joff new = current_spl_level;
306 1.1 joff
307 1.1 joff oldirqstate = disable_interrupts(I32_bit);
308 1.1 joff
309 1.1 joff #define DO_SOFTINT(si) \
310 1.1 joff if ((ipending & ~vic1_imask[new]) & SI_TO_IRQBIT(si)) { \
311 1.1 joff ipending &= ~SI_TO_IRQBIT(si); \
312 1.1 joff current_spl_level = si_to_ipl[(si)]; \
313 1.2 joff oldirqstate2 = enable_interrupts(I32_bit); \
314 1.1 joff softintr_dispatch(si); \
315 1.2 joff restore_interrupts(oldirqstate2); \
316 1.1 joff current_spl_level = new; \
317 1.1 joff }
318 1.1 joff
319 1.1 joff DO_SOFTINT(SI_SOFTSERIAL);
320 1.1 joff DO_SOFTINT(SI_SOFTNET);
321 1.1 joff DO_SOFTINT(SI_SOFTCLOCK);
322 1.1 joff DO_SOFTINT(SI_SOFT);
323 1.1 joff
324 1.1 joff __cpu_simple_unlock(&processing);
325 1.1 joff
326 1.1 joff restore_interrupts(oldirqstate);
327 1.1 joff }
328 1.1 joff
329 1.1 joff __inline void
330 1.1 joff splx(int new)
331 1.1 joff {
332 1.1 joff int old;
333 1.1 joff u_int oldirqstate;
334 1.1 joff
335 1.1 joff oldirqstate = disable_interrupts(I32_bit);
336 1.1 joff old = current_spl_level;
337 1.1 joff current_spl_level = new;
338 1.1 joff if (new != hardware_spl_level) {
339 1.1 joff hardware_spl_level = new;
340 1.1 joff ep93xx_set_intrmask(vic1_imask[new], vic2_imask[new]);
341 1.1 joff }
342 1.1 joff restore_interrupts(oldirqstate);
343 1.1 joff
344 1.1 joff /* If there are software interrupts to process, do it. */
345 1.1 joff if ((ipending & INT_SWMASK) & ~vic1_imask[new])
346 1.1 joff ep93xx_do_pending();
347 1.1 joff }
348 1.1 joff
349 1.1 joff int
350 1.1 joff _splraise(int ipl)
351 1.1 joff {
352 1.1 joff int old;
353 1.1 joff u_int oldirqstate;
354 1.1 joff
355 1.1 joff oldirqstate = disable_interrupts(I32_bit);
356 1.1 joff old = current_spl_level;
357 1.1 joff current_spl_level = ipl;
358 1.1 joff restore_interrupts(oldirqstate);
359 1.1 joff return (old);
360 1.1 joff }
361 1.1 joff
362 1.1 joff int
363 1.1 joff _spllower(int ipl)
364 1.1 joff {
365 1.1 joff int old = current_spl_level;
366 1.1 joff
367 1.1 joff if (old <= ipl)
368 1.1 joff return (old);
369 1.1 joff splx(ipl);
370 1.1 joff return (old);
371 1.1 joff }
372 1.1 joff
373 1.1 joff void
374 1.1 joff _setsoftintr(int si)
375 1.1 joff {
376 1.1 joff u_int oldirqstate;
377 1.1 joff
378 1.1 joff oldirqstate = disable_interrupts(I32_bit);
379 1.1 joff ipending |= SI_TO_IRQBIT(si);
380 1.1 joff restore_interrupts(oldirqstate);
381 1.1 joff
382 1.1 joff /* Process unmasked pending soft interrupts. */
383 1.1 joff if ((ipending & INT_SWMASK) & ~vic1_imask[current_spl_level])
384 1.1 joff ep93xx_do_pending();
385 1.1 joff }
386 1.1 joff
387 1.1 joff /*
388 1.1 joff * ep93xx_intr_init:
389 1.1 joff *
390 1.1 joff * Initialize the rest of the interrupt subsystem, making it
391 1.1 joff * ready to handle interrupts from devices.
392 1.1 joff */
393 1.1 joff void
394 1.1 joff ep93xx_intr_init(void)
395 1.1 joff {
396 1.1 joff struct intrq *iq;
397 1.1 joff int i;
398 1.1 joff
399 1.1 joff vic1_intr_enabled = 0;
400 1.1 joff vic2_intr_enabled = 0;
401 1.1 joff
402 1.1 joff for (i = 0; i < NIRQ; i++) {
403 1.1 joff iq = &intrq[i];
404 1.1 joff TAILQ_INIT(&iq->iq_list);
405 1.1 joff
406 1.1 joff sprintf(iq->iq_name, "irq %d", i);
407 1.1 joff evcnt_attach_dynamic(&iq->iq_ev, EVCNT_TYPE_INTR,
408 1.1 joff NULL, (i < VIC_NIRQ ? "vic1" : "vic2"),
409 1.1 joff iq->iq_name);
410 1.1 joff }
411 1.1 joff current_intr_depth = 0;
412 1.1 joff current_spl_level = 0;
413 1.1 joff hardware_spl_level = 0;
414 1.1 joff
415 1.1 joff /* All interrupts should use IRQ not FIQ */
416 1.1 joff VIC1REG(EP93XX_VIC_IntSelect) = 0;
417 1.1 joff VIC2REG(EP93XX_VIC_IntSelect) = 0;
418 1.1 joff
419 1.1 joff ep93xx_intr_calculate_masks();
420 1.1 joff
421 1.1 joff /* Enable IRQs (don't yet use FIQs). */
422 1.1 joff enable_interrupts(I32_bit);
423 1.1 joff }
424 1.1 joff
425 1.1 joff void *
426 1.1 joff ep93xx_intr_establish(int irq, int ipl, int (*ih_func)(void *), void *arg)
427 1.1 joff {
428 1.1 joff struct intrq* iq;
429 1.1 joff struct intrhand* ih;
430 1.1 joff u_int oldirqstate;
431 1.1 joff
432 1.1 joff if (irq < 0 || irq > NIRQ)
433 1.1 joff panic("ep93xx_intr_establish: IRQ %d out of range", irq);
434 1.1 joff if (ipl < 0 || ipl > NIPL)
435 1.1 joff panic("ep93xx_intr_establish: IPL %d out of range", ipl);
436 1.1 joff
437 1.1 joff ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
438 1.1 joff if (ih == NULL)
439 1.1 joff return (NULL);
440 1.1 joff
441 1.1 joff ih->ih_func = ih_func;
442 1.1 joff ih->ih_arg = arg;
443 1.1 joff ih->ih_irq = irq;
444 1.1 joff ih->ih_ipl = ipl;
445 1.1 joff
446 1.1 joff iq = &intrq[irq];
447 1.1 joff
448 1.1 joff oldirqstate = disable_interrupts(I32_bit);
449 1.1 joff TAILQ_INSERT_TAIL(&iq->iq_list, ih, ih_list);
450 1.1 joff ep93xx_intr_calculate_masks();
451 1.1 joff restore_interrupts(oldirqstate);
452 1.1 joff
453 1.1 joff return (ih);
454 1.1 joff }
455 1.1 joff
456 1.1 joff void
457 1.1 joff ep93xx_intr_disestablish(void *cookie)
458 1.1 joff {
459 1.1 joff struct intrhand* ih = cookie;
460 1.1 joff struct intrq* iq = &intrq[ih->ih_irq];
461 1.1 joff u_int oldirqstate;
462 1.1 joff
463 1.1 joff oldirqstate = disable_interrupts(I32_bit);
464 1.1 joff TAILQ_REMOVE(&iq->iq_list, ih, ih_list);
465 1.1 joff ep93xx_intr_calculate_masks();
466 1.1 joff restore_interrupts(oldirqstate);
467 1.1 joff }
468 1.1 joff
469 1.1 joff void
470 1.4 joff ep93xx_intr_dispatch(struct irqframe *frame)
471 1.1 joff {
472 1.1 joff struct intrq* iq;
473 1.1 joff struct intrhand* ih;
474 1.1 joff u_int oldirqstate;
475 1.1 joff int pcpl;
476 1.1 joff u_int32_t vic1_hwpend;
477 1.1 joff u_int32_t vic2_hwpend;
478 1.1 joff int irq;
479 1.1 joff
480 1.1 joff pcpl = current_spl_level;
481 1.1 joff
482 1.1 joff vic1_hwpend = VIC1REG(EP93XX_VIC_IRQStatus);
483 1.1 joff vic2_hwpend = VIC2REG(EP93XX_VIC_IRQStatus);
484 1.1 joff
485 1.1 joff hardware_spl_level = pcpl;
486 1.1 joff ep93xx_set_intrmask(vic1_imask[pcpl] | vic1_hwpend,
487 1.1 joff vic2_imask[pcpl] | vic2_hwpend);
488 1.1 joff
489 1.1 joff vic1_hwpend &= ~vic1_imask[pcpl];
490 1.1 joff vic2_hwpend &= ~vic2_imask[pcpl];
491 1.1 joff
492 1.3 joff if (vic1_hwpend) {
493 1.1 joff irq = ffs(vic1_hwpend) - 1;
494 1.1 joff
495 1.1 joff iq = &intrq[irq];
496 1.1 joff iq->iq_ev.ev_count++;
497 1.1 joff uvmexp.intrs++;
498 1.1 joff for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
499 1.1 joff ih = TAILQ_NEXT(ih, ih_list)) {
500 1.3 joff current_spl_level = ih->ih_ipl;
501 1.1 joff oldirqstate = enable_interrupts(I32_bit);
502 1.1 joff (void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
503 1.1 joff restore_interrupts(oldirqstate);
504 1.1 joff }
505 1.3 joff } else if (vic2_hwpend) {
506 1.1 joff irq = ffs(vic2_hwpend) - 1;
507 1.1 joff
508 1.1 joff iq = &intrq[irq + VIC_NIRQ];
509 1.1 joff iq->iq_ev.ev_count++;
510 1.1 joff uvmexp.intrs++;
511 1.1 joff for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
512 1.1 joff ih = TAILQ_NEXT(ih, ih_list)) {
513 1.3 joff current_spl_level = ih->ih_ipl;
514 1.1 joff oldirqstate = enable_interrupts(I32_bit);
515 1.1 joff (void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
516 1.1 joff restore_interrupts(oldirqstate);
517 1.1 joff }
518 1.1 joff }
519 1.1 joff
520 1.1 joff current_spl_level = pcpl;
521 1.1 joff hardware_spl_level = pcpl;
522 1.1 joff ep93xx_set_intrmask(vic1_imask[pcpl], vic2_imask[pcpl]);
523 1.1 joff
524 1.1 joff /* Check for pendings soft intrs. */
525 1.1 joff if ((ipending & INT_SWMASK) & ~vic1_imask[pcpl]) {
526 1.1 joff ep93xx_do_pending();
527 1.1 joff }
528 1.1 joff }
529