iq80310_intr.c revision 1.6.2.3 1 1.6.2.3 jdolecek /* $NetBSD: iq80310_intr.c,v 1.6.2.3 2002/02/11 20:07:44 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.2 thorpej /*
61 1.6.2.2 thorpej * We have 8 interrupt source bits -- 5 in the XINT3 register, and 3
62 1.6.2.3 jdolecek * in the XINT0 register (the upper 3). Note that the XINT0 IRQs
63 1.6.2.3 jdolecek * (SPCI INTA, INTB, and INTC) are always enabled, since they can not
64 1.6.2.3 jdolecek * be masked out in the CPLD (it provides only status, not masking,
65 1.6.2.3 jdolecek * for those interrupts).
66 1.6.2.2 thorpej */
67 1.6.2.3 jdolecek #define IRQ_BITS 0xff
68 1.6.2.3 jdolecek #define IRQ_BITS_ALWAYS_ON 0xe0
69 1.6.2.2 thorpej
70 1.6.2.3 jdolecek /* Interrupt handler queues. */
71 1.6.2.3 jdolecek struct intrq intrq[NIRQ];
72 1.6.2.2 thorpej
73 1.6.2.3 jdolecek /* Interrupts to mask at each level. */
74 1.6.2.3 jdolecek static int imask[NIPL];
75 1.6.2.2 thorpej
76 1.6.2.3 jdolecek /* Current interrupt priority level. */
77 1.6.2.3 jdolecek __volatile int current_spl_level;
78 1.6.2.2 thorpej
79 1.6.2.3 jdolecek /* Interrupts pending. */
80 1.6.2.3 jdolecek static __volatile int ipending;
81 1.6.2.2 thorpej
82 1.6.2.3 jdolecek /* Software copy of the IRQs we have enabled. */
83 1.6.2.3 jdolecek uint32_t intr_enabled;
84 1.6.2.2 thorpej
85 1.6.2.3 jdolecek /*
86 1.6.2.3 jdolecek * Map a software interrupt queue index (at the top of the word, and
87 1.6.2.3 jdolecek * highest priority softintr is encountered first in an ffs()).
88 1.6.2.3 jdolecek */
89 1.6.2.3 jdolecek #define SI_TO_IRQBIT(si) (1U << (31 - (si)))
90 1.6.2.2 thorpej
91 1.6.2.3 jdolecek /*
92 1.6.2.3 jdolecek * Map a software interrupt queue to an interrupt priority level.
93 1.6.2.3 jdolecek */
94 1.6.2.3 jdolecek static const int si_to_ipl[SI_NQUEUES] = {
95 1.6.2.3 jdolecek IPL_SOFT, /* SI_SOFT */
96 1.6.2.3 jdolecek IPL_SOFTCLOCK, /* SI_SOFTCLOCK */
97 1.6.2.3 jdolecek IPL_SOFTNET, /* SI_SOFTNET */
98 1.6.2.3 jdolecek IPL_SOFTSERIAL, /* SI_SOFTSERIAL */
99 1.6.2.3 jdolecek };
100 1.6.2.2 thorpej
101 1.6.2.3 jdolecek void iq80310_intr_dispatch(struct clockframe *frame);
102 1.6.2.2 thorpej
103 1.6.2.3 jdolecek static __inline uint32_t
104 1.6.2.2 thorpej iq80310_intstat_read(void)
105 1.6.2.2 thorpej {
106 1.6.2.2 thorpej uint32_t intstat;
107 1.6.2.2 thorpej
108 1.6.2.2 thorpej intstat = CPLD_READ(IQ80310_XINT3_STATUS) & 0x1f;
109 1.6.2.2 thorpej if (1/*rev F or later board*/)
110 1.6.2.2 thorpej intstat |= (CPLD_READ(IQ80310_XINT0_STATUS) & 0x7) << 5;
111 1.6.2.2 thorpej
112 1.6.2.3 jdolecek /* XXX Why do we have to mask off? */
113 1.6.2.3 jdolecek return (intstat & intr_enabled);
114 1.6.2.2 thorpej }
115 1.6.2.2 thorpej
116 1.6.2.3 jdolecek static __inline void
117 1.6.2.3 jdolecek iq80310_set_intrmask(void)
118 1.6.2.3 jdolecek {
119 1.6.2.3 jdolecek uint32_t disabled;
120 1.6.2.3 jdolecek
121 1.6.2.3 jdolecek intr_enabled |= IRQ_BITS_ALWAYS_ON;
122 1.6.2.3 jdolecek
123 1.6.2.3 jdolecek /* The XINT_MASK register sets a bit to *disable*. */
124 1.6.2.3 jdolecek disabled = (~intr_enabled) & IRQ_BITS;
125 1.6.2.3 jdolecek
126 1.6.2.3 jdolecek CPLD_WRITE(IQ80310_XINT_MASK, disabled & 0x1f);
127 1.6.2.3 jdolecek }
128 1.6.2.3 jdolecek
129 1.6.2.3 jdolecek static __inline void
130 1.6.2.3 jdolecek iq80310_enable_irq(int irq)
131 1.6.2.3 jdolecek {
132 1.6.2.3 jdolecek
133 1.6.2.3 jdolecek intr_enabled |= (1U << irq);
134 1.6.2.3 jdolecek iq80310_set_intrmask();
135 1.6.2.3 jdolecek }
136 1.6.2.3 jdolecek
137 1.6.2.3 jdolecek static __inline void
138 1.6.2.3 jdolecek iq80310_disable_irq(int irq)
139 1.6.2.3 jdolecek {
140 1.6.2.3 jdolecek
141 1.6.2.3 jdolecek intr_enabled &= ~(1U << irq);
142 1.6.2.3 jdolecek iq80310_set_intrmask();
143 1.6.2.3 jdolecek }
144 1.6.2.3 jdolecek
145 1.6.2.3 jdolecek /*
146 1.6.2.3 jdolecek * NOTE: This routine must be called with interrupts disabled in the CPSR.
147 1.6.2.3 jdolecek */
148 1.6.2.3 jdolecek static void
149 1.6.2.3 jdolecek iq80310_intr_calculate_masks(void)
150 1.6.2.2 thorpej {
151 1.6.2.3 jdolecek struct intrq *iq;
152 1.6.2.3 jdolecek struct intrhand *ih;
153 1.6.2.3 jdolecek int irq, ipl;
154 1.6.2.3 jdolecek
155 1.6.2.3 jdolecek /* First, figure out which IPLs each IRQ has. */
156 1.6.2.3 jdolecek for (irq = 0; irq < NIRQ; irq++) {
157 1.6.2.3 jdolecek int levels = 0;
158 1.6.2.3 jdolecek iq = &intrq[irq];
159 1.6.2.3 jdolecek iq80310_disable_irq(irq);
160 1.6.2.3 jdolecek for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
161 1.6.2.3 jdolecek ih = TAILQ_NEXT(ih, ih_list))
162 1.6.2.3 jdolecek levels |= (1U << ih->ih_ipl);
163 1.6.2.3 jdolecek iq->iq_levels = levels;
164 1.6.2.3 jdolecek }
165 1.6.2.2 thorpej
166 1.6.2.3 jdolecek /* Next, figure out which IRQs are used by each IPL. */
167 1.6.2.3 jdolecek for (ipl = 0; ipl < NIPL; ipl++) {
168 1.6.2.3 jdolecek int irqs = 0;
169 1.6.2.3 jdolecek for (irq = 0; irq < NIRQ; irq++) {
170 1.6.2.3 jdolecek if (intrq[irq].iq_levels & (1U << ipl))
171 1.6.2.3 jdolecek irqs |= (1U << irq);
172 1.6.2.3 jdolecek }
173 1.6.2.3 jdolecek imask[ipl] = irqs;
174 1.6.2.3 jdolecek }
175 1.6.2.3 jdolecek
176 1.6.2.3 jdolecek imask[IPL_NONE] = 0;
177 1.6.2.2 thorpej
178 1.6.2.2 thorpej /*
179 1.6.2.3 jdolecek * Initialize the soft interrupt masks to block themselves.
180 1.6.2.2 thorpej */
181 1.6.2.3 jdolecek imask[IPL_SOFT] = SI_TO_IRQBIT(SI_SOFT);
182 1.6.2.3 jdolecek imask[IPL_SOFTCLOCK] = SI_TO_IRQBIT(SI_SOFTCLOCK);
183 1.6.2.3 jdolecek imask[IPL_SOFTNET] = SI_TO_IRQBIT(SI_SOFTNET);
184 1.6.2.3 jdolecek imask[IPL_SOFTSERIAL] = SI_TO_IRQBIT(SI_SOFTSERIAL);
185 1.6.2.2 thorpej
186 1.6.2.2 thorpej /*
187 1.6.2.3 jdolecek * splsoftclock() is the only interface that users of the
188 1.6.2.3 jdolecek * generic software interrupt facility have to block their
189 1.6.2.3 jdolecek * soft intrs, so splsoftclock() must also block IPL_SOFT.
190 1.6.2.2 thorpej */
191 1.6.2.3 jdolecek imask[IPL_SOFTCLOCK] |= imask[IPL_SOFT];
192 1.6.2.2 thorpej
193 1.6.2.3 jdolecek /*
194 1.6.2.3 jdolecek * splsoftnet() must also block splsoftclock(), since we don't
195 1.6.2.3 jdolecek * want timer-driven network events to occur while we're
196 1.6.2.3 jdolecek * processing incoming packets.
197 1.6.2.3 jdolecek */
198 1.6.2.3 jdolecek imask[IPL_SOFTNET] |= imask[IPL_SOFTCLOCK];
199 1.6.2.3 jdolecek
200 1.6.2.3 jdolecek /*
201 1.6.2.3 jdolecek * Enforce a heirarchy that gives "slow" device (or devices with
202 1.6.2.3 jdolecek * limited input buffer space/"real-time" requirements) a better
203 1.6.2.3 jdolecek * chance at not dropping data.
204 1.6.2.3 jdolecek */
205 1.6.2.3 jdolecek imask[IPL_BIO] |= imask[IPL_SOFTNET];
206 1.6.2.3 jdolecek imask[IPL_NET] |= imask[IPL_BIO];
207 1.6.2.3 jdolecek imask[IPL_SOFTSERIAL] |= imask[IPL_NET];
208 1.6.2.3 jdolecek imask[IPL_TTY] |= imask[IPL_SOFTSERIAL];
209 1.6.2.3 jdolecek
210 1.6.2.3 jdolecek /*
211 1.6.2.3 jdolecek * splvm() blocks all interrupts that use the kernel memory
212 1.6.2.3 jdolecek * allocation facilities.
213 1.6.2.3 jdolecek */
214 1.6.2.3 jdolecek imask[IPL_IMP] |= imask[IPL_TTY];
215 1.6.2.3 jdolecek
216 1.6.2.3 jdolecek /*
217 1.6.2.3 jdolecek * Audio devices are not allowed to perform memory allocation
218 1.6.2.3 jdolecek * in their interrupt routines, and they have fairly "real-time"
219 1.6.2.3 jdolecek * requirements, so give them a high interrupt priority.
220 1.6.2.3 jdolecek */
221 1.6.2.3 jdolecek imask[IPL_AUDIO] |= imask[IPL_IMP];
222 1.6.2.3 jdolecek
223 1.6.2.3 jdolecek /*
224 1.6.2.3 jdolecek * splclock() must block anything that uses the scheduler.
225 1.6.2.3 jdolecek */
226 1.6.2.3 jdolecek imask[IPL_CLOCK] |= imask[IPL_AUDIO];
227 1.6.2.3 jdolecek
228 1.6.2.3 jdolecek /*
229 1.6.2.3 jdolecek * No separate statclock on the IQ80310.
230 1.6.2.3 jdolecek */
231 1.6.2.3 jdolecek imask[IPL_STATCLOCK] |= imask[IPL_CLOCK];
232 1.6.2.3 jdolecek
233 1.6.2.3 jdolecek /*
234 1.6.2.3 jdolecek * splhigh() must block "everything".
235 1.6.2.3 jdolecek */
236 1.6.2.3 jdolecek imask[IPL_HIGH] |= imask[IPL_STATCLOCK];
237 1.6.2.3 jdolecek
238 1.6.2.3 jdolecek /*
239 1.6.2.3 jdolecek * XXX We need serial drivers to run at the absolute highest priority
240 1.6.2.3 jdolecek * in order to avoid overruns, so serial > high.
241 1.6.2.3 jdolecek */
242 1.6.2.3 jdolecek imask[IPL_SERIAL] |= imask[IPL_HIGH];
243 1.6.2.3 jdolecek
244 1.6.2.3 jdolecek /*
245 1.6.2.3 jdolecek * Now compute which IRQs must be blocked when servicing any
246 1.6.2.3 jdolecek * given IRQ.
247 1.6.2.3 jdolecek */
248 1.6.2.3 jdolecek for (irq = 0; irq < NIRQ; irq++) {
249 1.6.2.3 jdolecek int irqs = (1U << irq);
250 1.6.2.3 jdolecek iq = &intrq[irq];
251 1.6.2.3 jdolecek if (TAILQ_FIRST(&iq->iq_list) != NULL)
252 1.6.2.3 jdolecek iq80310_enable_irq(irq);
253 1.6.2.3 jdolecek for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
254 1.6.2.3 jdolecek ih = TAILQ_NEXT(ih, ih_list))
255 1.6.2.3 jdolecek irqs |= imask[ih->ih_ipl];
256 1.6.2.3 jdolecek iq->iq_mask = irqs;
257 1.6.2.3 jdolecek }
258 1.6.2.2 thorpej }
259 1.6.2.2 thorpej
260 1.6.2.3 jdolecek static void
261 1.6.2.3 jdolecek iq80310_do_pending(void)
262 1.6.2.2 thorpej {
263 1.6.2.3 jdolecek static __cpu_simple_lock_t processing = __SIMPLELOCK_UNLOCKED;
264 1.6.2.3 jdolecek int new, oldirqstate;
265 1.6.2.3 jdolecek
266 1.6.2.3 jdolecek if (__cpu_simple_lock_try(&processing) == 0)
267 1.6.2.3 jdolecek return;
268 1.6.2.3 jdolecek
269 1.6.2.3 jdolecek new = current_spl_level;
270 1.6.2.2 thorpej
271 1.6.2.2 thorpej oldirqstate = disable_interrupts(I32_bit);
272 1.6.2.3 jdolecek
273 1.6.2.3 jdolecek #define DO_SOFTINT(si) \
274 1.6.2.3 jdolecek if ((ipending & ~new) & SI_TO_IRQBIT(si)) { \
275 1.6.2.3 jdolecek ipending &= ~SI_TO_IRQBIT(si); \
276 1.6.2.3 jdolecek current_spl_level |= imask[si_to_ipl[(si)]]; \
277 1.6.2.3 jdolecek restore_interrupts(oldirqstate); \
278 1.6.2.3 jdolecek softintr_dispatch(si); \
279 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit); \
280 1.6.2.3 jdolecek current_spl_level = new; \
281 1.6.2.3 jdolecek }
282 1.6.2.3 jdolecek
283 1.6.2.3 jdolecek DO_SOFTINT(SI_SOFTSERIAL);
284 1.6.2.3 jdolecek DO_SOFTINT(SI_SOFTNET);
285 1.6.2.3 jdolecek DO_SOFTINT(SI_SOFTCLOCK);
286 1.6.2.3 jdolecek DO_SOFTINT(SI_SOFT);
287 1.6.2.3 jdolecek
288 1.6.2.3 jdolecek __cpu_simple_unlock(&processing);
289 1.6.2.3 jdolecek
290 1.6.2.2 thorpej restore_interrupts(oldirqstate);
291 1.6.2.2 thorpej }
292 1.6.2.2 thorpej
293 1.6.2.3 jdolecek int
294 1.6.2.3 jdolecek _splraise(int ipl)
295 1.6.2.3 jdolecek {
296 1.6.2.3 jdolecek int old, oldirqstate;
297 1.6.2.3 jdolecek
298 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit);
299 1.6.2.3 jdolecek old = current_spl_level;
300 1.6.2.3 jdolecek current_spl_level |= imask[ipl];
301 1.6.2.3 jdolecek
302 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
303 1.6.2.3 jdolecek
304 1.6.2.3 jdolecek return (old);
305 1.6.2.3 jdolecek }
306 1.6.2.3 jdolecek
307 1.6.2.3 jdolecek __inline void
308 1.6.2.3 jdolecek splx(int new)
309 1.6.2.2 thorpej {
310 1.6.2.3 jdolecek int old;
311 1.6.2.2 thorpej
312 1.6.2.3 jdolecek old = current_spl_level;
313 1.6.2.3 jdolecek current_spl_level = new;
314 1.6.2.3 jdolecek
315 1.6.2.3 jdolecek /*
316 1.6.2.3 jdolecek * If there are pending hardware interrupts (i.e. the
317 1.6.2.3 jdolecek * external interrupt is disabled in the ICU), and all
318 1.6.2.3 jdolecek * hardware interrupts are being unblocked, then re-enable
319 1.6.2.3 jdolecek * the external hardware interrupt.
320 1.6.2.3 jdolecek *
321 1.6.2.3 jdolecek * XXX We have to wait for ALL hardware interrupts to
322 1.6.2.3 jdolecek * XXX be unblocked, because we currently lose if we
323 1.6.2.3 jdolecek * XXX get nested interrupts, and I don't know why yet.
324 1.6.2.3 jdolecek */
325 1.6.2.3 jdolecek if ((new & IRQ_BITS) == 0 && (ipending & IRQ_BITS))
326 1.6.2.3 jdolecek i80200_intr_enable(INTCTL_IM);
327 1.6.2.3 jdolecek
328 1.6.2.3 jdolecek /* If there are software interrupts to process, do it. */
329 1.6.2.3 jdolecek if ((ipending & ~IRQ_BITS) & ~new)
330 1.6.2.3 jdolecek iq80310_do_pending();
331 1.6.2.3 jdolecek }
332 1.6.2.3 jdolecek
333 1.6.2.3 jdolecek int
334 1.6.2.3 jdolecek _spllower(int ipl)
335 1.6.2.3 jdolecek {
336 1.6.2.3 jdolecek int old = current_spl_level;
337 1.6.2.3 jdolecek
338 1.6.2.3 jdolecek splx(imask[ipl]);
339 1.6.2.3 jdolecek return (old);
340 1.6.2.2 thorpej }
341 1.6.2.2 thorpej
342 1.6.2.2 thorpej void
343 1.6.2.3 jdolecek _setsoftintr(int si)
344 1.6.2.2 thorpej {
345 1.6.2.3 jdolecek int oldirqstate;
346 1.6.2.3 jdolecek
347 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit);
348 1.6.2.3 jdolecek ipending |= SI_TO_IRQBIT(si);
349 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
350 1.6.2.2 thorpej
351 1.6.2.3 jdolecek /* Process unmasked pending soft interrupts. */
352 1.6.2.3 jdolecek if ((ipending & ~IRQ_BITS) & ~current_spl_level)
353 1.6.2.3 jdolecek iq80310_do_pending();
354 1.6.2.2 thorpej }
355 1.6.2.2 thorpej
356 1.6.2.2 thorpej void
357 1.6.2.3 jdolecek iq80310_intr_init(void)
358 1.6.2.2 thorpej {
359 1.6.2.3 jdolecek struct intrq *iq;
360 1.6.2.3 jdolecek int i;
361 1.6.2.3 jdolecek
362 1.6.2.3 jdolecek /*
363 1.6.2.3 jdolecek * The Secondary PCI interrupts INTA, INTB, and INTC
364 1.6.2.3 jdolecek * area always enabled, since they cannot be masked
365 1.6.2.3 jdolecek * in the CPLD.
366 1.6.2.3 jdolecek */
367 1.6.2.3 jdolecek intr_enabled |= IRQ_BITS_ALWAYS_ON;
368 1.6.2.2 thorpej
369 1.6.2.3 jdolecek for (i = 0; i < NIRQ; i++) {
370 1.6.2.3 jdolecek iq = &intrq[i];
371 1.6.2.3 jdolecek TAILQ_INIT(&iq->iq_list);
372 1.6.2.3 jdolecek
373 1.6.2.3 jdolecek sprintf(iq->iq_name, "irq %d", i);
374 1.6.2.3 jdolecek evcnt_attach_dynamic(&iq->iq_ev, EVCNT_TYPE_INTR,
375 1.6.2.3 jdolecek NULL, "iq80310", iq->iq_name);
376 1.6.2.3 jdolecek }
377 1.6.2.3 jdolecek
378 1.6.2.3 jdolecek iq80310_intr_calculate_masks();
379 1.6.2.3 jdolecek
380 1.6.2.3 jdolecek /* Enable external interrupts on the i80200. */
381 1.6.2.3 jdolecek i80200_extirq_dispatch = iq80310_intr_dispatch;
382 1.6.2.3 jdolecek i80200_intr_enable(INTCTL_IM);
383 1.6.2.3 jdolecek
384 1.6.2.3 jdolecek /* Enable IRQs (don't yet use FIQs). */
385 1.6.2.3 jdolecek enable_interrupts(I32_bit);
386 1.6.2.2 thorpej }
387 1.6.2.2 thorpej
388 1.6.2.2 thorpej void *
389 1.6.2.2 thorpej iq80310_intr_establish(int irq, int ipl, int (*func)(void *), void *arg)
390 1.6.2.2 thorpej {
391 1.6.2.3 jdolecek struct intrq *iq;
392 1.6.2.3 jdolecek struct intrhand *ih;
393 1.6.2.2 thorpej u_int oldirqstate;
394 1.6.2.3 jdolecek
395 1.6.2.3 jdolecek if (irq < 0 || irq > NIRQ)
396 1.6.2.3 jdolecek panic("iq80310_intr_establish: IRQ %d out of range", irq);
397 1.6.2.2 thorpej
398 1.6.2.2 thorpej ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
399 1.6.2.2 thorpej if (ih == NULL)
400 1.6.2.2 thorpej return (NULL);
401 1.6.2.2 thorpej
402 1.6.2.2 thorpej ih->ih_func = func;
403 1.6.2.2 thorpej ih->ih_arg = arg;
404 1.6.2.3 jdolecek ih->ih_ipl = ipl;
405 1.6.2.3 jdolecek ih->ih_irq = irq;
406 1.6.2.2 thorpej
407 1.6.2.3 jdolecek iq = &intrq[irq];
408 1.6.2.2 thorpej
409 1.6.2.3 jdolecek /* All IQ80310 interrupts are level-triggered. */
410 1.6.2.3 jdolecek iq->iq_ist = IST_LEVEL;
411 1.6.2.2 thorpej
412 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit);
413 1.6.2.2 thorpej
414 1.6.2.3 jdolecek TAILQ_INSERT_TAIL(&iq->iq_list, ih, ih_list);
415 1.6.2.2 thorpej
416 1.6.2.3 jdolecek iq80310_intr_calculate_masks();
417 1.6.2.2 thorpej
418 1.6.2.2 thorpej restore_interrupts(oldirqstate);
419 1.6.2.2 thorpej
420 1.6.2.2 thorpej return (ih);
421 1.6.2.2 thorpej }
422 1.6.2.2 thorpej
423 1.6.2.2 thorpej void
424 1.6.2.2 thorpej iq80310_intr_disestablish(void *cookie)
425 1.6.2.2 thorpej {
426 1.6.2.3 jdolecek struct intrhand *ih = cookie;
427 1.6.2.3 jdolecek struct intrq *iq = &intrq[ih->ih_irq];
428 1.6.2.3 jdolecek int oldirqstate;
429 1.6.2.3 jdolecek
430 1.6.2.3 jdolecek oldirqstate = disable_interrupts(I32_bit);
431 1.6.2.3 jdolecek
432 1.6.2.3 jdolecek TAILQ_REMOVE(&iq->iq_list, ih, ih_list);
433 1.6.2.3 jdolecek
434 1.6.2.3 jdolecek iq80310_intr_calculate_masks();
435 1.6.2.3 jdolecek
436 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
437 1.6.2.3 jdolecek }
438 1.6.2.3 jdolecek
439 1.6.2.3 jdolecek void
440 1.6.2.3 jdolecek iq80310_intr_dispatch(struct clockframe *frame)
441 1.6.2.3 jdolecek {
442 1.6.2.3 jdolecek struct intrq *iq;
443 1.6.2.3 jdolecek struct intrhand *ih;
444 1.6.2.3 jdolecek int oldirqstate, pcpl, irq, ibit, hwpend;
445 1.6.2.3 jdolecek
446 1.6.2.3 jdolecek /* First, disable external IRQs. */
447 1.6.2.3 jdolecek i80200_intr_disable(INTCTL_IM);
448 1.6.2.3 jdolecek
449 1.6.2.3 jdolecek pcpl = current_spl_level;
450 1.6.2.3 jdolecek
451 1.6.2.3 jdolecek for (hwpend = iq80310_intstat_read(); hwpend != 0;) {
452 1.6.2.3 jdolecek irq = ffs(hwpend) - 1;
453 1.6.2.3 jdolecek ibit = (1U << irq);
454 1.6.2.3 jdolecek
455 1.6.2.3 jdolecek hwpend &= ~ibit;
456 1.6.2.3 jdolecek
457 1.6.2.3 jdolecek if (pcpl & ibit) {
458 1.6.2.3 jdolecek /*
459 1.6.2.3 jdolecek * IRQ is masked; mark it as pending and check
460 1.6.2.3 jdolecek * the next one. Note: external IRQs are already
461 1.6.2.3 jdolecek * disabled.
462 1.6.2.3 jdolecek */
463 1.6.2.3 jdolecek ipending |= ibit;
464 1.6.2.3 jdolecek continue;
465 1.6.2.3 jdolecek }
466 1.6.2.3 jdolecek
467 1.6.2.3 jdolecek ipending &= ~ibit;
468 1.6.2.2 thorpej
469 1.6.2.3 jdolecek iq = &intrq[irq];
470 1.6.2.3 jdolecek iq->iq_ev.ev_count++;
471 1.6.2.3 jdolecek uvmexp.intrs++;
472 1.6.2.3 jdolecek current_spl_level |= iq->iq_mask;
473 1.6.2.3 jdolecek oldirqstate = enable_interrupts(I32_bit);
474 1.6.2.3 jdolecek for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
475 1.6.2.3 jdolecek ih = TAILQ_NEXT(ih, ih_list)) {
476 1.6.2.3 jdolecek (void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
477 1.6.2.3 jdolecek }
478 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
479 1.6.2.3 jdolecek
480 1.6.2.3 jdolecek current_spl_level = pcpl;
481 1.6.2.3 jdolecek }
482 1.6.2.3 jdolecek
483 1.6.2.3 jdolecek /* Check for pendings soft intrs. */
484 1.6.2.3 jdolecek if ((ipending & ~IRQ_BITS) & ~current_spl_level) {
485 1.6.2.3 jdolecek oldirqstate = enable_interrupts(I32_bit);
486 1.6.2.3 jdolecek iq80310_do_pending();
487 1.6.2.3 jdolecek restore_interrupts(oldirqstate);
488 1.6.2.3 jdolecek }
489 1.6.2.3 jdolecek
490 1.6.2.3 jdolecek /*
491 1.6.2.3 jdolecek * If no hardware interrupts are masked, re-enable external
492 1.6.2.3 jdolecek * interrupts.
493 1.6.2.3 jdolecek */
494 1.6.2.3 jdolecek if ((ipending & IRQ_BITS) == 0)
495 1.6.2.3 jdolecek i80200_intr_enable(INTCTL_IM);
496 1.6.2.2 thorpej }
497