1 1.18 skrll /* $NetBSD: isa_irq.S,v 1.18 2020/11/21 19:58:11 skrll 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.1 thorpej * r6 - Address of current handler 117 1.18 skrll * r7 - Pointer to handler pointer list 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.18 skrll ENABLE_ALIGNMENT_FAULTS /* puts cur{cpu,lwp} in r4/r5 */ 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.17 skrll 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.15 matt ldrbne 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.18 skrll ldr r7, .Lspl_masks 187 1.1 thorpej 188 1.12 matt .Lfind_highest_ipl: 189 1.18 skrll ldr r2, [r7, 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.18 skrll ldr r2, [r7, r9, lsl #2] 197 1.1 thorpej mvn r2, r2 198 1.1 thorpej orr r0, r0, r2 199 1.1 thorpej 200 1.17 skrll 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.16 joerg mrs r0, cpsr /* 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.18 skrll ldr r7, .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.18 skrll ldr r6, [r7] /* 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.18 skrll add r7, r7, #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.1 thorpej /* Kill IRQ's in preparation for exit */ 273 1.16 joerg mrs r0, cpsr 274 1.6 matt orr r0, r0, #(I32_bit) 275 1.6 matt msr cpsr_all, r0 276 1.1 thorpej 277 1.1 thorpej /* Decrement the nest count */ 278 1.12 matt ldr r1, [r4, #CI_INTR_DEPTH] 279 1.1 thorpej sub r1, r1, #1 280 1.12 matt str r1, [r4, #CI_INTR_DEPTH] 281 1.1 thorpej 282 1.7 thorpej LOCK_CAS_CHECK 283 1.7 thorpej 284 1.3 scw DO_AST_AND_RESTORE_ALIGNMENT_FAULTS 285 1.1 thorpej PULLFRAMEFROMSVCANDEXIT 286 1.1 thorpej 287 1.1 thorpej /* NOT REACHED */ 288 1.1 thorpej b . - 8 289 1.1 thorpej 290 1.12 matt .Lcurrent_mask: 291 1.1 thorpej .word _C_LABEL(current_mask) /* irq's that are usable */ 292 1.1 thorpej 293 1.12 matt .Lcpu_info_store: 294 1.12 matt .word _C_LABEL(cpu_info_store) 295 1.12 matt 296 1.7 thorpej LOCK_CAS_CHECK_LOCALS 297 1.7 thorpej 298 1.3 scw AST_ALIGNMENT_FAULT_LOCALS 299 1.3 scw 300 1.3 scw 301 1.1 thorpej ENTRY(irq_setmasks) 302 1.1 thorpej /* Disable interrupts */ 303 1.16 joerg mrs r3, cpsr 304 1.1 thorpej orr r1, r3, #(I32_bit) 305 1.1 thorpej msr cpsr_all, r1 306 1.1 thorpej 307 1.1 thorpej /* Calculate interrupt mask */ 308 1.12 matt ldr r1, .Lcurrent_mask /* All the enabled interrupts */ 309 1.1 thorpej ldrh r1, [r1] /* get hardware bits of mask */ 310 1.1 thorpej /* .word 0xe0d110b0 */ /* hand-assembled ldrh r1, [r1] */ 311 1.12 matt ldr r0, .Lspl_masks 312 1.12 matt ldr r2, .Lcpu_info_store 313 1.12 matt ldr r2, [r2, #CI_CPL] 314 1.8 tsutsui ldr r2, [r0, r2, lsl #2] 315 1.1 thorpej and r1, r1, r2 316 1.12 matt ldr r2, .Ldisabled_mask /* Block due to active interrupts */ 317 1.1 thorpej ldr r2, [r2] 318 1.1 thorpej bic r1, r1, r2 319 1.1 thorpej 320 1.1 thorpej /* since 8259's are so slow to access, this code does everything 321 1.1 thorpej possible to avoid them */ 322 1.1 thorpej 323 1.1 thorpej /* get current mask: these are the bits */ 324 1.12 matt ldr r0, .Li8259_mask 325 1.1 thorpej ldr r2, [r0] 326 1.1 thorpej /* r2 = 0000.0000.0000.0000.ZZZZ.ZZZZ.ZZZZ.ZZZZ */ 327 1.1 thorpej 328 1.1 thorpej /* see if there's anything enabled on 8259 #2 */ 329 1.1 thorpej tst r1, #0xff00 330 1.1 thorpej 331 1.1 thorpej biceq r1, r1, #(1 << IRQ_SLAVE) /* no, so disable it */ 332 1.1 thorpej orrne r1, r1, #(1 << IRQ_SLAVE) /* yes, so enable it */ 333 1.1 thorpej /* eq => r1 = 0000.0000.0000.0000.0000.0000.MMMM.M0MM 334 1.6 matt ne => r1 = 0000.0000.0000.0000.MMMM.MMMM.MMMM.M1MM */ 335 1.1 thorpej 336 1.1 thorpej /* 8259 bit high => disable */ 337 1.1 thorpej mvn r1, r1 338 1.1 thorpej /* eq => r1 = 1111.1111.1111.1111.1111.1111.YYYY.Y1YY 339 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY 340 1.6 matt (for each bit position Y = !M) */ 341 1.1 thorpej 342 1.1 thorpej orreq r1, r2, r1, lsl #16 343 1.1 thorpej /* eq => r1 = 1111.1111.YYYY.Y1YY.ZZZZ.ZZZZ.ZZZZ.ZZZZ 344 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY */ 345 1.1 thorpej orreq r1, r1, #0x000000FF 346 1.1 thorpej /* eq => r1 = 1111.1111.YYYY.Y1YY.ZZZZ.ZZZZ.1111.1111 347 1.6 matt ne => r1 = 1111.1111.1111.1111.YYYY.YYYY.YYYY.Y0YY */ 348 1.1 thorpej and r1, r1, r1, lsr #16 349 1.1 thorpej /* eq => r1 = 0000.0000.0000.0000.ZZZZ.ZZZZ.YYYY.Y1YY 350 1.6 matt ne => r1 = 0000.0000.0000.0000.YYYY.YYYY.YYYY.Y0YY */ 351 1.1 thorpej 352 1.1 thorpej /* if old = new, don't bother to set again. 353 1.1 thorpej fast path to exit, since 8259's are so slow anyway */ 354 1.1 thorpej eors r2, r1, r2 /* which bits are different? */ 355 1.1 thorpej msreq cpsr_all, r3 /* no bits are different, return */ 356 1.1 thorpej moveq pc, lr 357 1.1 thorpej 358 1.1 thorpej /* have to set at least one of the 8259's, store new mask */ 359 1.1 thorpej str r1, [r0] 360 1.12 matt ldr r0, .Lvam_io_data 361 1.1 thorpej ldr r0, [r0] 362 1.1 thorpej 363 1.1 thorpej /* see if there's any change for 8259 #1 (master) */ 364 1.1 thorpej tst r2, #0x00FF /* bottom 8 bits different? */ 365 1.15 matt strbne r1, [r0, #(IO_ICU1 + 1)] /* icu1 / ocw1 */ 366 1.1 thorpej 367 1.1 thorpej /* anything for 8259 #2? */ 368 1.1 thorpej tst r2, #0xFF00 369 1.1 thorpej mov r1, r1, lsr #8 /* next byte */ 370 1.15 matt strbne r1, [r0, #(IO_ICU2 + 1)] /* icu2 / ocw1 */ 371 1.1 thorpej 372 1.1 thorpej /* Restore old cpsr and exit */ 373 1.1 thorpej msr cpsr_all, r3 374 1.1 thorpej mov pc, lr 375 1.1 thorpej 376 1.12 matt .Li8259_mask: 377 1.1 thorpej .word _C_LABEL(i8259_mask) 378 1.1 thorpej 379 1.12 matt .Lirqhandlers: 380 1.1 thorpej .word _C_LABEL(irqhandlers) /* Pointer to array of irqhandlers */ 381