4 * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
38 #ifndef EVBARM_SPL_NOINLINE
39 #define EVBARM_SPL_NOINLINE
43 * Interrupt support for the Integrator FPGA.
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/malloc.h>
52 #include <uvm/uvm_extern.h>
54 #include <arm/cpufunc.h>
56 #include <evbarm/ifpga/ifpgareg.h>
57 #include <evbarm/ifpga/ifpgavar.h>
59 /* Interrupt handler queues. */
60 struct intrq intrq
[NIRQ
];
62 /* Interrupts to mask at each level. */
63 int ifpga_imask
[NIPL
];
65 /* Interrupts pending. */
66 volatile int ifpga_ipending
;
68 /* Software copy of the IRQs we have enabled. */
69 volatile uint32_t intr_enabled
;
71 /* Mask if interrupts steered to FIQs. */
75 * Interrupt bit names.
77 const char * const ifpga_irqnames
[] = {
112 void ifpga_intr_dispatch(struct clockframe
*frame
);
114 extern struct ifpga_softc
*ifpga_sc
;
116 static inline uint32_t
117 ifpga_iintsrc_read(void)
119 return bus_space_read_4(ifpga_sc
->sc_iot
, ifpga_sc
->sc_irq_ioh
,
124 ifpga_enable_irq(int irq
)
127 intr_enabled
|= (1U << irq
);
128 ifpga_set_intrmask();
132 ifpga_disable_irq(int irq
)
135 intr_enabled
&= ~(1U << irq
);
136 ifpga_set_intrmask();
140 * NOTE: This routine must be called with interrupts disabled in the CPSR.
143 ifpga_intr_calculate_masks(void)
149 /* First, figure out which IPLs each IRQ has. */
150 for (irq
= 0; irq
< NIRQ
; irq
++) {
153 ifpga_disable_irq(irq
);
154 for (ih
= TAILQ_FIRST(&iq
->iq_list
); ih
!= NULL
;
155 ih
= TAILQ_NEXT(ih
, ih_list
))
156 levels
|= (1U << ih
->ih_ipl
);
157 iq
->iq_levels
= levels
;
160 /* Next, figure out which IRQs are used by each IPL. */
161 for (ipl
= 0; ipl
< NIPL
; ipl
++) {
163 for (irq
= 0; irq
< NIRQ
; irq
++) {
164 if (intrq
[irq
].iq_levels
& (1U << ipl
))
167 ifpga_imask
[ipl
] = irqs
;
170 KASSERT(ifpga_imask
[IPL_NONE
] == 0);
173 * Enforce a hierarchy that gives "slow" device (or devices with
174 * limited input buffer space/"real-time" requirements) a better
175 * chance at not dropping data.
177 ifpga_imask
[IPL_VM
] |= 0;
178 ifpga_imask
[IPL_SCHED
] |= ifpga_imask
[IPL_VM
];
179 ifpga_imask
[IPL_HIGH
] |= ifpga_imask
[IPL_SCHED
];
182 * Now compute which IRQs must be blocked when servicing any
185 for (irq
= 0; irq
< NIRQ
; irq
++) {
186 int irqs
= (1U << irq
);
188 if (TAILQ_FIRST(&iq
->iq_list
) != NULL
)
189 ifpga_enable_irq(irq
);
190 for (ih
= TAILQ_FIRST(&iq
->iq_list
); ih
!= NULL
;
191 ih
= TAILQ_NEXT(ih
, ih_list
))
192 irqs
|= ifpga_imask
[ih
->ih_ipl
];
208 return (ifpga_spllower(ipl
));
215 return (ifpga_splraise(ipl
));
221 * Initialize the rest of the interrupt subsystem, making it
222 * ready to handle interrupts from devices.
225 ifpga_intr_init(void)
232 for (i
= 0; i
< NIRQ
; i
++) {
234 TAILQ_INIT(&iq
->iq_list
);
236 evcnt_attach_dynamic(&iq
->iq_ev
, EVCNT_TYPE_INTR
,
237 NULL
, "ifpga", ifpga_irqnames
[i
]);
242 ifpga_intr_postinit(void)
244 ifpga_intr_calculate_masks();
246 /* Enable IRQs (don't yet use FIQs). */
247 enable_interrupts(I32_bit
);
251 ifpga_intr_establish(int irq
, int ipl
, int (*func
)(void *), void *arg
)
257 if (irq
< 0 || irq
> NIRQ
)
258 panic("ifpga_intr_establish: IRQ %d out of range", irq
);
260 ih
= malloc(sizeof(*ih
), M_DEVBUF
, M_NOWAIT
);
271 /* All IOP321 interrupts are level-triggered. */
272 iq
->iq_ist
= IST_LEVEL
;
274 oldirqstate
= disable_interrupts(I32_bit
);
276 TAILQ_INSERT_TAIL(&iq
->iq_list
, ih
, ih_list
);
278 ifpga_intr_calculate_masks();
280 restore_interrupts(oldirqstate
);
286 ifpga_intr_disestablish(void *cookie
)
288 struct intrhand
*ih
= cookie
;
289 struct intrq
*iq
= &intrq
[ih
->ih_irq
];
292 oldirqstate
= disable_interrupts(I32_bit
);
294 TAILQ_REMOVE(&iq
->iq_list
, ih
, ih_list
);
296 ifpga_intr_calculate_masks();
298 restore_interrupts(oldirqstate
);
302 ifpga_intr_dispatch(struct clockframe
*frame
)
306 int oldirqstate
, pcpl
, irq
, ibit
, hwpend
;
307 struct cpu_info
* const ci
= curcpu();
311 hwpend
= ifpga_iintsrc_read();
314 * Disable all the interrupts that are pending. We will
315 * reenable them once they are processed and not masked.
317 intr_enabled
&= ~hwpend
;
318 ifpga_set_intrmask();
320 /* Wait for these interrupts to be suppressed. */
321 while ((ifpga_iintsrc_read() & hwpend
) != 0)
324 while (hwpend
!= 0) {
325 irq
= ffs(hwpend
) - 1;
332 * IRQ is masked; mark it as pending and check
333 * the next one. Note: the IRQ is already disabled.
335 ifpga_ipending
|= ibit
;
339 ifpga_ipending
&= ~ibit
;
342 iq
->iq_ev
.ev_count
++;
344 ci
->ci_cpl
|= iq
->iq_mask
;
345 oldirqstate
= enable_interrupts(I32_bit
);
346 for (ih
= TAILQ_FIRST(&iq
->iq_list
); ih
!= NULL
;
347 ih
= TAILQ_NEXT(ih
, ih_list
)) {
348 (void) (*ih
->ih_func
)(ih
->ih_arg
? ih
->ih_arg
: frame
);
350 restore_interrupts(oldirqstate
);
353 hwpend
|= (ifpga_ipending
& IFPGA_INTR_HWMASK
) & ~pcpl
;
355 /* Re-enable this interrupt now that's it's cleared. */
356 intr_enabled
|= ibit
;
357 ifpga_set_intrmask();
360 #ifdef __HAVE_FAST_SOFTINTS