isa_irq.S revision 1.8 1 1.8 tsutsui /* $NetBSD: isa_irq.S,v 1.8 2007/08/13 01:55:31 tsutsui 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.1 thorpej Ldisabled_mask:
105 1.1 thorpej .word _C_LABEL(disabled_mask)
106 1.1 thorpej
107 1.1 thorpej Lcurrent_spl_level:
108 1.1 thorpej .word _C_LABEL(current_spl_level)
109 1.1 thorpej
110 1.1 thorpej Lcurrent_intr_depth:
111 1.1 thorpej .word _C_LABEL(current_intr_depth)
112 1.1 thorpej
113 1.1 thorpej Lvam_io_data:
114 1.1 thorpej .word _C_LABEL(isa_io_bs_tag)
115 1.1 thorpej
116 1.1 thorpej Lspl_masks:
117 1.1 thorpej .word _C_LABEL(spl_masks)
118 1.1 thorpej
119 1.1 thorpej /*
120 1.1 thorpej * Register usage
121 1.1 thorpej *
122 1.1 thorpej * r6 - Address of current handler
123 1.1 thorpej * r7 - Pointer to handler pointer list
124 1.1 thorpej * r8 - Current IRQ requests.
125 1.1 thorpej * r9 - Used to count through possible IRQ bits.
126 1.1 thorpej * r10 - Base address of IOMD
127 1.1 thorpej */
128 1.1 thorpej
129 1.1 thorpej /* Some documentation is in isa_machdep.c */
130 1.1 thorpej ASENTRY_NP(irq_entry)
131 1.1 thorpej sub lr, lr, #0x00000004 /* Adjust the lr */
132 1.1 thorpej
133 1.1 thorpej PUSHFRAMEINSVC /* Push an interrupt frame */
134 1.3 scw ENABLE_ALIGNMENT_FAULTS
135 1.1 thorpej
136 1.1 thorpej /* Load r8 with the ISA 8259 irqs */
137 1.1 thorpej /* r8 <- irq's pending [15:0] */
138 1.1 thorpej
139 1.1 thorpej /* address of 8259 #1 */
140 1.1 thorpej ldr r0, Lvam_io_data
141 1.1 thorpej ldr r0, [r0]
142 1.1 thorpej ldrb r8, [r0, #IO_ICU1] /* ocw3 = irr */
143 1.1 thorpej
144 1.1 thorpej /* clear the IRR bits that are currently masked. */
145 1.1 thorpej ldr r2, Li8259_mask
146 1.1 thorpej ldr r2, [r2]
147 1.1 thorpej mvn r2, r2 /* disabled -> enabled */
148 1.1 thorpej
149 1.1 thorpej /* address of 8259 #2 */
150 1.1 thorpej tst r2, #(1 << IRQ_SLAVE) /* if slave is enabled */
151 1.1 thorpej tstne r8, #(1 << IRQ_SLAVE) /* anything from slave? */
152 1.1 thorpej ldrneb r1, [r0, #IO_ICU2] /* ocw3 = irr */
153 1.1 thorpej orrne r8, r8, r1, lsl #8
154 1.1 thorpej
155 1.1 thorpej and r8, r8, r2 /* clear disabled */
156 1.1 thorpej
157 1.1 thorpej /* clear IRQ 2, which is only used for slave 8259 */
158 1.1 thorpej bic r8, r8, #(1 << IRQ_SLAVE)
159 1.1 thorpej
160 1.1 thorpej /*
161 1.1 thorpej * Note that we have entered the IRQ handler.
162 1.1 thorpej * We are in SVC mode so we cannot use the processor mode
163 1.1 thorpej * to determine if we are in an IRQ. Instead we will count the
164 1.1 thorpej * each time the interrupt handler is nested.
165 1.1 thorpej */
166 1.1 thorpej
167 1.1 thorpej ldr r0, Lcurrent_intr_depth
168 1.1 thorpej ldr r1, [r0]
169 1.1 thorpej add r1, r1, #1
170 1.1 thorpej str r1, [r0]
171 1.1 thorpej
172 1.1 thorpej /* Block the current requested interrupts */
173 1.1 thorpej
174 1.1 thorpej ldr r1, Ldisabled_mask
175 1.1 thorpej ldr r0, [r1]
176 1.1 thorpej stmfd sp!, {r0}
177 1.1 thorpej orr r0, r0, r8
178 1.1 thorpej
179 1.1 thorpej /*
180 1.1 thorpej * Need to block all interrupts at the IPL or lower for
181 1.1 thorpej * all asserted interrupts.
182 1.1 thorpej * This basically emulates hardware interrupt priority levels.
183 1.1 thorpej * Means we need to go through the interrupt mask and for
184 1.1 thorpej * every asserted interrupt we need to mask out all other
185 1.1 thorpej * interrupts at the same or lower IPL.
186 1.1 thorpej * If only we could wait until the main loop but we need to sort
187 1.1 thorpej * this out first so interrupts can be re-enabled.
188 1.1 thorpej *
189 1.1 thorpej * This would benefit from a special ffs type routine
190 1.1 thorpej */
191 1.1 thorpej
192 1.1 thorpej mov r9, #(_SPL_LEVELS - 1)
193 1.1 thorpej ldr r7, Lspl_masks
194 1.1 thorpej
195 1.1 thorpej Lfind_highest_ipl:
196 1.1 thorpej ldr r2, [r7, r9, lsl #2]
197 1.1 thorpej tst r8, r2
198 1.1 thorpej subeq r9, r9, #1
199 1.1 thorpej beq Lfind_highest_ipl
200 1.1 thorpej
201 1.1 thorpej /* r9 = SPL level of highest priority interrupt */
202 1.1 thorpej add r9, r9, #1
203 1.1 thorpej ldr r2, [r7, r9, lsl #2]
204 1.1 thorpej mvn r2, r2
205 1.1 thorpej orr r0, r0, r2
206 1.1 thorpej
207 1.1 thorpej str r0, [r1]
208 1.1 thorpej
209 1.1 thorpej ldr r0, Lcurrent_spl_level
210 1.1 thorpej ldr r1, [r0]
211 1.1 thorpej str r9, [r0]
212 1.1 thorpej stmfd sp!, {r1}
213 1.1 thorpej
214 1.1 thorpej /* Update the IOMD irq masks */
215 1.1 thorpej bl _C_LABEL(irq_setmasks)
216 1.1 thorpej
217 1.6 matt mrs r0, cpsr_all /* Enable IRQ's */
218 1.1 thorpej bic r0, r0, #I32_bit
219 1.1 thorpej msr cpsr_all, r0
220 1.1 thorpej
221 1.2 bjh21 ldr r7, Lirqhandlers
222 1.6 matt mov r9, #0x00000001
223 1.1 thorpej
224 1.1 thorpej irqloop:
225 1.1 thorpej /* This would benefit from a special ffs type routine */
226 1.1 thorpej tst r8, r9 /* Is a bit set ? */
227 1.1 thorpej beq nextirq /* No ? try next bit */
228 1.1 thorpej
229 1.1 thorpej ldr r6, [r7] /* Get address of first handler structure */
230 1.1 thorpej
231 1.1 thorpej teq r6, #0x00000000 /* Do we have a handler */
232 1.1 thorpej moveq r0, r8 /* IRQ requests as arg 0 */
233 1.1 thorpej beq _C_LABEL(stray_irqhandler) /* call special handler */
234 1.1 thorpej
235 1.1 thorpej ldr r0, Lcnt
236 1.1 thorpej ldr r1, [r0, #(V_INTR)]
237 1.1 thorpej add r1, r1, #0x00000001
238 1.1 thorpej str r1, [r0, #(V_INTR)]
239 1.1 thorpej
240 1.1 thorpej irqchainloop:
241 1.1 thorpej ldr r0, [r6, #(IH_ARG)] /* Get argument pointer */
242 1.1 thorpej teq r0, #0x00000000 /* If arg is zero pass stack frame */
243 1.1 thorpej addeq r0, sp, #8 /* ... stack frame */
244 1.5 matt
245 1.2 bjh21 mov lr, pc /* return address */
246 1.1 thorpej ldr pc, [r6, #(IH_FUNC)] /* Call handler */
247 1.1 thorpej
248 1.1 thorpej teq r0, #0x00000001 /* Was the irq serviced ? */
249 1.1 thorpej beq irqdone
250 1.1 thorpej
251 1.1 thorpej ldr r6, [r6, #(IH_NEXT)]
252 1.1 thorpej teq r6, #0x00000000
253 1.1 thorpej bne irqchainloop
254 1.6 matt b nextirq
255 1.1 thorpej
256 1.1 thorpej irqdone:
257 1.6 matt add r3, r6, #IH_EV_COUNT /* get address of ih's ev_count */
258 1.6 matt ldmia r3, {r1-r2} /* load ev_count */
259 1.6 matt adds r1, r1, #0x00000001 /* 64bit incr (lo) */
260 1.6 matt adc r2, r2, #0x00000000 /* 64bit incr (hi) */
261 1.6 matt stmia r3, {r1-r2} /* store ev_count */
262 1.6 matt
263 1.1 thorpej nextirq:
264 1.1 thorpej add r7, r7, #0x00000004 /* update pointer to handlers */
265 1.1 thorpej mov r9, r9, lsl #1 /* move on to next bit */
266 1.1 thorpej teq r9, #(1 << 16) /* done the last bit ? */
267 1.1 thorpej bne irqloop /* no - loop back. */
268 1.1 thorpej
269 1.1 thorpej ldmfd sp!, {r2}
270 1.1 thorpej ldr r1, Lcurrent_spl_level
271 1.1 thorpej str r2, [r1]
272 1.1 thorpej
273 1.1 thorpej /* Restore previous disabled mask */
274 1.1 thorpej ldmfd sp!, {r2}
275 1.1 thorpej ldr r1, Ldisabled_mask
276 1.1 thorpej str r2, [r1]
277 1.1 thorpej bl _C_LABEL(irq_setmasks)
278 1.1 thorpej
279 1.1 thorpej bl _C_LABEL(dosoftints) /* Handle the soft interrupts */
280 1.1 thorpej
281 1.1 thorpej /* Kill IRQ's in preparation for exit */
282 1.6 matt mrs r0, cpsr_all
283 1.6 matt orr r0, r0, #(I32_bit)
284 1.6 matt msr cpsr_all, r0
285 1.1 thorpej
286 1.1 thorpej /* Decrement the nest count */
287 1.1 thorpej ldr r0, Lcurrent_intr_depth
288 1.1 thorpej ldr r1, [r0]
289 1.1 thorpej sub r1, r1, #1
290 1.1 thorpej str r1, [r0]
291 1.1 thorpej
292 1.7 thorpej LOCK_CAS_CHECK
293 1.7 thorpej
294 1.3 scw DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
295 1.1 thorpej PULLFRAMEFROMSVCANDEXIT
296 1.1 thorpej
297 1.1 thorpej /* NOT REACHED */
298 1.1 thorpej b . - 8
299 1.1 thorpej
300 1.1 thorpej Lcurrent_mask:
301 1.1 thorpej .word _C_LABEL(current_mask) /* irq's that are usable */
302 1.1 thorpej
303 1.7 thorpej LOCK_CAS_CHECK_LOCALS
304 1.7 thorpej
305 1.3 scw AST_ALIGNMENT_FAULT_LOCALS
306 1.3 scw
307 1.3 scw
308 1.1 thorpej ENTRY(irq_setmasks)
309 1.1 thorpej /* Disable interrupts */
310 1.1 thorpej mrs r3, cpsr_all
311 1.1 thorpej orr r1, r3, #(I32_bit)
312 1.1 thorpej msr cpsr_all, r1
313 1.1 thorpej
314 1.1 thorpej /* Calculate interrupt mask */
315 1.1 thorpej ldr r1, Lcurrent_mask /* All the enabled interrupts */
316 1.1 thorpej ldrh r1, [r1] /* get hardware bits of mask */
317 1.1 thorpej /* .word 0xe0d110b0 */ /* hand-assembled ldrh r1, [r1] */
318 1.8 tsutsui ldr r0, Lspl_masks
319 1.8 tsutsui ldr r2, Lcurrent_spl_level
320 1.1 thorpej ldr r2, [r2]
321 1.8 tsutsui ldr r2, [r0, r2, lsl #2]
322 1.1 thorpej and r1, r1, r2
323 1.1 thorpej ldr r2, Ldisabled_mask /* Block due to active interrupts */
324 1.1 thorpej ldr r2, [r2]
325 1.1 thorpej bic r1, r1, r2
326 1.1 thorpej
327 1.1 thorpej /* since 8259's are so slow to access, this code does everything
328 1.1 thorpej possible to avoid them */
329 1.1 thorpej
330 1.1 thorpej /* get current mask: these are the bits */
331 1.1 thorpej ldr r0, Li8259_mask
332 1.1 thorpej ldr r2, [r0]
333 1.1 thorpej /* r2 = 0000.0000.0000.0000.ZZZZ.ZZZZ.ZZZZ.ZZZZ */
334 1.1 thorpej
335 1.1 thorpej /* see if there's anything enabled on 8259 #2 */
336 1.1 thorpej tst r1, #0xff00
337 1.1 thorpej
338 1.1 thorpej biceq r1, r1, #(1 << IRQ_SLAVE) /* no, so disable it */
339 1.1 thorpej orrne r1, r1, #(1 << IRQ_SLAVE) /* yes, so enable it */
340 1.1 thorpej /* eq => r1 = 0000.0000.0000.0000.0000.0000.MMMM.M0MM
341 1.6 matt ne => r1 = 0000.0000.0000.0000.MMMM.MMMM.MMMM.M1MM */
342 1.1 thorpej
343 1.1 thorpej /* 8259 bit high => disable */
344 1.1 thorpej mvn r1, r1
345 1.1 thorpej /* eq => r1 = 1111.1111.1111.1111.1111.1111.YYYY.Y1YY
346 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY
347 1.6 matt (for each bit position Y = !M) */
348 1.1 thorpej
349 1.1 thorpej orreq r1, r2, r1, lsl #16
350 1.1 thorpej /* eq => r1 = 1111.1111.YYYY.Y1YY.ZZZZ.ZZZZ.ZZZZ.ZZZZ
351 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY */
352 1.1 thorpej orreq r1, r1, #0x000000FF
353 1.1 thorpej /* eq => r1 = 1111.1111.YYYY.Y1YY.ZZZZ.ZZZZ.1111.1111
354 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY */
355 1.1 thorpej and r1, r1, r1, lsr #16
356 1.1 thorpej /* eq => r1 = 0000.0000.0000.0000.ZZZZ.ZZZZ.YYYY.Y1YY
357 1.6 matt ne => r1 = 0000.0000.0000.0000.YYYY.YYYY.YYYY.Y0YY */
358 1.1 thorpej
359 1.1 thorpej /* if old = new, don't bother to set again.
360 1.1 thorpej fast path to exit, since 8259's are so slow anyway */
361 1.1 thorpej eors r2, r1, r2 /* which bits are different? */
362 1.1 thorpej msreq cpsr_all, r3 /* no bits are different, return */
363 1.1 thorpej moveq pc, lr
364 1.1 thorpej
365 1.1 thorpej /* have to set at least one of the 8259's, store new mask */
366 1.1 thorpej str r1, [r0]
367 1.1 thorpej ldr r0, Lvam_io_data
368 1.1 thorpej ldr r0, [r0]
369 1.1 thorpej
370 1.1 thorpej /* see if there's any change for 8259 #1 (master) */
371 1.1 thorpej tst r2, #0x00FF /* bottom 8 bits different? */
372 1.1 thorpej strneb r1, [r0, #(IO_ICU1 + 1)] /* icu1 / ocw1 */
373 1.1 thorpej
374 1.1 thorpej /* anything for 8259 #2? */
375 1.1 thorpej tst r2, #0xFF00
376 1.1 thorpej mov r1, r1, lsr #8 /* next byte */
377 1.1 thorpej strneb r1, [r0, #(IO_ICU2 + 1)] /* icu2 / ocw1 */
378 1.1 thorpej
379 1.1 thorpej /* Restore old cpsr and exit */
380 1.1 thorpej msr cpsr_all, r3
381 1.1 thorpej mov pc, lr
382 1.1 thorpej
383 1.1 thorpej Lcnt:
384 1.1 thorpej .word _C_LABEL(uvmexp)
385 1.1 thorpej
386 1.1 thorpej Li8259_mask:
387 1.1 thorpej .word _C_LABEL(i8259_mask)
388 1.1 thorpej
389 1.1 thorpej Lirqhandlers:
390 1.1 thorpej .word _C_LABEL(irqhandlers) /* Pointer to array of irqhandlers */
391