Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 3 | * Operating System Services (OSS) chip handling |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Written by Joshua M. Thompson (funaho@jurai.org) |
| 5 | * |
| 6 | * |
| 7 | * This chip is used in the IIfx in place of VIA #2. It acts like a fancy |
| 8 | * VIA chip with prorammable interrupt levels. |
| 9 | * |
| 10 | * 990502 (jmt) - Major rewrite for new interrupt architecture as well as some |
| 11 | * recent insights into OSS operational details. |
Simon Arlott | 0c79cf6 | 2007-10-20 01:20:32 +0200 | [diff] [blame] | 12 | * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * to mostly match the A/UX interrupt scheme supported on the |
| 14 | * VIA side. Also added support for enabling the ISM irq again |
| 15 | * since we now have a functional IOP manager. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/init.h> |
Geert Uytterhoeven | ddc7fd2 | 2011-07-13 21:48:30 +0200 | [diff] [blame] | 23 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/macintosh.h> |
| 26 | #include <asm/macints.h> |
| 27 | #include <asm/mac_via.h> |
| 28 | #include <asm/mac_oss.h> |
| 29 | |
| 30 | int oss_present; |
| 31 | volatile struct mac_oss *oss; |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | /* |
| 34 | * Initialize the OSS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | */ |
| 36 | |
| 37 | void __init oss_init(void) |
| 38 | { |
| 39 | int i; |
| 40 | |
Finn Thain | 7a0bb44 | 2017-10-26 22:45:24 -0400 | [diff] [blame] | 41 | if (macintosh_config->ident != MAC_MODEL_IIFX) |
| 42 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | oss = (struct mac_oss *) OSS_BASE; |
Finn Thain | 7a0bb44 | 2017-10-26 22:45:24 -0400 | [diff] [blame] | 45 | pr_debug("OSS detected at %p", oss); |
| 46 | oss_present = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | /* Disable all interrupts. Unlike a VIA it looks like we */ |
| 49 | /* do this by setting the source's interrupt level to zero. */ |
| 50 | |
Finn Thain | b24f670 | 2015-03-30 12:22:30 +1100 | [diff] [blame] | 51 | for (i = 0; i < OSS_NUM_SOURCES; i++) |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 52 | oss->irq_level[i] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 56 | * Handle miscellaneous OSS interrupts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | */ |
| 58 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 59 | static void oss_irq(struct irq_desc *desc) |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 60 | { |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 61 | int events = oss->irq_pending & |
Thomas Gleixner | 625b86a | 2015-07-31 21:56:10 +0200 | [diff] [blame] | 62 | (OSS_IP_IOPSCC | OSS_IP_SCSI | OSS_IP_IOPISM); |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 63 | |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 64 | if (events & OSS_IP_IOPSCC) { |
| 65 | oss->irq_pending &= ~OSS_IP_IOPSCC; |
| 66 | generic_handle_irq(IRQ_MAC_SCC); |
| 67 | } |
| 68 | |
| 69 | if (events & OSS_IP_SCSI) { |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 70 | oss->irq_pending &= ~OSS_IP_SCSI; |
| 71 | generic_handle_irq(IRQ_MAC_SCSI); |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | if (events & OSS_IP_IOPISM) { |
| 75 | oss->irq_pending &= ~OSS_IP_IOPISM; |
| 76 | generic_handle_irq(IRQ_MAC_ADB); |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 77 | } |
| 78 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Nubus IRQ handler, OSS style |
| 82 | * |
| 83 | * Unlike the VIA/RBV this is on its own autovector interrupt level. |
| 84 | */ |
| 85 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 86 | static void oss_nubus_irq(struct irq_desc *desc) |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 87 | { |
| 88 | int events, irq_bit, i; |
| 89 | |
| 90 | events = oss->irq_pending & OSS_IP_NUBUS; |
| 91 | if (!events) |
| 92 | return; |
| 93 | |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 94 | /* There are only six slots on the OSS, not seven */ |
| 95 | |
| 96 | i = 6; |
| 97 | irq_bit = 0x40; |
| 98 | do { |
| 99 | --i; |
| 100 | irq_bit >>= 1; |
| 101 | if (events & irq_bit) { |
| 102 | oss->irq_pending &= ~irq_bit; |
| 103 | generic_handle_irq(NUBUS_SOURCE_BASE + i); |
| 104 | } |
| 105 | } while(events & (irq_bit - 1)); |
| 106 | } |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * Register the OSS and NuBus interrupt dispatchers. |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 110 | * |
| 111 | * This IRQ mapping is laid out with two things in mind: first, we try to keep |
| 112 | * things on their own levels to avoid having to do double-dispatches. Second, |
| 113 | * the levels match as closely as possible the alternate IRQ mapping mode (aka |
| 114 | * "A/UX mode") available on some VIA machines. |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 115 | */ |
| 116 | |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 117 | #define OSS_IRQLEV_IOPISM IRQ_AUTO_1 |
| 118 | #define OSS_IRQLEV_SCSI IRQ_AUTO_2 |
| 119 | #define OSS_IRQLEV_NUBUS IRQ_AUTO_3 |
| 120 | #define OSS_IRQLEV_IOPSCC IRQ_AUTO_4 |
| 121 | #define OSS_IRQLEV_VIA1 IRQ_AUTO_6 |
| 122 | |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 123 | void __init oss_register_interrupts(void) |
| 124 | { |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 125 | irq_set_chained_handler(OSS_IRQLEV_IOPISM, oss_irq); |
| 126 | irq_set_chained_handler(OSS_IRQLEV_SCSI, oss_irq); |
| 127 | irq_set_chained_handler(OSS_IRQLEV_NUBUS, oss_nubus_irq); |
| 128 | irq_set_chained_handler(OSS_IRQLEV_IOPSCC, oss_irq); |
| 129 | irq_set_chained_handler(OSS_IRQLEV_VIA1, via1_irq); |
| 130 | |
| 131 | /* OSS_VIA1 gets enabled here because it has no machspec interrupt. */ |
| 132 | oss->irq_level[OSS_VIA1] = IRQ_AUTO_6; |
Geert Uytterhoeven | 9145db5 | 2011-08-10 12:48:29 +0200 | [diff] [blame] | 133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Enable an OSS interrupt |
| 137 | * |
| 138 | * It looks messy but it's rather straightforward. The switch() statement |
| 139 | * just maps the machspec interrupt numbers to the right OSS interrupt |
| 140 | * source (if the OSS handles that interrupt) and then sets the interrupt |
| 141 | * level for that source to nonzero, thus enabling the interrupt. |
| 142 | */ |
| 143 | |
| 144 | void oss_irq_enable(int irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | switch(irq) { |
Finn Thain | 80614e5 | 2009-11-17 20:06:48 +1100 | [diff] [blame] | 146 | case IRQ_MAC_SCC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC; |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 148 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | case IRQ_MAC_ADB: |
| 150 | oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM; |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 151 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | case IRQ_MAC_SCSI: |
| 153 | oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI; |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 154 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | case IRQ_NUBUS_9: |
| 156 | case IRQ_NUBUS_A: |
| 157 | case IRQ_NUBUS_B: |
| 158 | case IRQ_NUBUS_C: |
| 159 | case IRQ_NUBUS_D: |
| 160 | case IRQ_NUBUS_E: |
| 161 | irq -= NUBUS_SOURCE_BASE; |
| 162 | oss->irq_level[irq] = OSS_IRQLEV_NUBUS; |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 163 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 165 | |
| 166 | if (IRQ_SRC(irq) == 1) |
| 167 | via_irq_enable(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Disable an OSS interrupt |
| 172 | * |
| 173 | * Same as above except we set the source's interrupt level to zero, |
| 174 | * to disable the interrupt. |
| 175 | */ |
| 176 | |
| 177 | void oss_irq_disable(int irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | switch(irq) { |
Finn Thain | 80614e5 | 2009-11-17 20:06:48 +1100 | [diff] [blame] | 179 | case IRQ_MAC_SCC: |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 180 | oss->irq_level[OSS_IOPSCC] = 0; |
| 181 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | case IRQ_MAC_ADB: |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 183 | oss->irq_level[OSS_IOPISM] = 0; |
| 184 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | case IRQ_MAC_SCSI: |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 186 | oss->irq_level[OSS_SCSI] = 0; |
| 187 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | case IRQ_NUBUS_9: |
| 189 | case IRQ_NUBUS_A: |
| 190 | case IRQ_NUBUS_B: |
| 191 | case IRQ_NUBUS_C: |
| 192 | case IRQ_NUBUS_D: |
| 193 | case IRQ_NUBUS_E: |
| 194 | irq -= NUBUS_SOURCE_BASE; |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 195 | oss->irq_level[irq] = 0; |
| 196 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
Finn Thain | da3fb3c | 2011-10-24 01:11:18 +1100 | [diff] [blame] | 198 | |
| 199 | if (IRQ_SRC(irq) == 1) |
| 200 | via_irq_disable(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |