isa_irq.S revision 1.14 1 1.14 matt /* $NetBSD: isa_irq.S,v 1.14 2012/09/03 16:35:33 matt Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright 1997
5 1.1 thorpej * Digital Equipment Corporation. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This software is furnished under license and may be used and
8 1.1 thorpej * copied only in accordance with the following terms and conditions.
9 1.1 thorpej * Subject to these conditions, you may download, copy, install,
10 1.1 thorpej * use, modify and distribute this software in source and/or binary
11 1.1 thorpej * form. No title or ownership is transferred hereby.
12 1.1 thorpej *
13 1.1 thorpej * 1) Any source code used, modified or distributed must reproduce
14 1.1 thorpej * and retain this copyright notice and list of conditions as
15 1.1 thorpej * they appear in the source file.
16 1.1 thorpej *
17 1.1 thorpej * 2) No right is granted to use any trade name, trademark, or logo of
18 1.1 thorpej * Digital Equipment Corporation. Neither the "Digital Equipment
19 1.1 thorpej * Corporation" name nor any trademark or logo of Digital Equipment
20 1.1 thorpej * Corporation may be used to endorse or promote products derived
21 1.1 thorpej * from this software without the prior written permission of
22 1.1 thorpej * Digital Equipment Corporation.
23 1.1 thorpej *
24 1.1 thorpej * 3) This software is provided "AS-IS" and any express or implied
25 1.1 thorpej * warranties, including but not limited to, any implied warranties
26 1.1 thorpej * of merchantability, fitness for a particular purpose, or
27 1.1 thorpej * non-infringement are disclaimed. In no event shall DIGITAL be
28 1.1 thorpej * liable for any damages whatsoever, and in particular, DIGITAL
29 1.1 thorpej * shall not be liable for special, indirect, consequential, or
30 1.1 thorpej * incidental damages or damages for lost profits, loss of
31 1.1 thorpej * revenue or loss of use, whether such damages arise in contract,
32 1.1 thorpej * negligence, tort, under statute, in equity, at law or otherwise,
33 1.1 thorpej * even if advised of the possibility of such damage.
34 1.1 thorpej */
35 1.1 thorpej
36 1.1 thorpej /*
37 1.1 thorpej * Copyright (c) 1994-1998 Mark Brinicombe.
38 1.1 thorpej * Copyright (c) 1994 Brini.
39 1.1 thorpej * All rights reserved.
40 1.1 thorpej *
41 1.1 thorpej * This code is derived from software written for Brini by Mark Brinicombe
42 1.1 thorpej *
43 1.1 thorpej * Redistribution and use in source and binary forms, with or without
44 1.1 thorpej * modification, are permitted provided that the following conditions
45 1.1 thorpej * are met:
46 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
47 1.1 thorpej * notice, this list of conditions and the following disclaimer.
48 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
50 1.1 thorpej * documentation and/or other materials provided with the distribution.
51 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
52 1.1 thorpej * must display the following acknowledgement:
53 1.1 thorpej * This product includes software developed by Mark Brinicombe
54 1.1 thorpej * for the NetBSD Project.
55 1.1 thorpej * 4. The name of the company nor the name of the author may be used to
56 1.1 thorpej * endorse or promote products derived from this software without specific
57 1.1 thorpej * prior written permission.
58 1.1 thorpej *
59 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61 1.1 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 1.1 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63 1.1 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
64 1.1 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 1.1 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 1.1 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 1.1 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
68 1.1 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 1.1 thorpej *
70 1.1 thorpej * from: irq.S
71 1.1 thorpej *
72 1.1 thorpej * Low level irq and fiq handlers
73 1.1 thorpej *
74 1.1 thorpej * Created : 27/09/94
75 1.1 thorpej */
76 1.1 thorpej
77 1.1 thorpej #include "assym.h"
78 1.1 thorpej #include <machine/asm.h>
79 1.1 thorpej #include <machine/cpu.h>
80 1.1 thorpej #include <machine/frame.h>
81 1.1 thorpej #include <dev/isa/isareg.h>
82 1.1 thorpej #include <shark/isa/icu.h>
83 1.1 thorpej #include <machine/irqhandler.h>
84 1.1 thorpej
85 1.1 thorpej .text
86 1.1 thorpej .align 0
87 1.1 thorpej
88 1.1 thorpej /*
89 1.1 thorpej *
90 1.1 thorpej * irq_entry
91 1.1 thorpej *
92 1.1 thorpej * Main entry point for the IRQ vector
93 1.1 thorpej *
94 1.1 thorpej * This function reads the irq request bits in the IOMD registers
95 1.1 thorpej * IRQRQA, IRQRQB and DMARQ
96 1.1 thorpej * It then calls an installed handler for each bit that is set.
97 1.1 thorpej * The function stray_irqhandler is called if a handler is not defined
98 1.1 thorpej * for a particular interrupt.
99 1.1 thorpej * If a interrupt handler is found then it is called with r0 containing
100 1.1 thorpej * the argument defined in the handler structure. If the field ih_arg
101 1.1 thorpej * is zero then a pointer to the IRQ frame on the stack is passed instead.
102 1.1 thorpej */
103 1.1 thorpej
104 1.12 matt .Ldisabled_mask:
105 1.1 thorpej .word _C_LABEL(disabled_mask)
106 1.1 thorpej
107 1.12 matt .Lvam_io_data:
108 1.1 thorpej .word _C_LABEL(isa_io_bs_tag)
109 1.1 thorpej
110 1.12 matt .Lspl_masks:
111 1.1 thorpej .word _C_LABEL(spl_masks)
112 1.1 thorpej
113 1.1 thorpej /*
114 1.1 thorpej * Register usage
115 1.1 thorpej *
116 1.14 matt * r5 - Pointer to handler pointer list
117 1.1 thorpej * r6 - Address of current handler
118 1.1 thorpej * r8 - Current IRQ requests.
119 1.1 thorpej * r9 - Used to count through possible IRQ bits.
120 1.1 thorpej * r10 - Base address of IOMD
121 1.1 thorpej */
122 1.1 thorpej
123 1.1 thorpej /* Some documentation is in isa_machdep.c */
124 1.1 thorpej ASENTRY_NP(irq_entry)
125 1.1 thorpej sub lr, lr, #0x00000004 /* Adjust the lr */
126 1.1 thorpej
127 1.1 thorpej PUSHFRAMEINSVC /* Push an interrupt frame */
128 1.12 matt ENABLE_ALIGNMENT_FAULTS /* cpuinfo is in r4 after execution */
129 1.1 thorpej
130 1.1 thorpej /* Load r8 with the ISA 8259 irqs */
131 1.1 thorpej /* r8 <- irq's pending [15:0] */
132 1.1 thorpej
133 1.1 thorpej /* address of 8259 #1 */
134 1.12 matt ldr r0, .Lvam_io_data
135 1.1 thorpej ldr r0, [r0]
136 1.1 thorpej ldrb r8, [r0, #IO_ICU1] /* ocw3 = irr */
137 1.1 thorpej
138 1.1 thorpej /* clear the IRR bits that are currently masked. */
139 1.12 matt ldr r2, .Li8259_mask
140 1.1 thorpej ldr r2, [r2]
141 1.1 thorpej mvn r2, r2 /* disabled -> enabled */
142 1.1 thorpej
143 1.1 thorpej /* address of 8259 #2 */
144 1.1 thorpej tst r2, #(1 << IRQ_SLAVE) /* if slave is enabled */
145 1.1 thorpej tstne r8, #(1 << IRQ_SLAVE) /* anything from slave? */
146 1.1 thorpej ldrneb r1, [r0, #IO_ICU2] /* ocw3 = irr */
147 1.1 thorpej orrne r8, r8, r1, lsl #8
148 1.1 thorpej
149 1.1 thorpej and r8, r8, r2 /* clear disabled */
150 1.1 thorpej
151 1.1 thorpej /* clear IRQ 2, which is only used for slave 8259 */
152 1.1 thorpej bic r8, r8, #(1 << IRQ_SLAVE)
153 1.1 thorpej
154 1.1 thorpej /*
155 1.1 thorpej * Note that we have entered the IRQ handler.
156 1.1 thorpej * We are in SVC mode so we cannot use the processor mode
157 1.1 thorpej * to determine if we are in an IRQ. Instead we will count the
158 1.1 thorpej * each time the interrupt handler is nested.
159 1.1 thorpej */
160 1.1 thorpej
161 1.12 matt ldr r1, [r4, #CI_INTR_DEPTH]
162 1.1 thorpej add r1, r1, #1
163 1.12 matt str r1, [r4, #CI_INTR_DEPTH]
164 1.1 thorpej
165 1.1 thorpej /* Block the current requested interrupts */
166 1.1 thorpej
167 1.12 matt ldr r1, .Ldisabled_mask
168 1.1 thorpej ldr r0, [r1]
169 1.1 thorpej stmfd sp!, {r0}
170 1.1 thorpej orr r0, r0, r8
171 1.1 thorpej
172 1.1 thorpej /*
173 1.1 thorpej * Need to block all interrupts at the IPL or lower for
174 1.1 thorpej * all asserted interrupts.
175 1.1 thorpej * This basically emulates hardware interrupt priority levels.
176 1.1 thorpej * Means we need to go through the interrupt mask and for
177 1.1 thorpej * every asserted interrupt we need to mask out all other
178 1.1 thorpej * interrupts at the same or lower IPL.
179 1.1 thorpej * If only we could wait until the main loop but we need to sort
180 1.1 thorpej * this out first so interrupts can be re-enabled.
181 1.1 thorpej *
182 1.1 thorpej * This would benefit from a special ffs type routine
183 1.1 thorpej */
184 1.1 thorpej
185 1.12 matt mov r9, #(NIPL - 1)
186 1.14 matt ldr r5, .Lspl_masks
187 1.1 thorpej
188 1.12 matt .Lfind_highest_ipl:
189 1.14 matt ldr r2, [r5, r9, lsl #2]
190 1.1 thorpej tst r8, r2
191 1.1 thorpej subeq r9, r9, #1
192 1.12 matt beq .Lfind_highest_ipl
193 1.1 thorpej
194 1.1 thorpej /* r9 = SPL level of highest priority interrupt */
195 1.1 thorpej add r9, r9, #1
196 1.14 matt ldr r2, [r5, r9, lsl #2]
197 1.1 thorpej mvn r2, r2
198 1.1 thorpej orr r0, r0, r2
199 1.1 thorpej
200 1.1 thorpej str r0, [r1]
201 1.1 thorpej
202 1.12 matt ldr r1, [r4, #CI_CPL]
203 1.12 matt str r9, [r4, #CI_CPL]
204 1.1 thorpej stmfd sp!, {r1}
205 1.1 thorpej
206 1.1 thorpej /* Update the IOMD irq masks */
207 1.1 thorpej bl _C_LABEL(irq_setmasks)
208 1.1 thorpej
209 1.6 matt mrs r0, cpsr_all /* Enable IRQ's */
210 1.1 thorpej bic r0, r0, #I32_bit
211 1.1 thorpej msr cpsr_all, r0
212 1.1 thorpej
213 1.14 matt ldr r5, .Lirqhandlers
214 1.6 matt mov r9, #0x00000001
215 1.1 thorpej
216 1.1 thorpej irqloop:
217 1.1 thorpej /* This would benefit from a special ffs type routine */
218 1.1 thorpej tst r8, r9 /* Is a bit set ? */
219 1.1 thorpej beq nextirq /* No ? try next bit */
220 1.1 thorpej
221 1.14 matt ldr r6, [r5] /* Get address of first handler structure */
222 1.1 thorpej
223 1.1 thorpej teq r6, #0x00000000 /* Do we have a handler */
224 1.1 thorpej moveq r0, r8 /* IRQ requests as arg 0 */
225 1.1 thorpej beq _C_LABEL(stray_irqhandler) /* call special handler */
226 1.1 thorpej
227 1.13 matt ldr r0, [r4, #(CI_CC_NINTR)]
228 1.13 matt ldr r1, [r4, #(CI_CC_NINTR+4)]
229 1.13 matt adds r0, r0, #0x00000001
230 1.13 matt adc r1, r1, #0x00000000
231 1.13 matt str r0, [r4, #(CI_CC_NINTR)]
232 1.13 matt ldr r1, [r4, #(CI_CC_NINTR+4)]
233 1.1 thorpej
234 1.1 thorpej irqchainloop:
235 1.1 thorpej ldr r0, [r6, #(IH_ARG)] /* Get argument pointer */
236 1.1 thorpej teq r0, #0x00000000 /* If arg is zero pass stack frame */
237 1.1 thorpej addeq r0, sp, #8 /* ... stack frame */
238 1.5 matt
239 1.2 bjh21 mov lr, pc /* return address */
240 1.1 thorpej ldr pc, [r6, #(IH_FUNC)] /* Call handler */
241 1.1 thorpej
242 1.1 thorpej teq r0, #0x00000001 /* Was the irq serviced ? */
243 1.1 thorpej beq irqdone
244 1.1 thorpej
245 1.1 thorpej ldr r6, [r6, #(IH_NEXT)]
246 1.1 thorpej teq r6, #0x00000000
247 1.1 thorpej bne irqchainloop
248 1.6 matt b nextirq
249 1.1 thorpej
250 1.1 thorpej irqdone:
251 1.6 matt add r3, r6, #IH_EV_COUNT /* get address of ih's ev_count */
252 1.6 matt ldmia r3, {r1-r2} /* load ev_count */
253 1.6 matt adds r1, r1, #0x00000001 /* 64bit incr (lo) */
254 1.6 matt adc r2, r2, #0x00000000 /* 64bit incr (hi) */
255 1.6 matt stmia r3, {r1-r2} /* store ev_count */
256 1.6 matt
257 1.1 thorpej nextirq:
258 1.14 matt add r5, r5, #0x00000004 /* update pointer to handlers */
259 1.1 thorpej mov r9, r9, lsl #1 /* move on to next bit */
260 1.1 thorpej teq r9, #(1 << 16) /* done the last bit ? */
261 1.1 thorpej bne irqloop /* no - loop back. */
262 1.1 thorpej
263 1.1 thorpej ldmfd sp!, {r2}
264 1.12 matt str r2, [r4, #CI_CPL]
265 1.1 thorpej
266 1.1 thorpej /* Restore previous disabled mask */
267 1.1 thorpej ldmfd sp!, {r2}
268 1.12 matt ldr r1, .Ldisabled_mask
269 1.1 thorpej str r2, [r1]
270 1.1 thorpej bl _C_LABEL(irq_setmasks)
271 1.1 thorpej
272 1.10 ad #ifdef __HAVE_FAST_SOFTINTS
273 1.1 thorpej bl _C_LABEL(dosoftints) /* Handle the soft interrupts */
274 1.10 ad #endif
275 1.1 thorpej
276 1.1 thorpej /* Kill IRQ's in preparation for exit */
277 1.6 matt mrs r0, cpsr_all
278 1.6 matt orr r0, r0, #(I32_bit)
279 1.6 matt msr cpsr_all, r0
280 1.1 thorpej
281 1.1 thorpej /* Decrement the nest count */
282 1.12 matt ldr r1, [r4, #CI_INTR_DEPTH]
283 1.1 thorpej sub r1, r1, #1
284 1.12 matt str r1, [r4, #CI_INTR_DEPTH]
285 1.1 thorpej
286 1.7 thorpej LOCK_CAS_CHECK
287 1.7 thorpej
288 1.3 scw DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
289 1.1 thorpej PULLFRAMEFROMSVCANDEXIT
290 1.1 thorpej
291 1.1 thorpej /* NOT REACHED */
292 1.1 thorpej b . - 8
293 1.1 thorpej
294 1.12 matt .Lcurrent_mask:
295 1.1 thorpej .word _C_LABEL(current_mask) /* irq's that are usable */
296 1.1 thorpej
297 1.12 matt .Lcpu_info_store:
298 1.12 matt .word _C_LABEL(cpu_info_store)
299 1.12 matt
300 1.7 thorpej LOCK_CAS_CHECK_LOCALS
301 1.7 thorpej
302 1.3 scw AST_ALIGNMENT_FAULT_LOCALS
303 1.3 scw
304 1.3 scw
305 1.1 thorpej ENTRY(irq_setmasks)
306 1.1 thorpej /* Disable interrupts */
307 1.1 thorpej mrs r3, cpsr_all
308 1.1 thorpej orr r1, r3, #(I32_bit)
309 1.1 thorpej msr cpsr_all, r1
310 1.1 thorpej
311 1.1 thorpej /* Calculate interrupt mask */
312 1.12 matt ldr r1, .Lcurrent_mask /* All the enabled interrupts */
313 1.1 thorpej ldrh r1, [r1] /* get hardware bits of mask */
314 1.1 thorpej /* .word 0xe0d110b0 */ /* hand-assembled ldrh r1, [r1] */
315 1.12 matt ldr r0, .Lspl_masks
316 1.12 matt ldr r2, .Lcpu_info_store
317 1.12 matt ldr r2, [r2, #CI_CPL]
318 1.8 tsutsui ldr r2, [r0, r2, lsl #2]
319 1.1 thorpej and r1, r1, r2
320 1.12 matt ldr r2, .Ldisabled_mask /* Block due to active interrupts */
321 1.1 thorpej ldr r2, [r2]
322 1.1 thorpej bic r1, r1, r2
323 1.1 thorpej
324 1.1 thorpej /* since 8259's are so slow to access, this code does everything
325 1.1 thorpej possible to avoid them */
326 1.1 thorpej
327 1.1 thorpej /* get current mask: these are the bits */
328 1.12 matt ldr r0, .Li8259_mask
329 1.1 thorpej ldr r2, [r0]
330 1.1 thorpej /* r2 = 0000.0000.0000.0000.ZZZZ.ZZZZ.ZZZZ.ZZZZ */
331 1.1 thorpej
332 1.1 thorpej /* see if there's anything enabled on 8259 #2 */
333 1.1 thorpej tst r1, #0xff00
334 1.1 thorpej
335 1.1 thorpej biceq r1, r1, #(1 << IRQ_SLAVE) /* no, so disable it */
336 1.1 thorpej orrne r1, r1, #(1 << IRQ_SLAVE) /* yes, so enable it */
337 1.1 thorpej /* eq => r1 = 0000.0000.0000.0000.0000.0000.MMMM.M0MM
338 1.6 matt ne => r1 = 0000.0000.0000.0000.MMMM.MMMM.MMMM.M1MM */
339 1.1 thorpej
340 1.1 thorpej /* 8259 bit high => disable */
341 1.1 thorpej mvn r1, r1
342 1.1 thorpej /* eq => r1 = 1111.1111.1111.1111.1111.1111.YYYY.Y1YY
343 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY
344 1.6 matt (for each bit position Y = !M) */
345 1.1 thorpej
346 1.1 thorpej orreq r1, r2, r1, lsl #16
347 1.1 thorpej /* eq => r1 = 1111.1111.YYYY.Y1YY.ZZZZ.ZZZZ.ZZZZ.ZZZZ
348 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY */
349 1.1 thorpej orreq r1, r1, #0x000000FF
350 1.1 thorpej /* eq => r1 = 1111.1111.YYYY.Y1YY.ZZZZ.ZZZZ.1111.1111
351 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY */
352 1.1 thorpej and r1, r1, r1, lsr #16
353 1.1 thorpej /* eq => r1 = 0000.0000.0000.0000.ZZZZ.ZZZZ.YYYY.Y1YY
354 1.6 matt ne => r1 = 0000.0000.0000.0000.YYYY.YYYY.YYYY.Y0YY */
355 1.1 thorpej
356 1.1 thorpej /* if old = new, don't bother to set again.
357 1.1 thorpej fast path to exit, since 8259's are so slow anyway */
358 1.1 thorpej eors r2, r1, r2 /* which bits are different? */
359 1.1 thorpej msreq cpsr_all, r3 /* no bits are different, return */
360 1.1 thorpej moveq pc, lr
361 1.1 thorpej
362 1.1 thorpej /* have to set at least one of the 8259's, store new mask */
363 1.1 thorpej str r1, [r0]
364 1.12 matt ldr r0, .Lvam_io_data
365 1.1 thorpej ldr r0, [r0]
366 1.1 thorpej
367 1.1 thorpej /* see if there's any change for 8259 #1 (master) */
368 1.1 thorpej tst r2, #0x00FF /* bottom 8 bits different? */
369 1.1 thorpej strneb r1, [r0, #(IO_ICU1 + 1)] /* icu1 / ocw1 */
370 1.1 thorpej
371 1.1 thorpej /* anything for 8259 #2? */
372 1.1 thorpej tst r2, #0xFF00
373 1.1 thorpej mov r1, r1, lsr #8 /* next byte */
374 1.1 thorpej strneb r1, [r0, #(IO_ICU2 + 1)] /* icu2 / ocw1 */
375 1.1 thorpej
376 1.1 thorpej /* Restore old cpsr and exit */
377 1.1 thorpej msr cpsr_all, r3
378 1.1 thorpej mov pc, lr
379 1.1 thorpej
380 1.12 matt .Li8259_mask:
381 1.1 thorpej .word _C_LABEL(i8259_mask)
382 1.1 thorpej
383 1.12 matt .Lirqhandlers:
384 1.1 thorpej .word _C_LABEL(irqhandlers) /* Pointer to array of irqhandlers */
385