1 /* $NetBSD: intr.c,v 1.39 2026/11/14 19:02:13 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Adam Glass, Gordon W. Ross, and Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Link and dispatch interrupts. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.39 2026/11/14 19:02:13 thorpej Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/vmmeter.h> 42 #include <sys/cpu.h> 43 #include <sys/intr.h> 44 45 #include <m68k/vectors.h> 46 47 #include <machine/psc.h> 48 #include <machine/viareg.h> 49 50 #define NISR 8 51 #define ISRLOC 0x18 52 53 static int intr_noint(void *); 54 55 static int ((*intr_func[NISR])(void *)) = { 56 intr_noint, 57 intr_noint, 58 intr_noint, 59 intr_noint, 60 intr_noint, 61 intr_noint, 62 intr_noint, 63 intr_noint 64 }; 65 static void *intr_arg[NISR] = { 66 NULL, 67 NULL, 68 NULL, 69 NULL, 70 NULL, 71 NULL, 72 NULL, 73 NULL 74 }; 75 76 #ifdef DEBUG 77 int intr_debug = 0; 78 #endif 79 80 /* 81 * Some of the below are not used yet, but might be used someday on the 82 * IIfx/Q700/900/950/etc. where the interrupt controller may be reprogrammed 83 * to interrupt on different levels as listed in locore.s 84 */ 85 uint16_t ipl2psl_table[NIPL]; 86 87 extern u_int intrcnt[]; /* from locore.s */ 88 89 void intr_computeipl(void); 90 91 #define MAX_INAME_LENGTH 53 92 #define STD_INAMES \ 93 "spur\0via1\0via2\0unused1\0scc\0unused2\0unused3\0nmi\0clock\0" 94 #define AUX_INAMES \ 95 "spur\0soft\0via2\0ethernet\0scc\0sound\0via1\0nmi\0clock\0 " 96 #define AV_INAMES \ 97 "spur\0via1\0via2\0ethernet\0scc\0dsp\0unused1\0nmi\0clock\0 " 98 99 void 100 intr_init(void) 101 { 102 extern char intrnames[MAX_INAME_LENGTH]; 103 extern char eintrnames[] __diagused; 104 const char *inames; 105 106 ipl2psl_table[IPL_NONE] = 0; 107 ipl2psl_table[IPL_SOFTCLOCK] = PSL_S|PSL_IPL1; 108 ipl2psl_table[IPL_SOFTNET] = PSL_S|PSL_IPL1; 109 ipl2psl_table[IPL_SOFTSERIAL] = PSL_S|PSL_IPL1; 110 ipl2psl_table[IPL_SOFTBIO] = PSL_S|PSL_IPL1; 111 ipl2psl_table[IPL_HIGH] = PSL_S|PSL_IPL7; 112 113 if (mac68k_machine.aux_interrupts) { 114 inames = AUX_INAMES; 115 116 /* Standard spl(9) interrupt priorities */ 117 ipl2psl_table[IPL_VM] = (PSL_S | PSL_IPL6); 118 ipl2psl_table[IPL_SCHED] = (PSL_S | PSL_IPL6); 119 } else { 120 inames = STD_INAMES; 121 122 /* Standard spl(9) interrupt priorities */ 123 ipl2psl_table[IPL_VM] = (PSL_S | PSL_IPL2); 124 ipl2psl_table[IPL_SCHED] = (PSL_S | PSL_IPL3); 125 126 if (current_mac_model->class == MACH_CLASSAV) { 127 inames = AV_INAMES; 128 ipl2psl_table[IPL_VM] = (PSL_S | PSL_IPL4); 129 ipl2psl_table[IPL_SCHED] = (PSL_S | PSL_IPL4); 130 } 131 } 132 133 KASSERT(MAX_INAME_LENGTH <= 134 ((uintptr_t)eintrnames - (uintptr_t)intrnames)); 135 memcpy(intrnames, inames, MAX_INAME_LENGTH); 136 137 intr_computeipl(); 138 139 /* Initialize the VIAs */ 140 via_init(); 141 142 /* Initialize the PSC (if present) */ 143 psc_init(); 144 } 145 146 147 /* 148 * Compute the interrupt levels for the spl*() 149 * calls. This doesn't have to be fast. 150 */ 151 void 152 intr_computeipl(void) 153 { 154 /* 155 * Enforce the following relationship, as defined in spl(9): 156 * `bio <= net <= tty <= vm <= statclock <= clock <= sched <= serial' 157 */ 158 if (ipl2psl_table[IPL_VM] > ipl2psl_table[IPL_SCHED]) 159 ipl2psl_table[IPL_SCHED] = ipl2psl_table[IPL_VM]; 160 161 if (ipl2psl_table[IPL_SCHED] > ipl2psl_table[IPL_HIGH]) 162 ipl2psl_table[IPL_HIGH] = ipl2psl_table[IPL_SCHED]; 163 } 164 165 /* 166 * Establish an autovectored interrupt handler. 167 * Called by driver attach functions. 168 * 169 * XXX Warning! DO NOT use Macintosh ROM traps from an interrupt handler 170 * established by this routine, either directly or indirectly, without 171 * properly saving and restoring all registers. If not, chaos _will_ 172 * ensue! (sar 19980806) 173 */ 174 void 175 intr_establish(int (*func)(void *), void *arg, int ipl) 176 { 177 if ((ipl < 0) || (ipl >= NISR)) 178 panic("intr_establish: bad ipl %d", ipl); 179 180 #ifdef DIAGNOSTIC 181 if (intr_func[ipl] != intr_noint) 182 printf("intr_establish: attempt to share ipl %d\n", ipl); 183 #endif 184 185 intr_func[ipl] = func; 186 intr_arg[ipl] = arg; 187 } 188 189 /* 190 * Disestablish an interrupt handler. 191 */ 192 void 193 intr_disestablish(int ipl) 194 { 195 if ((ipl < 0) || (ipl >= NISR)) 196 panic("intr_disestablish: bad ipl %d", ipl); 197 198 intr_func[ipl] = intr_noint; 199 intr_arg[ipl] = NULL; 200 } 201 202 /* 203 * This is the dispatcher called by the low-level 204 * assembly language interrupt routine. 205 * 206 * XXX Note: see the warning in intr_establish() 207 */ 208 void 209 intr_dispatch(struct clockframe frame) 210 { 211 const int ipl = VECO_TO_VECI(frame.cf_vo) - VECI_INTRAV0; 212 213 intrcnt[ipl]++; 214 curcpu()->ci_data.cpu_nintr++; 215 216 (void)(*intr_func[ipl])(intr_arg[ipl] ? intr_arg[ipl] : &frame); 217 } 218 219 /* 220 * Default interrupt handler: do nothing. 221 */ 222 static int 223 intr_noint(void *arg) 224 { 225 #ifdef DEBUG 226 if (intr_debug) { 227 const struct clockframe *frame = arg; 228 const int ipl = VECO_TO_VECI(frame->cf_vo) - VECI_INTRAV0; 229 printf("intr_noint: ipl %d\n", ipl); 230 } 231 #endif 232 return 0; 233 } 234