at91aic.c revision 1.1.20.2 1 1.1.20.2 yamt /* $Id: at91aic.c,v 1.1.20.2 2010/03/11 15:02:04 yamt Exp $ */
2 1.1.20.2 yamt /* $NetBSD: at91aic.c,v 1.1.20.2 2010/03/11 15:02:04 yamt Exp $ */
3 1.1.20.1 yamt
4 1.1.20.1 yamt /*
5 1.1.20.1 yamt * Copyright (c) 2007 Embedtronics Oy.
6 1.1.20.1 yamt * All rights reserved.
7 1.1.20.1 yamt *
8 1.1.20.1 yamt * Based on ep93xx_intr.c
9 1.1.20.1 yamt * Copyright (c) 2002 The NetBSD Foundation, Inc.
10 1.1.20.1 yamt * All rights reserved.
11 1.1.20.1 yamt *
12 1.1.20.1 yamt * This code is derived from software contributed to The NetBSD Foundation
13 1.1.20.1 yamt * by Jesse Off
14 1.1.20.1 yamt *
15 1.1.20.1 yamt * This code is derived from software contributed to The NetBSD Foundation
16 1.1.20.1 yamt * by Ichiro FUKUHARA and Naoto Shimazaki.
17 1.1.20.1 yamt *
18 1.1.20.1 yamt * Redistribution and use in source and binary forms, with or without
19 1.1.20.1 yamt * modification, are permitted provided that the following conditions
20 1.1.20.1 yamt * are met:
21 1.1.20.1 yamt * 1. Redistributions of source code must retain the above copyright
22 1.1.20.1 yamt * notice, this list of conditions and the following disclaimer.
23 1.1.20.1 yamt * 2. Redistributions in binary form must reproduce the above copyright
24 1.1.20.1 yamt * notice, this list of conditions and the following disclaimer in the
25 1.1.20.1 yamt * documentation and/or other materials provided with the distribution.
26 1.1.20.1 yamt *
27 1.1.20.1 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1.20.1 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1.20.1 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1.20.1 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1.20.1 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1.20.1 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1.20.1 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1.20.1 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1.20.1 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1.20.1 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1.20.1 yamt * POSSIBILITY OF SUCH DAMAGE.
38 1.1.20.1 yamt */
39 1.1.20.1 yamt
40 1.1.20.1 yamt
41 1.1.20.1 yamt /*
42 1.1.20.1 yamt * Interrupt support for the Atmel's AT91xx9xxx family controllers
43 1.1.20.1 yamt */
44 1.1.20.1 yamt
45 1.1.20.1 yamt #include <sys/param.h>
46 1.1.20.1 yamt #include <sys/systm.h>
47 1.1.20.1 yamt #include <sys/malloc.h>
48 1.1.20.1 yamt #include <sys/termios.h>
49 1.1.20.1 yamt
50 1.1.20.1 yamt #include <uvm/uvm_extern.h>
51 1.1.20.1 yamt
52 1.1.20.1 yamt #include <machine/bus.h>
53 1.1.20.1 yamt #include <machine/intr.h>
54 1.1.20.1 yamt
55 1.1.20.1 yamt #include <arm/cpufunc.h>
56 1.1.20.1 yamt
57 1.1.20.1 yamt #include <arm/at91/at91reg.h>
58 1.1.20.1 yamt #include <arm/at91/at91var.h>
59 1.1.20.1 yamt #include <arm/at91/at91aicreg.h>
60 1.1.20.1 yamt #include <arm/at91/at91aicvar.h>
61 1.1.20.1 yamt
62 1.1.20.1 yamt #define NIRQ 32
63 1.1.20.1 yamt
64 1.1.20.1 yamt /* Interrupt handler queues. */
65 1.1.20.1 yamt struct intrq intrq[NIRQ];
66 1.1.20.1 yamt
67 1.1.20.1 yamt /* Interrupts to mask at each level. */
68 1.1.20.1 yamt static u_int32_t aic_imask[NIPL];
69 1.1.20.1 yamt
70 1.1.20.1 yamt /* Software copy of the IRQs we have enabled. */
71 1.1.20.1 yamt volatile u_int32_t aic_intr_enabled;
72 1.1.20.1 yamt
73 1.1.20.1 yamt #define AICREG(reg) *((volatile u_int32_t*) (AT91AIC_BASE + (reg)))
74 1.1.20.1 yamt
75 1.1.20.1 yamt static int at91aic_match(device_t, cfdata_t, void *);
76 1.1.20.1 yamt static void at91aic_attach(device_t, device_t, void *);
77 1.1.20.1 yamt
78 1.1.20.1 yamt CFATTACH_DECL(at91aic, sizeof(struct device),
79 1.1.20.1 yamt at91aic_match, at91aic_attach, NULL, NULL);
80 1.1.20.1 yamt
81 1.1.20.1 yamt static int
82 1.1.20.1 yamt at91aic_match(device_t parent, cfdata_t match, void *aux)
83 1.1.20.1 yamt {
84 1.1.20.1 yamt if (strcmp(match->cf_name, "at91aic") == 0)
85 1.1.20.1 yamt return 2;
86 1.1.20.1 yamt return 0;
87 1.1.20.1 yamt }
88 1.1.20.1 yamt
89 1.1.20.1 yamt static void
90 1.1.20.1 yamt at91aic_attach(device_t parent, device_t self, void *aux)
91 1.1.20.1 yamt {
92 1.1.20.1 yamt (void)parent; (void)self; (void)aux;
93 1.1.20.1 yamt printf("\n");
94 1.1.20.1 yamt }
95 1.1.20.1 yamt
96 1.1.20.1 yamt static inline void
97 1.1.20.1 yamt at91_set_intrmask(u_int32_t aic_irqs)
98 1.1.20.1 yamt {
99 1.1.20.1 yamt AICREG(AIC_IDCR) = aic_irqs;
100 1.1.20.1 yamt AICREG(AIC_IECR) = aic_intr_enabled & ~aic_irqs;
101 1.1.20.1 yamt }
102 1.1.20.1 yamt
103 1.1.20.1 yamt static inline void
104 1.1.20.1 yamt at91_enable_irq(int irq)
105 1.1.20.1 yamt {
106 1.1.20.1 yamt aic_intr_enabled |= (1U << irq);
107 1.1.20.1 yamt AICREG(AIC_IECR) = (1U << irq);
108 1.1.20.1 yamt }
109 1.1.20.1 yamt
110 1.1.20.1 yamt static inline void
111 1.1.20.1 yamt at91_disable_irq(int irq)
112 1.1.20.1 yamt {
113 1.1.20.1 yamt aic_intr_enabled &= ~(1U << irq);
114 1.1.20.1 yamt AICREG(AIC_IDCR) = (1U << irq);
115 1.1.20.1 yamt }
116 1.1.20.1 yamt
117 1.1.20.1 yamt /*
118 1.1.20.1 yamt * NOTE: This routine must be called with interrupts disabled in the CPSR.
119 1.1.20.1 yamt */
120 1.1.20.1 yamt static void
121 1.1.20.1 yamt at91aic_calculate_masks(void)
122 1.1.20.1 yamt {
123 1.1.20.1 yamt struct intrq *iq;
124 1.1.20.1 yamt struct intrhand *ih;
125 1.1.20.1 yamt int irq, ipl;
126 1.1.20.1 yamt
127 1.1.20.1 yamt /* First, figure out which IPLs each IRQ has. */
128 1.1.20.1 yamt for (irq = 0; irq < NIRQ; irq++) {
129 1.1.20.1 yamt int levels = 0;
130 1.1.20.1 yamt iq = &intrq[irq];
131 1.1.20.1 yamt at91_disable_irq(irq);
132 1.1.20.1 yamt for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
133 1.1.20.1 yamt ih = TAILQ_NEXT(ih, ih_list))
134 1.1.20.1 yamt levels |= (1U << ih->ih_ipl);
135 1.1.20.1 yamt iq->iq_levels = levels;
136 1.1.20.1 yamt }
137 1.1.20.1 yamt
138 1.1.20.1 yamt /* Next, figure out which IRQs are used by each IPL. */
139 1.1.20.1 yamt for (ipl = 0; ipl < NIPL; ipl++) {
140 1.1.20.1 yamt int aic_irqs = 0;
141 1.1.20.1 yamt for (irq = 0; irq < AIC_NIRQ; irq++) {
142 1.1.20.1 yamt if (intrq[irq].iq_levels & (1U << ipl))
143 1.1.20.1 yamt aic_irqs |= (1U << irq);
144 1.1.20.1 yamt }
145 1.1.20.1 yamt aic_imask[ipl] = aic_irqs;
146 1.1.20.1 yamt }
147 1.1.20.1 yamt
148 1.1.20.1 yamt aic_imask[IPL_NONE] = 0;
149 1.1.20.1 yamt
150 1.1.20.1 yamt /*
151 1.1.20.1 yamt * splvm() blocks all interrupts that use the kernel memory
152 1.1.20.1 yamt * allocation facilities.
153 1.1.20.1 yamt */
154 1.1.20.1 yamt aic_imask[IPL_VM] |= aic_imask[IPL_NONE];
155 1.1.20.1 yamt
156 1.1.20.1 yamt /*
157 1.1.20.1 yamt * splclock() must block anything that uses the scheduler.
158 1.1.20.1 yamt */
159 1.1.20.1 yamt aic_imask[IPL_CLOCK] |= aic_imask[IPL_VM];
160 1.1.20.1 yamt
161 1.1.20.1 yamt /*
162 1.1.20.1 yamt * splhigh() must block "everything".
163 1.1.20.1 yamt */
164 1.1.20.1 yamt aic_imask[IPL_HIGH] |= aic_imask[IPL_CLOCK];
165 1.1.20.1 yamt
166 1.1.20.1 yamt /*
167 1.1.20.1 yamt * Now compute which IRQs must be blocked when servicing any
168 1.1.20.1 yamt * given IRQ.
169 1.1.20.1 yamt */
170 1.1.20.1 yamt for (irq = 0; irq < MIN(NIRQ, AIC_NIRQ); irq++) {
171 1.1.20.1 yamt iq = &intrq[irq];
172 1.1.20.1 yamt if (TAILQ_FIRST(&iq->iq_list) != NULL)
173 1.1.20.1 yamt at91_enable_irq(irq);
174 1.1.20.1 yamt }
175 1.1.20.1 yamt /*
176 1.1.20.1 yamt * update current mask
177 1.1.20.1 yamt */
178 1.1.20.1 yamt at91_set_intrmask(aic_imask[curcpl()]);
179 1.1.20.1 yamt }
180 1.1.20.1 yamt
181 1.1.20.1 yamt inline void
182 1.1.20.1 yamt splx(int new)
183 1.1.20.1 yamt {
184 1.1.20.1 yamt int old;
185 1.1.20.1 yamt u_int oldirqstate;
186 1.1.20.1 yamt
187 1.1.20.1 yamt oldirqstate = disable_interrupts(I32_bit);
188 1.1.20.1 yamt old = curcpl();
189 1.1.20.1 yamt if (old != new) {
190 1.1.20.1 yamt set_curcpl(new);
191 1.1.20.1 yamt at91_set_intrmask(aic_imask[new]);
192 1.1.20.1 yamt }
193 1.1.20.1 yamt restore_interrupts(oldirqstate);
194 1.1.20.1 yamt #ifdef __HAVE_FAST_SOFTINTS
195 1.1.20.1 yamt cpu_dosoftints();
196 1.1.20.1 yamt #endif
197 1.1.20.1 yamt }
198 1.1.20.1 yamt
199 1.1.20.1 yamt int
200 1.1.20.1 yamt _splraise(int ipl)
201 1.1.20.1 yamt {
202 1.1.20.1 yamt int old;
203 1.1.20.1 yamt u_int oldirqstate;
204 1.1.20.1 yamt
205 1.1.20.1 yamt oldirqstate = disable_interrupts(I32_bit);
206 1.1.20.1 yamt old = curcpl();
207 1.1.20.1 yamt if (old != ipl) {
208 1.1.20.1 yamt set_curcpl(ipl);
209 1.1.20.1 yamt at91_set_intrmask(aic_imask[ipl]);
210 1.1.20.1 yamt }
211 1.1.20.1 yamt restore_interrupts(oldirqstate);
212 1.1.20.1 yamt
213 1.1.20.1 yamt return (old);
214 1.1.20.1 yamt }
215 1.1.20.1 yamt
216 1.1.20.1 yamt int
217 1.1.20.1 yamt _spllower(int ipl)
218 1.1.20.1 yamt {
219 1.1.20.1 yamt int old = curcpl();
220 1.1.20.1 yamt
221 1.1.20.1 yamt if (old <= ipl)
222 1.1.20.1 yamt return (old);
223 1.1.20.1 yamt splx(ipl);
224 1.1.20.1 yamt #ifdef __HAVE_FAST_SOFTINTS
225 1.1.20.1 yamt cpu_dosoftints();
226 1.1.20.1 yamt #endif
227 1.1.20.1 yamt return (old);
228 1.1.20.1 yamt }
229 1.1.20.1 yamt
230 1.1.20.1 yamt /*
231 1.1.20.1 yamt * at91aic_init:
232 1.1.20.1 yamt *
233 1.1.20.1 yamt * Initialize the rest of the interrupt subsystem, making it
234 1.1.20.1 yamt * ready to handle interrupts from devices.
235 1.1.20.1 yamt */
236 1.1.20.1 yamt void
237 1.1.20.1 yamt at91aic_init(void)
238 1.1.20.1 yamt {
239 1.1.20.1 yamt struct intrq *iq;
240 1.1.20.1 yamt int i;
241 1.1.20.1 yamt
242 1.1.20.1 yamt aic_intr_enabled = 0;
243 1.1.20.1 yamt
244 1.1.20.1 yamt // disable intrrupts:
245 1.1.20.1 yamt AICREG(AIC_IDCR) = -1;
246 1.1.20.1 yamt
247 1.1.20.1 yamt for (i = 0; i < NIRQ; i++) {
248 1.1.20.1 yamt iq = &intrq[i];
249 1.1.20.1 yamt TAILQ_INIT(&iq->iq_list);
250 1.1.20.1 yamt
251 1.1.20.1 yamt sprintf(iq->iq_name, "irq %d", i);
252 1.1.20.1 yamt evcnt_attach_dynamic(&iq->iq_ev, EVCNT_TYPE_INTR,
253 1.1.20.1 yamt NULL, "aic", iq->iq_name);
254 1.1.20.1 yamt }
255 1.1.20.1 yamt
256 1.1.20.1 yamt /* All interrupts should use IRQ not FIQ */
257 1.1.20.1 yamt
258 1.1.20.1 yamt AICREG(AIC_IDCR) = -1; /* disable interrupts */
259 1.1.20.1 yamt AICREG(AIC_ICCR) = -1; /* clear all interrupts */
260 1.1.20.1 yamt AICREG(AIC_DCR) = 0; /* not in debug mode, just to make sure */
261 1.1.20.1 yamt for (i = 0; i < NIRQ; i++) {
262 1.1.20.1 yamt AICREG(AIC_SMR(i)) = 0; /* disable interrupt */
263 1.1.20.1 yamt AICREG(AIC_SVR(i)) = (u_int32_t)&intrq[i]; // address of interrupt queue
264 1.1.20.1 yamt }
265 1.1.20.1 yamt AICREG(AIC_FVR) = 0; // fast interrupt...
266 1.1.20.1 yamt AICREG(AIC_SPU) = 0; // spurious interrupt vector
267 1.1.20.1 yamt
268 1.1.20.1 yamt AICREG(AIC_EOICR) = 0; /* clear logic... */
269 1.1.20.1 yamt AICREG(AIC_EOICR) = 0; /* clear logic... */
270 1.1.20.1 yamt
271 1.1.20.1 yamt at91aic_calculate_masks();
272 1.1.20.1 yamt
273 1.1.20.1 yamt /* Enable IRQs (don't yet use FIQs). */
274 1.1.20.1 yamt enable_interrupts(I32_bit);
275 1.1.20.1 yamt }
276 1.1.20.1 yamt
277 1.1.20.1 yamt void *
278 1.1.20.1 yamt at91aic_intr_establish(int irq, int ipl, int type, int (*ih_func)(void *), void *arg)
279 1.1.20.1 yamt {
280 1.1.20.1 yamt struct intrq* iq;
281 1.1.20.1 yamt struct intrhand* ih;
282 1.1.20.1 yamt u_int oldirqstate;
283 1.1.20.1 yamt unsigned ok;
284 1.1.20.1 yamt uint32_t smr;
285 1.1.20.1 yamt
286 1.1.20.1 yamt if (irq < 0 || irq >= NIRQ)
287 1.1.20.1 yamt panic("intr_establish: IRQ %d out of range", irq);
288 1.1.20.1 yamt if (ipl < 0 || ipl >= NIPL)
289 1.1.20.1 yamt panic("intr_establish: IPL %d out of range", ipl);
290 1.1.20.1 yamt
291 1.1.20.1 yamt smr = 1; // all interrupts have priority one.. ok?
292 1.1.20.1 yamt switch (type) {
293 1.1.20.1 yamt case _INTR_LOW_LEVEL:
294 1.1.20.1 yamt smr |= AIC_SMR_SRCTYPE_LVL_LO;
295 1.1.20.1 yamt break;
296 1.1.20.1 yamt case INTR_HIGH_LEVEL:
297 1.1.20.1 yamt smr |= AIC_SMR_SRCTYPE_LVL_HI;
298 1.1.20.1 yamt break;
299 1.1.20.1 yamt case INTR_FALLING_EDGE:
300 1.1.20.1 yamt smr |= AIC_SMR_SRCTYPE_FALLING;
301 1.1.20.1 yamt break;
302 1.1.20.1 yamt case INTR_RISING_EDGE:
303 1.1.20.1 yamt smr |= AIC_SMR_SRCTYPE_RISING;
304 1.1.20.1 yamt break;
305 1.1.20.1 yamt default:
306 1.1.20.1 yamt panic("intr_establish: interrupt type %d is invalid", type);
307 1.1.20.1 yamt }
308 1.1.20.1 yamt
309 1.1.20.1 yamt ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
310 1.1.20.1 yamt if (ih == NULL)
311 1.1.20.1 yamt return (NULL);
312 1.1.20.1 yamt
313 1.1.20.1 yamt ih->ih_func = ih_func;
314 1.1.20.1 yamt ih->ih_arg = arg;
315 1.1.20.1 yamt ih->ih_irq = irq;
316 1.1.20.1 yamt ih->ih_ipl = ipl;
317 1.1.20.1 yamt
318 1.1.20.1 yamt iq = &intrq[irq];
319 1.1.20.1 yamt
320 1.1.20.1 yamt oldirqstate = disable_interrupts(I32_bit);
321 1.1.20.1 yamt if (TAILQ_FIRST(&iq->iq_list) == NULL || (iq->iq_type & ~type) == 0) {
322 1.1.20.1 yamt AICREG(AIC_SMR(irq)) = smr;
323 1.1.20.1 yamt iq->iq_type = type;
324 1.1.20.1 yamt TAILQ_INSERT_TAIL(&iq->iq_list, ih, ih_list);
325 1.1.20.1 yamt at91aic_calculate_masks();
326 1.1.20.1 yamt ok = 1;
327 1.1.20.1 yamt } else
328 1.1.20.1 yamt ok = 0;
329 1.1.20.1 yamt restore_interrupts(oldirqstate);
330 1.1.20.1 yamt
331 1.1.20.1 yamt if (ok) {
332 1.1.20.1 yamt #ifdef AT91AIC_DEBUG
333 1.1.20.1 yamt int i;
334 1.1.20.1 yamt printf("\n");
335 1.1.20.1 yamt for (i = 0; i < NIPL; i++) {
336 1.1.20.1 yamt printf("IPL%d: aic_imask=0x%08X\n", i, aic_imask[i]);
337 1.1.20.1 yamt }
338 1.1.20.1 yamt #endif
339 1.1.20.1 yamt } else {
340 1.1.20.1 yamt free(ih, M_DEVBUF);
341 1.1.20.1 yamt ih = NULL;
342 1.1.20.1 yamt }
343 1.1.20.1 yamt
344 1.1.20.1 yamt return (ih);
345 1.1.20.1 yamt }
346 1.1.20.1 yamt
347 1.1.20.1 yamt void
348 1.1.20.1 yamt at91aic_intr_disestablish(void *cookie)
349 1.1.20.1 yamt {
350 1.1.20.1 yamt struct intrhand* ih = cookie;
351 1.1.20.1 yamt struct intrq* iq = &intrq[ih->ih_irq];
352 1.1.20.1 yamt u_int oldirqstate;
353 1.1.20.1 yamt
354 1.1.20.1 yamt oldirqstate = disable_interrupts(I32_bit);
355 1.1.20.1 yamt TAILQ_REMOVE(&iq->iq_list, ih, ih_list);
356 1.1.20.1 yamt at91aic_calculate_masks();
357 1.1.20.1 yamt restore_interrupts(oldirqstate);
358 1.1.20.1 yamt }
359 1.1.20.1 yamt
360 1.1.20.1 yamt #include <arm/at91/at91reg.h>
361 1.1.20.1 yamt #include <arm/at91/at91dbgureg.h>
362 1.1.20.1 yamt #include <arm/at91/at91pdcreg.h>
363 1.1.20.1 yamt
364 1.1.20.1 yamt static inline void intr_process(struct intrq *iq, int pcpl, struct irqframe *frame);
365 1.1.20.1 yamt
366 1.1.20.1 yamt static inline void
367 1.1.20.1 yamt intr_process(struct intrq *iq, int pcpl, struct irqframe *frame)
368 1.1.20.1 yamt {
369 1.1.20.1 yamt struct intrhand* ih;
370 1.1.20.1 yamt u_int oldirqstate, intr;
371 1.1.20.1 yamt
372 1.1.20.1 yamt intr = iq - intrq;
373 1.1.20.1 yamt
374 1.1.20.1 yamt iq->iq_ev.ev_count++;
375 1.1.20.1 yamt uvmexp.intrs++;
376 1.1.20.1 yamt
377 1.1.20.1 yamt if ((1U << intr) & aic_imask[pcpl]) {
378 1.1.20.1 yamt panic("interrupt %d should be masked! (aic_imask=0x%X)", intr, aic_imask[pcpl]);
379 1.1.20.1 yamt }
380 1.1.20.1 yamt
381 1.1.20.1 yamt if (iq->iq_busy) {
382 1.1.20.1 yamt panic("interrupt %d busy!", intr);
383 1.1.20.1 yamt }
384 1.1.20.1 yamt
385 1.1.20.1 yamt iq->iq_busy = 1;
386 1.1.20.1 yamt
387 1.1.20.1 yamt for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
388 1.1.20.1 yamt ih = TAILQ_NEXT(ih, ih_list)) {
389 1.1.20.1 yamt set_curcpl(ih->ih_ipl);
390 1.1.20.1 yamt at91_set_intrmask(aic_imask[ih->ih_ipl]);
391 1.1.20.1 yamt oldirqstate = enable_interrupts(I32_bit);
392 1.1.20.1 yamt (void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
393 1.1.20.1 yamt restore_interrupts(oldirqstate);
394 1.1.20.1 yamt }
395 1.1.20.1 yamt
396 1.1.20.1 yamt if (!iq->iq_busy) {
397 1.1.20.1 yamt panic("interrupt %d not busy!", intr);
398 1.1.20.1 yamt }
399 1.1.20.1 yamt iq->iq_busy = 0;
400 1.1.20.1 yamt
401 1.1.20.1 yamt set_curcpl(pcpl);
402 1.1.20.1 yamt at91_set_intrmask(aic_imask[pcpl]);
403 1.1.20.1 yamt }
404 1.1.20.1 yamt
405 1.1.20.1 yamt void
406 1.1.20.1 yamt at91aic_intr_dispatch(struct irqframe *frame)
407 1.1.20.1 yamt {
408 1.1.20.1 yamt struct intrq* iq;
409 1.1.20.1 yamt int pcpl = curcpl();
410 1.1.20.1 yamt
411 1.1.20.1 yamt iq = (struct intrq *)AICREG(AIC_IVR); // get current queue
412 1.1.20.1 yamt
413 1.1.20.1 yamt // OK, service interrupt
414 1.1.20.1 yamt if (iq)
415 1.1.20.1 yamt intr_process(iq, pcpl, frame);
416 1.1.20.1 yamt
417 1.1.20.1 yamt AICREG(AIC_EOICR) = 0; // end of interrupt
418 1.1.20.1 yamt }
419 1.1.20.1 yamt
420 1.1.20.1 yamt #if 0
421 1.1.20.1 yamt void
422 1.1.20.1 yamt at91aic_intr_poll(int irq)
423 1.1.20.1 yamt {
424 1.1.20.1 yamt u_int oldirqstate;
425 1.1.20.1 yamt uint32_t ipr;
426 1.1.20.1 yamt int pcpl = curcpl();
427 1.1.20.1 yamt
428 1.1.20.1 yamt oldirqstate = disable_interrupts(I32_bit);
429 1.1.20.1 yamt ipr = AICREG(AIC_IPR);
430 1.1.20.1 yamt if ((ipr & (1U << irq) & ~aic_imask[pcpl]))
431 1.1.20.1 yamt intr_process(&intrq[irq], pcpl, NULL);
432 1.1.20.1 yamt restore_interrupts(oldirqstate);
433 1.1.20.1 yamt #ifdef __HAVE_FAST_SOFTINTS
434 1.1.20.1 yamt cpu_dosoftints();
435 1.1.20.1 yamt #endif
436 1.1.20.1 yamt }
437 1.1.20.1 yamt #endif
438 1.1.20.1 yamt
439 1.1.20.1 yamt void
440 1.1.20.1 yamt at91aic_intr_poll(void *ihp, int flags)
441 1.1.20.1 yamt {
442 1.1.20.1 yamt struct intrhand* ih = ihp;
443 1.1.20.1 yamt u_int oldirqstate, irq = ih->ih_irq;
444 1.1.20.1 yamt uint32_t ipr;
445 1.1.20.1 yamt int pcpl = curcpl();
446 1.1.20.1 yamt
447 1.1.20.1 yamt oldirqstate = disable_interrupts(I32_bit);
448 1.1.20.1 yamt ipr = AICREG(AIC_IPR);
449 1.1.20.1 yamt if ((ipr & (1U << irq))
450 1.1.20.1 yamt && (flags || !(aic_imask[pcpl] & (1U << irq)))) {
451 1.1.20.1 yamt set_curcpl(ih->ih_ipl);
452 1.1.20.1 yamt at91_set_intrmask(aic_imask[ih->ih_ipl]);
453 1.1.20.1 yamt (void)enable_interrupts(I32_bit);
454 1.1.20.1 yamt (void)(*ih->ih_func)(ih->ih_arg ? ih->ih_arg : NULL);
455 1.1.20.1 yamt (void)disable_interrupts(I32_bit);
456 1.1.20.1 yamt set_curcpl(pcpl);
457 1.1.20.1 yamt at91_set_intrmask(aic_imask[pcpl]);
458 1.1.20.1 yamt }
459 1.1.20.1 yamt restore_interrupts(oldirqstate);
460 1.1.20.1 yamt
461 1.1.20.1 yamt #ifdef __HAVE_FAST_SOFTINTS
462 1.1.20.1 yamt cpu_dosoftints();
463 1.1.20.1 yamt #endif
464 1.1.20.1 yamt }
465