iq80310_intr.c revision 1.6.2.4 1 1.6.2.4 jdolecek /* $NetBSD: iq80310_intr.c,v 1.6.2.4 2002/03/16 15:57:27 jdolecek Exp $ */
2 1.6.2.2 thorpej
3 1.6.2.2 thorpej /*
4 1.6.2.3 jdolecek * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5 1.6.2.2 thorpej * All rights reserved.
6 1.6.2.2 thorpej *
7 1.6.2.2 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.6.2.2 thorpej *
9 1.6.2.2 thorpej * Redistribution and use in source and binary forms, with or without
10 1.6.2.2 thorpej * modification, are permitted provided that the following conditions
11 1.6.2.2 thorpej * are met:
12 1.6.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.6.2.2 thorpej * notice, this list of conditions and the following disclaimer.
14 1.6.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.6.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.6.2.2 thorpej * documentation and/or other materials provided with the distribution.
17 1.6.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.6.2.2 thorpej * must display the following acknowledgement:
19 1.6.2.2 thorpej * This product includes software developed for the NetBSD Project by
20 1.6.2.2 thorpej * Wasabi Systems, Inc.
21 1.6.2.2 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.6.2.2 thorpej * or promote products derived from this software without specific prior
23 1.6.2.2 thorpej * written permission.
24 1.6.2.2 thorpej *
25 1.6.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.6.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.6.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.6.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.6.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.6.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.6.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.6.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.6.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.6.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.6.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.6.2.2 thorpej */
37 1.6.2.2 thorpej
38 1.6.2.2 thorpej /*
39 1.6.2.2 thorpej * Interrupt support for the Intel IQ80310.
40 1.6.2.2 thorpej */
41 1.6.2.2 thorpej
42 1.6.2.2 thorpej #include <sys/param.h>
43 1.6.2.2 thorpej #include <sys/systm.h>
44 1.6.2.2 thorpej #include <sys/malloc.h>
45 1.6.2.2 thorpej
46 1.6.2.3 jdolecek #include <uvm/uvm_extern.h>
47 1.6.2.3 jdolecek
48 1.6.2.2 thorpej #include <machine/bus.h>
49 1.6.2.2 thorpej #include <machine/intr.h>
50 1.6.2.3 jdolecek
51 1.6.2.2 thorpej #include <arm/cpufunc.h>
52 1.6.2.2 thorpej
53 1.6.2.2 thorpej #include <arm/xscale/i80200reg.h>
54 1.6.2.3 jdolecek #include <arm/xscale/i80200var.h>
55 1.6.2.2 thorpej
56 1.6.2.2 thorpej #include <evbarm/iq80310/iq80310reg.h>
57 1.6.2.2 thorpej #include <evbarm/iq80310/iq80310var.h>
58 1.6.2.2 thorpej #include <evbarm/iq80310/obiovar.h>
59 1.6.2.2 thorpej
60 1.6.2.4 jdolecek #if defined(IOP310_TEAMASA_NPWR)
61 1.6.2.4 jdolecek /*
62 1.6.2.4 jdolecek * We have 5 interrupt source bits -- all in XINT3. All interrupts
63 1.6.2.4 jdolecek * can be masked in the CPLD.
64 1.6.2.4 jdolecek */
65 1.6.2.4 jdolecek #define IRQ_BITS 0x1f
66 1.6.2.4 jdolecek #define IRQ_BITS_ALWAYS_ON 0x00
67 1.6.2.4 jdolecek #else /* Default to stock IQ80310 */
68 1.6.2.2 thorpej /*
69 1.6.2.2 thorpej * We have 8 interrupt source bits -- 5 in the XINT3 register, and 3
70 1.6.2.3 jdolecek * in the XINT0 register (the upper 3). Note that the XINT0 IRQs
71 1.6.2.3 jdolecek * (SPCI INTA, INTB, and INTC) are always enabled, since they can not
72 1.6.2.3 jdolecek * be masked out in the CPLD (it provides only status, not masking,
73 1.6.2.3 jdolecek * for those interrupts).
74 1.6.2.2 thorpej */
75 1.6.2.3 jdolecek #define IRQ_BITS 0xff
76 1.6.2.3 jdolecek #define IRQ_BITS_ALWAYS_ON 0xe0
77 1.6.2.4 jdolecek #define IRQ_READ_XINT0 1 /* XXX only if board rev >= F */
78 1.6.2.4 jdolecek #endif /* list of IQ80310-based designs */
79 1.6.2.2 thorpej
80 1.6.2.3 jdolecek /* Interrupt handler queues. */
81 1.6.2.3 jdolecek struct intrq intrq[NIRQ];
82 1.6.2.2 thorpej
83 1.6.2.3 jdolecek /* Interrupts to mask at each level. */
84 1.6.2.3 jdolecek static int imask[NIPL];
85 1.6.2.2 thorpej
86 1.6.2.3 jdolecek /* Current interrupt priority level. */
87 1.6.2.3 jdolecek __volatile int current_spl_level;
88 1.6.2.2 thorpej
89 1.6.2.3 jdolecek /* Interrupts pending. */
90 1.6.2.3 jdolecek static __volatile int ipending;
91 1.6.2.2 thorpej
92 1.6.2.3 jdolecek /* Software copy of the IRQs we have enabled. */
93 1.6.2.3 jdolecek uint32_t intr_enabled;
94 1.6.2.2 thorpej
95 1.6.2.3 jdolecek /*
96 1.6.2.3 jdolecek * Map a software interrupt queue index (at the top of the word, and
97 1.6.2.3 jdolecek * highest priority softintr is encountered first in an ffs()).
98 1.6.2.3 jdolecek */
99 1.6.2.3 jdolecek #define SI_TO_IRQBIT(si) (1U << (31 - (si)))
100 1.6.2.2 thorpej
101 1.6.2.3 jdolecek /*
102 1.6.2.3 jdolecek * Map a software interrupt queue to an interrupt priority level.
103 1.6.2.3 jdolecek */
104 1.6.2.3 jdolecek static const int si_to_ipl[SI_NQUEUES] = {
105 1.6.2.3 jdolecek IPL_SOFT, /* SI_SOFT */
106 1.6.2.3 jdolecek IPL_SOFTCLOCK, /* SI_SOFTCLOCK */
107 1.6.2.3 jdolecek IPL_SOFTNET, /* SI_SOFTNET */
108 1.6.2.3 jdolecek IPL_SOFTSERIAL, /* SI_SOFTSERIAL */
109 1.6.2.3 jdolecek };
110 1.6.2.2 thorpej
111 1.6.2.3 jdolecek void iq80310_intr_dispatch(struct clockframe *frame);
112 1.6.2.2 thorpej
113 1.6.2.3 jdolecek static __inline uint32_t
114 1.6.2.2 thorpej iq80310_intstat_read(void)
115 1.6.2.2 thorpej {
116 1.6.2.2 thorpej uint32_t intstat;
117 1.6.2.2 thorpej
118 1.6.2.2 thorpej intstat = CPLD_READ(IQ80310_XINT3_STATUS) & 0x1f;
119 1.6.2.4 jdolecek #if defined(IRQ_READ_XINT0)
120 1.6.2.4 jdolecek if (IRQ_READ_XINT0)
121 1.6.2.2 thorpej intstat |= (CPLD_READ(IQ80310_XINT0_STATUS) & 0x7) << 5;
122 1.6.2.4 jdolecek #endif
123 1.6.2.2 thorpej
124 1.6.2.3 jdolecek /* XXX Why do we have to mask off? */
125 1.6.2.3 jdolecek return (intstat & intr_enabled);
126 1.6.2.2 thorpej }
127 1.6.2.2 thorpej
128 1.6.2.3 jdolecek static __inline void
129 1.6.2.3 jdolecek iq80310_set_intrmask(void)
130 1.6.2.3 jdolecek {
131 1.6.2.3 jdolecek uint32_t disabled;
132 1.6.2.3 jdolecek
133 1.6.2.3 jdolecek intr_enabled |= IRQ_BITS_ALWAYS_ON;
134 1.6.2.3 jdolecek
135 1.6.2.3 jdolecek /* The XINT_MASK register sets a bit to *disable*. */
136 1.6.2.3 jdolecek disabled = (~intr_enabled) & IRQ_BITS;
137 1.6.2.3 jdolecek
138 1.6.2.3 jdolecek CPLD_WRITE(IQ80310_XINT_MASK, disabled & 0x1f);
139 1.6.2.3 jdolecek }
140 1.6.2.3 jdolecek
141 1.6.2.3 jdolecek static __inline void
142 1.6.2.3 jdolecek iq80310_enable_irq(int irq)
143 1.6.2.3 jdolecek {
144 1.6.2.3 jdolecek
145 1.6.2.3 jdolecek intr_enabled |= (1U << irq);
146 1.6.2.3 jdolecek iq80310_set_intrmask();
147 1.6.2.3 jdolecek }
148 1.6.2.3 jdolecek
149 1.6.2.3 jdolecek static __inline void
150 1.6.2.3 jdolecek iq80310_disable_irq(int irq)
151 1.6.2.3 jdolecek {
152 1.6.2.3 jdolecek
153 1.6.2.3 jdolecek intr_enabled &= ~(1U << irq);
154 1.6.2.3 jdolecek iq80310_set_intrmask();
155 1.6.2.3 jdolecek }
156 1.6.2.3 jdolecek
157 1.6.2.3 jdolecek /*
158 1.6.2.3 jdolecek * NOTE: This routine must be called with interrupts disabled in the CPSR.
159 1.6.2.3 jdolecek */
160 1.6.2.3 jdolecek static void
161 1.6.2.3 jdolecek iq80310_intr_calculate_masks(void)
162 1.6.2.2 thorpej {
163 1.6.2.3 jdolecek struct intrq *iq;
164 1.6.2.3 jdolecek struct intrhand *ih;
165 1.6.2.3 jdolecek int irq, ipl;
166 1.6.2.3 jdolecek
167 1.6.2.3 jdolecek /* First, figure out which IPLs each IRQ has. */
168 1.6.2.3 jdolecek for (irq = 0; irq < NIRQ; irq++) {
169 1.6.2.3 jdolecek int levels = 0;
170 1.6.2.3 jdolecek iq = &intrq[irq];
171 1.6.2.3 jdolecek iq80310_disable_irq(irq);
172 1.6.2.3 jdolecek for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
173 1.6.2.3 jdolecek ih = TAILQ_NEXT(ih, ih_list))
174 1.6.2.3 jdolecek levels |= (1U << ih->ih_ipl);
175 1.6.2.3 jdolecek iq->iq_levels = levels;
176 1.6.2.3 jdolecek }
177 1.6.2.2 thorpej
178 1.6.2.3 jdolecek /* Next, figure out which IRQs are used by each IPL. */
179 1.6.2.3 jdolecek for (ipl = 0; ipl < NIPL; ipl++) {
180 1.6.2.3 jdolecek int irqs = 0;
181 1.6.2.3 jdolecek for (irq = 0; irq < NIRQ; irq++) {
182 1.6.2.3 jdolecek if (intrq[irq].iq_levels & (1U << ipl))
183 1.6.2.3 jdolecek irqs |= (1U << irq);
184 1.6.2.3 jdolecek }
185 1.6.2.3 jdolecek imask[ipl] = irqs;
186 1.6.2.3 jdolecek }
187 1.6.2.3 jdolecek
188 1.6.2.3 jdolecek imask[IPL_NONE] = 0;
189 1.6.2.2 thorpej
190 1.6.2.2 thorpej /*
191 1.6.2.3 jdolecek * Initialize the soft interrupt masks to block themselves.
192 1.6.2.2 thorpej */
193 1.6.2.3 jdolecek imask[IPL_SOFT] = SI_TO_IRQBIT(SI_SOFT);
194 1.6.2.3 jdolecek imask[IPL_SOFTCLOCK] = SI_TO_IRQBIT(SI_SOFTCLOCK);
195 1.6.2.3 jdolecek imask[IPL_SOFTNET] = SI_TO_IRQBIT(SI_SOFTNET);
196 1.6.2.3 jdolecek imask[IPL_SOFTSERIAL] = SI_TO_IRQBIT(SI_SOFTSERIAL);
197 1.6.2.2 thorpej
198 1.6.2.2 thorpej /*
199 1.6.2.3 jdolecek * splsoftclock() is the only interface that users of the
200 1.6.2.3 jdolecek * generic software interrupt facility have to block their
201 1.6.2.3 jdolecek * soft intrs, so splsoftclock() must also block IPL_SOFT.
202 1.6.2.2 thorpej */
203 1.6.2.3 jdolecek imask[IPL_SOFTCLOCK] |= imask[IPL_SOFT];
204 1.6.2.2 thorpej
205 1.6.2.3 jdolecek /*
206 1.6.2.3 jdolecek * splsoftnet() must also block splsoftclock(), since we don't
207 1.6.2.3 jdolecek * want timer-driven network events to occur while we're
208 1.6.2.3 jdolecek * processing incoming packets.
209 1.6.2.3 jdolecek */
210 1.6.2.3 jdolecek imask[IPL_SOFTNET] |= imask[IPL_SOFTCLOCK];
211 1.6.2.3 jdolecek
212 1.6.2.3 jdolecek /*
213 1.6.2.3 jdolecek * Enforce a heirarchy that gives "slow" device (or devices with
214 1.6.2.3 jdolecek * limited input buffer space/"real-time" requirements) a better
215 1.6.2.3 jdolecek * chance at not dropping data.
216 1.6.2.3 jdolecek */
217 1.6.2.3 jdolecek imask[IPL_BIO] |= imask[IPL_SOFTNET];
218 1.6.2.3 jdolecek imask[IPL_NET] |= imask[IPL_BIO];
219 1.6.2.3 jdolecek imask[IPL_SOFTSERIAL] |= imask[IPL_NET];
220 1.6.2.3 jdolecek imask[IPL_TTY] |= imask[IPL_SOFTSERIAL];
221 1.6.2.3 jdolecek
222 1.6.2.3 jdolecek /*
223 1.6.2.3 jdolecek * splvm() blocks all interrupts that use the kernel memory
224 1.6.2.3 jdolecek * allocation facilities.
225 1.6.2.3 jdolecek */
226 1.6.2.3 jdolecek imask[IPL_IMP] |= imask[IPL_TTY];
227 1.6.2.3 jdolecek
228 1.6.2.3 jdolecek /*
229 1.6.2.3 jdolecek * Audio devices are not allowed to perform memory allocation
230 1.6.2.3 jdolecek * in their interrupt routines, and they have fairly "real-time"
231 1.6.2.3 jdolecek * requirements, so give them a high interrupt priority.
232 1.6.2.3 jdolecek */
233 1.6.2.3 jdolecek imask[IPL_AUDIO] |= imask[IPL_IMP];
234 1.6.2.3 jdolecek
235 1.6.2.3 jdolecek /*
236 1.6.2.3 jdolecek * splclock() must block anything that uses the scheduler.
237 1.6.2.3 jdolecek */
238 1.6.2.3 jdolecek imask[IPL_CLOCK] |= imask[IPL_AUDIO];
239 1.6.2.3 jdolecek
240 1.6.2.3 jdolecek /*
241 1.6.2.3 jdolecek * No separate statclock on the IQ80310.
242 1.6.2.3 jdolecek */
243 1.6.2.3 jdolecek imask[IPL_STATCLOCK] |= imask[IPL_CLOCK];
244 1.6.2.3 jdolecek
245 1.6.2.3 jdolecek /*
246 1.6.2.3 jdolecek * splhigh() must block "everything".
247 1.6.2.3 jdolecek */
248 1.6.2.3 jdolecek imask[IPL_HIGH] |= imask[IPL_STATCLOCK];
249 1.6.2.3 jdolecek
250 1.6.2.3 jdolecek /*
251 1.6.2.3 jdolecek * XXX We need serial drivers to run at the absolute highest priority
252 1.6.2.3 jdolecek * in order to avoid overruns, so serial > high.
253 1.6.2.3 jdolecek */
254 1.6.2.3 jdolecek imask[IPL_SERIAL] |= imask[IPL_HIGH];
255 1.6.2.3 jdolecek
256 1.6.2.3 jdolecek /*
257 1.6.2.3 jdolecek * Now compute which IRQs must be blocked when servicing any
258 1.6.2.3 jdolecek * given IRQ.
259 1.6.2.3 jdolecek */
260 1.6.2.3 jdolecek for (irq = 0; irq < NIRQ; irq++) {
261 1.6.2.3 jdolecek int irqs = (1U << irq);
262 1.6.2.3 jdolecek iq = &intrq[irq];
263 1.6.2.3 jdolecek if (TAILQ_FIRST(&iq->iq_list) != NULL)
264 1.6.2.3 jdolecek iq80310_enable_irq(irq);
265 1.6.2.3 jdolecek for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
266 1.6.2.3 jdolecek ih = TAILQ_NEXT(ih, ih_list))
267 1.6.2.3 jdolecek irqs |= imask[ih->ih_ipl];
268 1.6.2.3 jdolecek iq->iq_mask = irqs;
269 1.6.2.3 jdolecek }
270 1.6.2.2 thorpej }
271 1.6.2.2 thorpej
272 1.6.2.3 jdolecek static void
273 1.6.2.3 jdolecek iq80310_do_pending(void)
274 1.6.2.2 thorpej {
275 1.6.2.3 jdolecek static __cpu_simple_lock_t processing = __SIMPLELOCK_UNLOCKED;
276 1.6.2.3 jdolecek int new, oldirqstate;
277 1.6.2.3 jdolecek
278 1.6.2.3 jdolecek if (__cpu_simple_lock_try(&processing) == 0)
279 1.6.2.3 jdolecek return;
280 1.6.2.3 jdolecek
281 1.6.2.3 jdolecek new = current_spl_level;
282 1.6.2.2 thorpej
283 1.6.2.2 thorpej oldirqstate = disable_interrupts(I32_bit);
284 1.6.2.3 jdolecek
285 1.6.2.3 jdolecek #define DO_SOFTINT(si) \
286 1.6.2.3 jdolecek if ((ipending & ~new) & SI_TO_IRQBIT(si)) { \
287 1.6.2.3 jdolecek ipending &= ~SI_TO_IRQBIT(si); \
288 1.6.2.3 jdolecek current_spl_level |= imask[si_to_ipl[(si)]]; \
289 1.6.2.3 jdolecek restore_interrupts(oldirqstate); \
290 1.6.2.3 jdolecek softintr_dispatch(si); \
291 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit); \
292 1.6.2.3 jdolecek current_spl_level = new; \
293 1.6.2.3 jdolecek }
294 1.6.2.3 jdolecek
295 1.6.2.3 jdolecek DO_SOFTINT(SI_SOFTSERIAL);
296 1.6.2.3 jdolecek DO_SOFTINT(SI_SOFTNET);
297 1.6.2.3 jdolecek DO_SOFTINT(SI_SOFTCLOCK);
298 1.6.2.3 jdolecek DO_SOFTINT(SI_SOFT);
299 1.6.2.3 jdolecek
300 1.6.2.3 jdolecek __cpu_simple_unlock(&processing);
301 1.6.2.3 jdolecek
302 1.6.2.2 thorpej restore_interrupts(oldirqstate);
303 1.6.2.2 thorpej }
304 1.6.2.2 thorpej
305 1.6.2.3 jdolecek int
306 1.6.2.3 jdolecek _splraise(int ipl)
307 1.6.2.3 jdolecek {
308 1.6.2.3 jdolecek int old, oldirqstate;
309 1.6.2.3 jdolecek
310 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit);
311 1.6.2.3 jdolecek old = current_spl_level;
312 1.6.2.3 jdolecek current_spl_level |= imask[ipl];
313 1.6.2.3 jdolecek
314 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
315 1.6.2.3 jdolecek
316 1.6.2.3 jdolecek return (old);
317 1.6.2.3 jdolecek }
318 1.6.2.3 jdolecek
319 1.6.2.3 jdolecek __inline void
320 1.6.2.3 jdolecek splx(int new)
321 1.6.2.2 thorpej {
322 1.6.2.3 jdolecek int old;
323 1.6.2.2 thorpej
324 1.6.2.3 jdolecek old = current_spl_level;
325 1.6.2.3 jdolecek current_spl_level = new;
326 1.6.2.3 jdolecek
327 1.6.2.3 jdolecek /*
328 1.6.2.3 jdolecek * If there are pending hardware interrupts (i.e. the
329 1.6.2.3 jdolecek * external interrupt is disabled in the ICU), and all
330 1.6.2.3 jdolecek * hardware interrupts are being unblocked, then re-enable
331 1.6.2.3 jdolecek * the external hardware interrupt.
332 1.6.2.3 jdolecek *
333 1.6.2.3 jdolecek * XXX We have to wait for ALL hardware interrupts to
334 1.6.2.3 jdolecek * XXX be unblocked, because we currently lose if we
335 1.6.2.3 jdolecek * XXX get nested interrupts, and I don't know why yet.
336 1.6.2.3 jdolecek */
337 1.6.2.3 jdolecek if ((new & IRQ_BITS) == 0 && (ipending & IRQ_BITS))
338 1.6.2.3 jdolecek i80200_intr_enable(INTCTL_IM);
339 1.6.2.3 jdolecek
340 1.6.2.3 jdolecek /* If there are software interrupts to process, do it. */
341 1.6.2.3 jdolecek if ((ipending & ~IRQ_BITS) & ~new)
342 1.6.2.3 jdolecek iq80310_do_pending();
343 1.6.2.3 jdolecek }
344 1.6.2.3 jdolecek
345 1.6.2.3 jdolecek int
346 1.6.2.3 jdolecek _spllower(int ipl)
347 1.6.2.3 jdolecek {
348 1.6.2.3 jdolecek int old = current_spl_level;
349 1.6.2.3 jdolecek
350 1.6.2.3 jdolecek splx(imask[ipl]);
351 1.6.2.3 jdolecek return (old);
352 1.6.2.2 thorpej }
353 1.6.2.2 thorpej
354 1.6.2.2 thorpej void
355 1.6.2.3 jdolecek _setsoftintr(int si)
356 1.6.2.2 thorpej {
357 1.6.2.3 jdolecek int oldirqstate;
358 1.6.2.3 jdolecek
359 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit);
360 1.6.2.3 jdolecek ipending |= SI_TO_IRQBIT(si);
361 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
362 1.6.2.2 thorpej
363 1.6.2.3 jdolecek /* Process unmasked pending soft interrupts. */
364 1.6.2.3 jdolecek if ((ipending & ~IRQ_BITS) & ~current_spl_level)
365 1.6.2.3 jdolecek iq80310_do_pending();
366 1.6.2.2 thorpej }
367 1.6.2.2 thorpej
368 1.6.2.2 thorpej void
369 1.6.2.3 jdolecek iq80310_intr_init(void)
370 1.6.2.2 thorpej {
371 1.6.2.3 jdolecek struct intrq *iq;
372 1.6.2.3 jdolecek int i;
373 1.6.2.3 jdolecek
374 1.6.2.3 jdolecek /*
375 1.6.2.3 jdolecek * The Secondary PCI interrupts INTA, INTB, and INTC
376 1.6.2.3 jdolecek * area always enabled, since they cannot be masked
377 1.6.2.3 jdolecek * in the CPLD.
378 1.6.2.3 jdolecek */
379 1.6.2.3 jdolecek intr_enabled |= IRQ_BITS_ALWAYS_ON;
380 1.6.2.2 thorpej
381 1.6.2.3 jdolecek for (i = 0; i < NIRQ; i++) {
382 1.6.2.3 jdolecek iq = &intrq[i];
383 1.6.2.3 jdolecek TAILQ_INIT(&iq->iq_list);
384 1.6.2.3 jdolecek
385 1.6.2.3 jdolecek sprintf(iq->iq_name, "irq %d", i);
386 1.6.2.3 jdolecek evcnt_attach_dynamic(&iq->iq_ev, EVCNT_TYPE_INTR,
387 1.6.2.3 jdolecek NULL, "iq80310", iq->iq_name);
388 1.6.2.3 jdolecek }
389 1.6.2.3 jdolecek
390 1.6.2.3 jdolecek iq80310_intr_calculate_masks();
391 1.6.2.3 jdolecek
392 1.6.2.3 jdolecek /* Enable external interrupts on the i80200. */
393 1.6.2.3 jdolecek i80200_extirq_dispatch = iq80310_intr_dispatch;
394 1.6.2.3 jdolecek i80200_intr_enable(INTCTL_IM);
395 1.6.2.3 jdolecek
396 1.6.2.3 jdolecek /* Enable IRQs (don't yet use FIQs). */
397 1.6.2.3 jdolecek enable_interrupts(I32_bit);
398 1.6.2.2 thorpej }
399 1.6.2.2 thorpej
400 1.6.2.2 thorpej void *
401 1.6.2.2 thorpej iq80310_intr_establish(int irq, int ipl, int (*func)(void *), void *arg)
402 1.6.2.2 thorpej {
403 1.6.2.3 jdolecek struct intrq *iq;
404 1.6.2.3 jdolecek struct intrhand *ih;
405 1.6.2.2 thorpej u_int oldirqstate;
406 1.6.2.3 jdolecek
407 1.6.2.3 jdolecek if (irq < 0 || irq > NIRQ)
408 1.6.2.3 jdolecek panic("iq80310_intr_establish: IRQ %d out of range", irq);
409 1.6.2.2 thorpej
410 1.6.2.2 thorpej ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
411 1.6.2.2 thorpej if (ih == NULL)
412 1.6.2.2 thorpej return (NULL);
413 1.6.2.2 thorpej
414 1.6.2.2 thorpej ih->ih_func = func;
415 1.6.2.2 thorpej ih->ih_arg = arg;
416 1.6.2.3 jdolecek ih->ih_ipl = ipl;
417 1.6.2.3 jdolecek ih->ih_irq = irq;
418 1.6.2.2 thorpej
419 1.6.2.3 jdolecek iq = &intrq[irq];
420 1.6.2.2 thorpej
421 1.6.2.3 jdolecek /* All IQ80310 interrupts are level-triggered. */
422 1.6.2.3 jdolecek iq->iq_ist = IST_LEVEL;
423 1.6.2.2 thorpej
424 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit);
425 1.6.2.2 thorpej
426 1.6.2.3 jdolecek TAILQ_INSERT_TAIL(&iq->iq_list, ih, ih_list);
427 1.6.2.2 thorpej
428 1.6.2.3 jdolecek iq80310_intr_calculate_masks();
429 1.6.2.2 thorpej
430 1.6.2.2 thorpej restore_interrupts(oldirqstate);
431 1.6.2.2 thorpej
432 1.6.2.2 thorpej return (ih);
433 1.6.2.2 thorpej }
434 1.6.2.2 thorpej
435 1.6.2.2 thorpej void
436 1.6.2.2 thorpej iq80310_intr_disestablish(void *cookie)
437 1.6.2.2 thorpej {
438 1.6.2.3 jdolecek struct intrhand *ih = cookie;
439 1.6.2.3 jdolecek struct intrq *iq = &intrq[ih->ih_irq];
440 1.6.2.3 jdolecek int oldirqstate;
441 1.6.2.3 jdolecek
442 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit);
443 1.6.2.3 jdolecek
444 1.6.2.3 jdolecek TAILQ_REMOVE(&iq->iq_list, ih, ih_list);
445 1.6.2.3 jdolecek
446 1.6.2.3 jdolecek iq80310_intr_calculate_masks();
447 1.6.2.3 jdolecek
448 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
449 1.6.2.3 jdolecek }
450 1.6.2.3 jdolecek
451 1.6.2.3 jdolecek void
452 1.6.2.3 jdolecek iq80310_intr_dispatch(struct clockframe *frame)
453 1.6.2.3 jdolecek {
454 1.6.2.3 jdolecek struct intrq *iq;
455 1.6.2.3 jdolecek struct intrhand *ih;
456 1.6.2.3 jdolecek int oldirqstate, pcpl, irq, ibit, hwpend;
457 1.6.2.3 jdolecek
458 1.6.2.3 jdolecek /* First, disable external IRQs. */
459 1.6.2.3 jdolecek i80200_intr_disable(INTCTL_IM);
460 1.6.2.3 jdolecek
461 1.6.2.3 jdolecek pcpl = current_spl_level;
462 1.6.2.3 jdolecek
463 1.6.2.3 jdolecek for (hwpend = iq80310_intstat_read(); hwpend != 0;) {
464 1.6.2.3 jdolecek irq = ffs(hwpend) - 1;
465 1.6.2.3 jdolecek ibit = (1U << irq);
466 1.6.2.3 jdolecek
467 1.6.2.3 jdolecek hwpend &= ~ibit;
468 1.6.2.3 jdolecek
469 1.6.2.3 jdolecek if (pcpl & ibit) {
470 1.6.2.3 jdolecek /*
471 1.6.2.3 jdolecek * IRQ is masked; mark it as pending and check
472 1.6.2.3 jdolecek * the next one. Note: external IRQs are already
473 1.6.2.3 jdolecek * disabled.
474 1.6.2.3 jdolecek */
475 1.6.2.3 jdolecek ipending |= ibit;
476 1.6.2.3 jdolecek continue;
477 1.6.2.3 jdolecek }
478 1.6.2.3 jdolecek
479 1.6.2.3 jdolecek ipending &= ~ibit;
480 1.6.2.2 thorpej
481 1.6.2.3 jdolecek iq = &intrq[irq];
482 1.6.2.3 jdolecek iq->iq_ev.ev_count++;
483 1.6.2.3 jdolecek uvmexp.intrs++;
484 1.6.2.3 jdolecek current_spl_level |= iq->iq_mask;
485 1.6.2.3 jdolecek oldirqstate = enable_interrupts(I32_bit);
486 1.6.2.3 jdolecek for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
487 1.6.2.3 jdolecek ih = TAILQ_NEXT(ih, ih_list)) {
488 1.6.2.3 jdolecek (void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
489 1.6.2.3 jdolecek }
490 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
491 1.6.2.3 jdolecek
492 1.6.2.3 jdolecek current_spl_level = pcpl;
493 1.6.2.3 jdolecek }
494 1.6.2.3 jdolecek
495 1.6.2.3 jdolecek /* Check for pendings soft intrs. */
496 1.6.2.3 jdolecek if ((ipending & ~IRQ_BITS) & ~current_spl_level) {
497 1.6.2.3 jdolecek oldirqstate = enable_interrupts(I32_bit);
498 1.6.2.3 jdolecek iq80310_do_pending();
499 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
500 1.6.2.3 jdolecek }
501 1.6.2.3 jdolecek
502 1.6.2.3 jdolecek /*
503 1.6.2.3 jdolecek * If no hardware interrupts are masked, re-enable external
504 1.6.2.3 jdolecek * interrupts.
505 1.6.2.3 jdolecek */
506 1.6.2.3 jdolecek if ((ipending & IRQ_BITS) == 0)
507 1.6.2.3 jdolecek i80200_intr_enable(INTCTL_IM);
508 1.6.2.2 thorpej }
509