Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Macintosh interrupts |
| 3 | * |
| 4 | * General design: |
| 5 | * In contrary to the Amiga and Atari platforms, the Mac hardware seems to |
| 6 | * exclusively use the autovector interrupts (the 'generic level0-level7' |
| 7 | * interrupts with exception vectors 0x19-0x1f). The following interrupt levels |
| 8 | * are used: |
| 9 | * 1 - VIA1 |
| 10 | * - slot 0: one second interrupt (CA2) |
| 11 | * - slot 1: VBlank (CA1) |
| 12 | * - slot 2: ADB data ready (SR full) |
| 13 | * - slot 3: ADB data (CB2) |
| 14 | * - slot 4: ADB clock (CB1) |
| 15 | * - slot 5: timer 2 |
| 16 | * - slot 6: timer 1 |
| 17 | * - slot 7: status of IRQ; signals 'any enabled int.' |
| 18 | * |
| 19 | * 2 - VIA2 or RBV |
| 20 | * - slot 0: SCSI DRQ (CA2) |
| 21 | * - slot 1: NUBUS IRQ (CA1) need to read port A to find which |
| 22 | * - slot 2: /EXP IRQ (only on IIci) |
| 23 | * - slot 3: SCSI IRQ (CB2) |
| 24 | * - slot 4: ASC IRQ (CB1) |
| 25 | * - slot 5: timer 2 (not on IIci) |
| 26 | * - slot 6: timer 1 (not on IIci) |
| 27 | * - slot 7: status of IRQ; signals 'any enabled int.' |
| 28 | * |
| 29 | * 2 - OSS (IIfx only?) |
| 30 | * - slot 0: SCSI interrupt |
| 31 | * - slot 1: Sound interrupt |
| 32 | * |
| 33 | * Levels 3-6 vary by machine type. For VIA or RBV Macintoshes: |
| 34 | * |
| 35 | * 3 - unused (?) |
| 36 | * |
Finn Thain | 80614e5 | 2009-11-17 20:06:48 +1100 | [diff] [blame] | 37 | * 4 - SCC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | * |
| 39 | * 5 - unused (?) |
| 40 | * [serial errors or special conditions seem to raise level 6 |
| 41 | * interrupts on some models (LC4xx?)] |
| 42 | * |
| 43 | * 6 - off switch (?) |
| 44 | * |
Finn Thain | 8d9f014 | 2011-10-24 01:11:16 +1100 | [diff] [blame] | 45 | * Machines with Quadra-like VIA hardware, except PSC and PMU machines, support |
| 46 | * an alternate interrupt mapping, as used by A/UX. It spreads ethernet and |
| 47 | * sound out to their own autovector IRQs and gives VIA1 a higher priority: |
| 48 | * |
| 49 | * 1 - unused (?) |
| 50 | * |
| 51 | * 3 - on-board SONIC |
| 52 | * |
| 53 | * 5 - Apple Sound Chip (ASC) |
| 54 | * |
| 55 | * 6 - VIA1 |
| 56 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * For OSS Macintoshes (IIfx only at this point): |
| 58 | * |
| 59 | * 3 - Nubus interrupt |
| 60 | * - slot 0: Slot $9 |
| 61 | * - slot 1: Slot $A |
| 62 | * - slot 2: Slot $B |
| 63 | * - slot 3: Slot $C |
| 64 | * - slot 4: Slot $D |
| 65 | * - slot 5: Slot $E |
| 66 | * |
| 67 | * 4 - SCC IOP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * |
| 69 | * 5 - ISM IOP (ADB?) |
| 70 | * |
| 71 | * 6 - unused |
| 72 | * |
| 73 | * For PSC Macintoshes (660AV, 840AV): |
| 74 | * |
| 75 | * 3 - PSC level 3 |
| 76 | * - slot 0: MACE |
| 77 | * |
| 78 | * 4 - PSC level 4 |
| 79 | * - slot 1: SCC channel A interrupt |
| 80 | * - slot 2: SCC channel B interrupt |
| 81 | * - slot 3: MACE DMA |
| 82 | * |
| 83 | * 5 - PSC level 5 |
| 84 | * |
| 85 | * 6 - PSC level 6 |
| 86 | * |
| 87 | * Finally we have good 'ole level 7, the non-maskable interrupt: |
| 88 | * |
| 89 | * 7 - NMI (programmer's switch on the back of some Macs) |
| 90 | * Also RAM parity error on models which support it (IIc, IIfx?) |
| 91 | * |
| 92 | * The current interrupt logic looks something like this: |
| 93 | * |
| 94 | * - We install dispatchers for the autovector interrupts (1-7). These |
| 95 | * dispatchers are responsible for querying the hardware (the |
| 96 | * VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using |
| 97 | * this information a machspec interrupt number is generated by placing the |
| 98 | * index of the interrupt hardware into the low three bits and the original |
| 99 | * autovector interrupt number in the upper 5 bits. The handlers for the |
| 100 | * resulting machspec interrupt are then called. |
| 101 | * |
| 102 | * - Nubus is a special case because its interrupts are hidden behind two |
| 103 | * layers of hardware. Nubus interrupts come in as index 1 on VIA #2, |
| 104 | * which translates to IRQ number 17. In this spot we install _another_ |
| 105 | * dispatcher. This dispatcher finds the interrupting slot number (9-F) and |
| 106 | * then forms a new machspec interrupt number as above with the slot number |
| 107 | * minus 9 in the low three bits and the pseudo-level 7 in the upper five |
| 108 | * bits. The handlers for this new machspec interrupt number are then |
| 109 | * called. This puts Nubus interrupts into the range 56-62. |
| 110 | * |
| 111 | * - The Baboon interrupts (used on some PowerBooks) are an even more special |
| 112 | * case. They're hidden behind the Nubus slot $C interrupt thus adding a |
| 113 | * third layer of indirection. Why oh why did the Apple engineers do that? |
| 114 | * |
| 115 | * - We support "fast" and "slow" handlers, just like the Amiga port. The |
| 116 | * fast handlers are called first and with all interrupts disabled. They |
| 117 | * are expected to execute quickly (hence the name). The slow handlers are |
| 118 | * called last with interrupts enabled and the interrupt level restored. |
| 119 | * They must therefore be reentrant. |
| 120 | * |
| 121 | * TODO: |
| 122 | * |
| 123 | */ |
| 124 | |
| 125 | #include <linux/types.h> |
| 126 | #include <linux/kernel.h> |
| 127 | #include <linux/sched.h> |
Finn Thain | ed04c97 | 2011-10-24 01:11:15 +1100 | [diff] [blame] | 128 | #include <linux/interrupt.h> |
| 129 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #include <asm/macintosh.h> |
Finn Thain | ed04c97 | 2011-10-24 01:11:15 +1100 | [diff] [blame] | 134 | #include <asm/macints.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | #include <asm/mac_via.h> |
| 136 | #include <asm/mac_psc.h> |
Geert Uytterhoeven | c85627f | 2008-12-21 12:03:37 +0100 | [diff] [blame] | 137 | #include <asm/mac_oss.h> |
Finn Thain | ed04c97 | 2011-10-24 01:11:15 +1100 | [diff] [blame] | 138 | #include <asm/mac_iop.h> |
| 139 | #include <asm/mac_baboon.h> |
| 140 | #include <asm/hwtest.h> |
| 141 | #include <asm/irq_regs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | #define SHUTUP_SONIC |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | * console_loglevel determines NMI handler function |
| 147 | */ |
| 148 | |
Al Viro | 2850bc2 | 2006-10-07 14:16:45 +0100 | [diff] [blame] | 149 | irqreturn_t mac_nmi_handler(int, void *); |
| 150 | irqreturn_t mac_debug_handler(int, void *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* #define DEBUG_MACINTS */ |
| 153 | |
Finn Thain | c4af5da | 2011-10-24 01:11:17 +1100 | [diff] [blame^] | 154 | static unsigned int mac_irq_startup(struct irq_data *); |
| 155 | static void mac_irq_shutdown(struct irq_data *); |
| 156 | |
Geert Uytterhoeven | c288bf2 | 2011-04-13 22:31:28 +0200 | [diff] [blame] | 157 | static struct irq_chip mac_irq_chip = { |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 158 | .name = "mac", |
Geert Uytterhoeven | e8abf5e | 2011-04-17 22:53:04 +0200 | [diff] [blame] | 159 | .irq_enable = mac_irq_enable, |
| 160 | .irq_disable = mac_irq_disable, |
Finn Thain | c4af5da | 2011-10-24 01:11:17 +1100 | [diff] [blame^] | 161 | .irq_startup = mac_irq_startup, |
| 162 | .irq_shutdown = mac_irq_shutdown, |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 163 | }; |
| 164 | |
Al Viro | 66a3f82 | 2007-07-20 04:33:28 +0100 | [diff] [blame] | 165 | void __init mac_init_IRQ(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | #ifdef DEBUG_MACINTS |
| 168 | printk("mac_init_IRQ(): Setting things up...\n"); |
| 169 | #endif |
Geert Uytterhoeven | edb3472 | 2011-06-01 11:15:21 +0200 | [diff] [blame] | 170 | m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER, |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 171 | NUM_MAC_SOURCES - IRQ_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* Make sure the SONIC interrupt is cleared or things get ugly */ |
| 173 | #ifdef SHUTUP_SONIC |
| 174 | printk("Killing onboard sonic... "); |
| 175 | /* This address should hopefully be mapped already */ |
| 176 | if (hwreg_present((void*)(0x50f0a000))) { |
| 177 | *(long *)(0x50f0a014) = 0x7fffL; |
| 178 | *(long *)(0x50f0a010) = 0L; |
| 179 | } |
| 180 | printk("Done.\n"); |
| 181 | #endif /* SHUTUP_SONIC */ |
| 182 | |
| 183 | /* |
| 184 | * Now register the handlers for the master IRQ handlers |
| 185 | * at levels 1-7. Most of the work is done elsewhere. |
| 186 | */ |
| 187 | |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 188 | if (oss_present) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | oss_register_interrupts(); |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 190 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | via_register_interrupts(); |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 192 | if (psc_present) |
| 193 | psc_register_interrupts(); |
| 194 | if (baboon_present) |
| 195 | baboon_register_interrupts(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | iop_register_interrupts(); |
Geert Uytterhoeven | 92c3dd1 | 2008-12-30 14:02:27 +0100 | [diff] [blame] | 197 | if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI", |
| 198 | mac_nmi_handler)) |
| 199 | pr_err("Couldn't register NMI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | #ifdef DEBUG_MACINTS |
| 201 | printk("mac_init_IRQ(): Done!\n"); |
| 202 | #endif |
| 203 | } |
| 204 | |
| 205 | /* |
Finn Thain | 2690e21 | 2011-09-11 23:40:50 +1000 | [diff] [blame] | 206 | * mac_irq_enable - enable an interrupt source |
| 207 | * mac_irq_disable - disable an interrupt source |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | * |
| 209 | * These routines are just dispatchers to the VIA/OSS/PSC routines. |
| 210 | */ |
| 211 | |
Finn Thain | 2690e21 | 2011-09-11 23:40:50 +1000 | [diff] [blame] | 212 | void mac_irq_enable(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
Finn Thain | 2690e21 | 2011-09-11 23:40:50 +1000 | [diff] [blame] | 214 | int irq = data->irq; |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 215 | int irq_src = IRQ_SRC(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | switch(irq_src) { |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 218 | case 1: |
| 219 | via_irq_enable(irq); |
| 220 | break; |
| 221 | case 2: |
| 222 | case 7: |
| 223 | if (oss_present) |
| 224 | oss_irq_enable(irq); |
| 225 | else |
| 226 | via_irq_enable(irq); |
| 227 | break; |
| 228 | case 3: |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 229 | case 5: |
| 230 | case 6: |
| 231 | if (psc_present) |
| 232 | psc_irq_enable(irq); |
| 233 | else if (oss_present) |
| 234 | oss_irq_enable(irq); |
Finn Thain | 80614e5 | 2009-11-17 20:06:48 +1100 | [diff] [blame] | 235 | break; |
| 236 | case 4: |
| 237 | if (psc_present) |
| 238 | psc_irq_enable(irq); |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 239 | break; |
| 240 | case 8: |
| 241 | if (baboon_present) |
| 242 | baboon_irq_enable(irq); |
| 243 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Finn Thain | 2690e21 | 2011-09-11 23:40:50 +1000 | [diff] [blame] | 247 | void mac_irq_disable(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Finn Thain | 2690e21 | 2011-09-11 23:40:50 +1000 | [diff] [blame] | 249 | int irq = data->irq; |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 250 | int irq_src = IRQ_SRC(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | switch(irq_src) { |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 253 | case 1: |
| 254 | via_irq_disable(irq); |
| 255 | break; |
| 256 | case 2: |
| 257 | case 7: |
| 258 | if (oss_present) |
| 259 | oss_irq_disable(irq); |
| 260 | else |
| 261 | via_irq_disable(irq); |
| 262 | break; |
| 263 | case 3: |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 264 | case 5: |
| 265 | case 6: |
| 266 | if (psc_present) |
| 267 | psc_irq_disable(irq); |
| 268 | else if (oss_present) |
| 269 | oss_irq_disable(irq); |
Finn Thain | 80614e5 | 2009-11-17 20:06:48 +1100 | [diff] [blame] | 270 | break; |
| 271 | case 4: |
| 272 | if (psc_present) |
| 273 | psc_irq_disable(irq); |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 274 | break; |
| 275 | case 8: |
| 276 | if (baboon_present) |
| 277 | baboon_irq_disable(irq); |
| 278 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Finn Thain | c4af5da | 2011-10-24 01:11:17 +1100 | [diff] [blame^] | 282 | static unsigned int mac_irq_startup(struct irq_data *data) |
| 283 | { |
| 284 | int irq = data->irq; |
| 285 | |
| 286 | if (IRQ_SRC(irq) == 7 && !oss_present) |
| 287 | via_nubus_irq_startup(irq); |
| 288 | else |
| 289 | mac_irq_enable(data); |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static void mac_irq_shutdown(struct irq_data *data) |
| 295 | { |
| 296 | int irq = data->irq; |
| 297 | |
| 298 | if (IRQ_SRC(irq) == 7 && !oss_present) |
| 299 | via_nubus_irq_shutdown(irq); |
| 300 | else |
| 301 | mac_irq_disable(data); |
| 302 | } |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | static int num_debug[8]; |
| 305 | |
Al Viro | 2850bc2 | 2006-10-07 14:16:45 +0100 | [diff] [blame] | 306 | irqreturn_t mac_debug_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
| 308 | if (num_debug[irq] < 10) { |
| 309 | printk("DEBUG: Unexpected IRQ %d\n", irq); |
| 310 | num_debug[irq]++; |
| 311 | } |
| 312 | return IRQ_HANDLED; |
| 313 | } |
| 314 | |
| 315 | static int in_nmi; |
| 316 | static volatile int nmi_hold; |
| 317 | |
Al Viro | 2850bc2 | 2006-10-07 14:16:45 +0100 | [diff] [blame] | 318 | irqreturn_t mac_nmi_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
| 320 | int i; |
| 321 | /* |
| 322 | * generate debug output on NMI switch if 'debug' kernel option given |
| 323 | * (only works with Penguin!) |
| 324 | */ |
| 325 | |
| 326 | in_nmi++; |
| 327 | for (i=0; i<100; i++) |
| 328 | udelay(1000); |
| 329 | |
| 330 | if (in_nmi == 1) { |
| 331 | nmi_hold = 1; |
| 332 | printk("... pausing, press NMI to resume ..."); |
| 333 | } else { |
| 334 | printk(" ok!\n"); |
| 335 | nmi_hold = 0; |
| 336 | } |
| 337 | |
| 338 | barrier(); |
| 339 | |
| 340 | while (nmi_hold == 1) |
| 341 | udelay(1000); |
| 342 | |
Roman Zippel | 9c5f4af | 2006-06-25 05:47:04 -0700 | [diff] [blame] | 343 | if (console_loglevel >= 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | #if 0 |
Al Viro | 2850bc2 | 2006-10-07 14:16:45 +0100 | [diff] [blame] | 345 | struct pt_regs *fp = get_irq_regs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | show_state(); |
| 347 | printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp); |
| 348 | printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n", |
| 349 | fp->d0, fp->d1, fp->d2, fp->d3); |
| 350 | printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n", |
| 351 | fp->d4, fp->d5, fp->a0, fp->a1); |
| 352 | |
| 353 | if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page) |
| 354 | printk("Corrupted stack page\n"); |
| 355 | printk("Process %s (pid: %d, stackpage=%08lx)\n", |
| 356 | current->comm, current->pid, current->kernel_stack_page); |
| 357 | if (intr_count == 1) |
| 358 | dump_stack((struct frame *)fp); |
| 359 | #else |
| 360 | /* printk("NMI "); */ |
| 361 | #endif |
| 362 | } |
| 363 | in_nmi--; |
| 364 | return IRQ_HANDLED; |
| 365 | } |