5 * Digital Equipment Corporation. All rights reserved.
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file.
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of
22 * Digital Equipment Corporation.
24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage.
37 * Copyright (c) 1994-1998 Mark Brinicombe.
38 * Copyright (c) 1994 Brini.
39 * All rights reserved.
41 * This code is derived from software written for Brini by Mark Brinicombe
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by Mark Brinicombe
54 * for the NetBSD Project.
55 * 4. The name of the company nor the name of the author may be used to
56 * endorse or promote products derived from this software without specific
57 * prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
64 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
68 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 * Low level irq and fiq handlers
78 #include <machine/asm.h>
79 #include <machine/cpu.h>
80 #include <machine/frame.h>
81 #include <dev/isa/isareg.h>
82 #include <shark/isa/icu.h>
83 #include <machine/irqhandler.h>
92 * Main entry point for the IRQ vector
94 * This function reads the irq request bits in the IOMD registers
95 * IRQRQA, IRQRQB and DMARQ
96 * It then calls an installed handler for each bit that is set.
97 * The function stray_irqhandler is called if a handler is not defined
98 * for a particular interrupt.
99 * If a interrupt handler is found then it is called with r0 containing
100 * the argument defined in the handler structure. If the field ih_arg
101 * is zero then a pointer to the IRQ frame on the stack is passed instead.
105 .word _C_LABEL(disabled_mask)
108 .word _C_LABEL(isa_io_bs_tag)
111 .word _C_LABEL(spl_masks)
116 * r6 - Address of current handler
117 * r7 - Pointer to handler pointer list
118 * r8 - Current IRQ requests.
119 * r9 - Used to count through possible IRQ bits.
120 * r10 - Base address of IOMD
123 /* Some documentation is in isa_machdep.c */
124 ASENTRY_NP(irq_entry)
125 sub lr, lr, #0x00000004 /* Adjust the lr */
127 PUSHFRAMEINSVC /* Push an interrupt frame */
128 ENABLE_ALIGNMENT_FAULTS /* cpuinfo is in r4 after execution */
130 /* Load r8 with the ISA 8259 irqs */
131 /* r8 <- irq's pending [15:0] */
133 /* address of 8259 #1 */
134 ldr r0, .Lvam_io_data
136 ldrb r8, [r0, #IO_ICU1] /* ocw3 = irr */
138 /* clear the IRR bits that are currently masked. */
141 mvn r2, r2 /* disabled -> enabled */
143 /* address of 8259 #2 */
144 tst r2, #(1 << IRQ_SLAVE) /* if slave is enabled */
145 tstne r8, #(1 << IRQ_SLAVE) /* anything from slave? */
146 ldrneb r1, [r0, #IO_ICU2] /* ocw3 = irr */
147 orrne r8, r8, r1, lsl #8
149 and r8, r8, r2 /* clear disabled */
151 /* clear IRQ 2, which is only used for slave 8259 */
152 bic r8, r8, #(1 << IRQ_SLAVE)
155 * Note that we have entered the IRQ handler.
156 * We are in SVC mode so we cannot use the processor mode
157 * to determine if we are in an IRQ. Instead we will count the
158 * each time the interrupt handler is nested.
161 ldr r1, [r4, #CI_INTR_DEPTH]
163 str r1, [r4, #CI_INTR_DEPTH]
165 /* Block the current requested interrupts */
167 ldr r1, .Ldisabled_mask
173 * Need to block all interrupts at the IPL or lower for
174 * all asserted interrupts.
175 * This basically emulates hardware interrupt priority levels.
176 * Means we need to go through the interrupt mask and for
177 * every asserted interrupt we need to mask out all other
178 * interrupts at the same or lower IPL.
179 * If only we could wait until the main loop but we need to sort
180 * this out first so interrupts can be re-enabled.
182 * This would benefit from a special ffs type routine
189 ldr r2, [r7, r9, lsl #2]
192 beq .Lfind_highest_ipl
194 /* r9 = SPL level of highest priority interrupt */
196 ldr r2, [r7, r9, lsl #2]
202 ldr r1, [r4, #CI_CPL]
203 str r9, [r4, #CI_CPL]
206 /* Update the IOMD irq masks */
207 bl _C_LABEL(irq_setmasks)
209 mrs r0, cpsr_all /* Enable IRQ's */
213 ldr r7, .Lirqhandlers
217 /* This would benefit from a special ffs type routine */
218 tst r8, r9 /* Is a bit set ? */
219 beq nextirq /* No ? try next bit */
221 ldr r6, [r7] /* Get address of first handler structure */
223 teq r6, #0x00000000 /* Do we have a handler */
224 moveq r0, r8 /* IRQ requests as arg 0 */
225 beq _C_LABEL(stray_irqhandler) /* call special handler */
228 ldr r1, [r0, #(V_INTR)]
229 add r1, r1, #0x00000001
230 str r1, [r0, #(V_INTR)]
233 ldr r0, [r6, #(IH_ARG)] /* Get argument pointer */
234 teq r0, #0x00000000 /* If arg is zero pass stack frame */
235 addeq r0, sp, #8 /* ... stack frame */
237 mov lr, pc /* return address */
238 ldr pc, [r6, #(IH_FUNC)] /* Call handler */
240 teq r0, #0x00000001 /* Was the irq serviced ? */
243 ldr r6, [r6, #(IH_NEXT)]
249 add r3, r6, #IH_EV_COUNT /* get address of ih's ev_count */
250 ldmia r3, {r1-r2} /* load ev_count */
251 adds r1, r1, #0x00000001 /* 64bit incr (lo) */
252 adc r2, r2, #0x00000000 /* 64bit incr (hi) */
253 stmia r3, {r1-r2} /* store ev_count */
256 add r7, r7, #0x00000004 /* update pointer to handlers */
257 mov r9, r9, lsl #1 /* move on to next bit */
258 teq r9, #(1 << 16) /* done the last bit ? */
259 bne irqloop /* no - loop back. */
262 str r2, [r4, #CI_CPL]
264 /* Restore previous disabled mask */
266 ldr r1, .Ldisabled_mask
268 bl _C_LABEL(irq_setmasks)
270 #ifdef __HAVE_FAST_SOFTINTS
271 bl _C_LABEL(dosoftints) /* Handle the soft interrupts */
274 /* Kill IRQ's in preparation for exit */
276 orr r0, r0, #(I32_bit)
279 /* Decrement the nest count */
280 ldr r1, [r4, #CI_INTR_DEPTH]
282 str r1, [r4, #CI_INTR_DEPTH]
286 DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
287 PULLFRAMEFROMSVCANDEXIT
293 .word _C_LABEL(current_mask) /* irq's that are usable */
296 .word _C_LABEL(cpu_info_store)
298 LOCK_CAS_CHECK_LOCALS
300 AST_ALIGNMENT_FAULT_LOCALS
304 /* Disable interrupts */
306 orr r1, r3, #(I32_bit)
309 /* Calculate interrupt mask */
310 ldr r1, .Lcurrent_mask /* All the enabled interrupts */
311 ldrh r1, [r1] /* get hardware bits of mask */
312 /* .word 0xe0d110b0 */ /* hand-assembled ldrh r1, [r1] */
314 ldr r2, .Lcpu_info_store
315 ldr r2, [r2, #CI_CPL]
316 ldr r2, [r0, r2, lsl #2]
318 ldr r2, .Ldisabled_mask /* Block due to active interrupts */
322 /* since 8259's are so slow to access, this code does everything
323 possible to avoid them */
325 /* get current mask: these are the bits */
328 /* r2 = 0000.0000.0000.0000.ZZZZ.ZZZZ.ZZZZ.ZZZZ */
330 /* see if there's anything enabled on 8259 #2 */
333 biceq r1, r1, #(1 << IRQ_SLAVE) /* no, so disable it */
334 orrne r1, r1, #(1 << IRQ_SLAVE) /* yes, so enable it */
335 /* eq => r1 = 0000.0000.0000.0000.0000.0000.MMMM.M0MM
336 ne => r1 = 0000.0000.0000.0000.MMMM.MMMM.MMMM.M1MM */
338 /* 8259 bit high => disable */
340 /* eq => r1 = 1111.1111.1111.1111.1111.1111.YYYY.Y1YY
341 ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY
342 (for each bit position Y = !M) */
344 orreq r1, r2, r1, lsl #16
345 /* eq => r1 = 1111.1111.YYYY.Y1YY.ZZZZ.ZZZZ.ZZZZ.ZZZZ
346 ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY */
347 orreq r1, r1, #0x000000FF
348 /* eq => r1 = 1111.1111.YYYY.Y1YY.ZZZZ.ZZZZ.1111.1111
349 ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY */
350 and r1, r1, r1, lsr #16
351 /* eq => r1 = 0000.0000.0000.0000.ZZZZ.ZZZZ.YYYY.Y1YY
352 ne => r1 = 0000.0000.0000.0000.YYYY.YYYY.YYYY.Y0YY */
354 /* if old = new, don't bother to set again.
355 fast path to exit, since 8259's are so slow anyway */
356 eors r2, r1, r2 /* which bits are different? */
357 msreq cpsr_all, r3 /* no bits are different, return */
360 /* have to set at least one of the 8259's, store new mask */
362 ldr r0, .Lvam_io_data
365 /* see if there's any change for 8259 #1 (master) */
366 tst r2, #0x00FF /* bottom 8 bits different? */
367 strneb r1, [r0, #(IO_ICU1 + 1)] /* icu1 / ocw1 */
369 /* anything for 8259 #2? */
371 mov r1, r1, lsr #8 /* next byte */
372 strneb r1, [r0, #(IO_ICU2 + 1)] /* icu2 / ocw1 */
374 /* Restore old cpsr and exit */
379 .word _C_LABEL(uvmexp)
382 .word _C_LABEL(i8259_mask)
385 .word _C_LABEL(irqhandlers) /* Pointer to array of irqhandlers */