]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * OSS handling | |
3 | * Written by Joshua M. Thompson (funaho@jurai.org) | |
4 | * | |
5 | * | |
6 | * This chip is used in the IIfx in place of VIA #2. It acts like a fancy | |
7 | * VIA chip with prorammable interrupt levels. | |
8 | * | |
9 | * 990502 (jmt) - Major rewrite for new interrupt architecture as well as some | |
10 | * recent insights into OSS operational details. | |
0c79cf6a | 11 | * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped |
1da177e4 LT |
12 | * to mostly match the A/UX interrupt scheme supported on the |
13 | * VIA side. Also added support for enabling the ISM irq again | |
14 | * since we now have a functional IOP manager. | |
15 | */ | |
16 | ||
17 | #include <linux/types.h> | |
18 | #include <linux/kernel.h> | |
19 | #include <linux/mm.h> | |
20 | #include <linux/delay.h> | |
21 | #include <linux/init.h> | |
22 | ||
23 | #include <asm/bootinfo.h> | |
1da177e4 LT |
24 | #include <asm/macintosh.h> |
25 | #include <asm/macints.h> | |
26 | #include <asm/mac_via.h> | |
27 | #include <asm/mac_oss.h> | |
28 | ||
29 | int oss_present; | |
30 | volatile struct mac_oss *oss; | |
31 | ||
8dfbdf4a AB |
32 | static irqreturn_t oss_irq(int, void *); |
33 | static irqreturn_t oss_nubus_irq(int, void *); | |
1da177e4 | 34 | |
2850bc27 AV |
35 | extern irqreturn_t via1_irq(int, void *); |
36 | extern irqreturn_t mac_scc_dispatch(int, void *); | |
1da177e4 LT |
37 | |
38 | /* | |
39 | * Initialize the OSS | |
40 | * | |
41 | * The OSS "detection" code is actually in via_init() which is always called | |
42 | * before us. Thus we can count on oss_present being valid on entry. | |
43 | */ | |
44 | ||
45 | void __init oss_init(void) | |
46 | { | |
47 | int i; | |
48 | ||
49 | if (!oss_present) return; | |
50 | ||
51 | oss = (struct mac_oss *) OSS_BASE; | |
52 | ||
53 | /* Disable all interrupts. Unlike a VIA it looks like we */ | |
54 | /* do this by setting the source's interrupt level to zero. */ | |
55 | ||
56 | for (i = 0; i <= OSS_NUM_SOURCES; i++) { | |
57 | oss->irq_level[i] = OSS_IRQLEV_DISABLED; | |
58 | } | |
59 | /* If we disable VIA1 here, we never really handle it... */ | |
60 | oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1; | |
61 | } | |
62 | ||
63 | /* | |
64 | * Register the OSS and NuBus interrupt dispatchers. | |
65 | */ | |
66 | ||
67 | void __init oss_register_interrupts(void) | |
68 | { | |
92c3dd15 GU |
69 | if (request_irq(OSS_IRQLEV_SCSI, oss_irq, IRQ_FLG_LOCK, |
70 | "scsi", (void *) oss)) | |
71 | pr_err("Couldn't register %s interrupt\n", "scsi"); | |
72 | if (request_irq(OSS_IRQLEV_IOPSCC, mac_scc_dispatch, IRQ_FLG_LOCK, | |
73 | "scc", mac_scc_dispatch)) | |
74 | pr_err("Couldn't register %s interrupt\n", "scc"); | |
75 | if (request_irq(OSS_IRQLEV_NUBUS, oss_nubus_irq, IRQ_FLG_LOCK, | |
76 | "nubus", (void *) oss)) | |
77 | pr_err("Couldn't register %s interrupt\n", "nubus"); | |
78 | if (request_irq(OSS_IRQLEV_SOUND, oss_irq, IRQ_FLG_LOCK, | |
79 | "sound", (void *) oss)) | |
80 | pr_err("Couldn't register %s interrupt\n", "sound"); | |
81 | if (request_irq(OSS_IRQLEV_VIA1, via1_irq, IRQ_FLG_LOCK, | |
82 | "via1", (void *) via1)) | |
83 | pr_err("Couldn't register %s interrupt\n", "via1"); | |
1da177e4 LT |
84 | } |
85 | ||
86 | /* | |
87 | * Initialize OSS for Nubus access | |
88 | */ | |
89 | ||
90 | void __init oss_nubus_init(void) | |
91 | { | |
92 | } | |
93 | ||
94 | /* | |
95 | * Handle miscellaneous OSS interrupts. Right now that's just sound | |
96 | * and SCSI; everything else is routed to its own autovector IRQ. | |
97 | */ | |
98 | ||
8dfbdf4a | 99 | static irqreturn_t oss_irq(int irq, void *dev_id) |
1da177e4 LT |
100 | { |
101 | int events; | |
102 | ||
103 | events = oss->irq_pending & (OSS_IP_SOUND|OSS_IP_SCSI); | |
104 | if (!events) | |
105 | return IRQ_NONE; | |
106 | ||
107 | #ifdef DEBUG_IRQS | |
108 | if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) { | |
109 | printk("oss_irq: irq %d events = 0x%04X\n", irq, | |
110 | (int) oss->irq_pending); | |
111 | } | |
112 | #endif | |
113 | /* FIXME: how do you clear a pending IRQ? */ | |
114 | ||
115 | if (events & OSS_IP_SOUND) { | |
1da177e4 | 116 | oss->irq_pending &= ~OSS_IP_SOUND; |
647b804c | 117 | /* FIXME: call sound handler */ |
1da177e4 | 118 | } else if (events & OSS_IP_SCSI) { |
1da177e4 | 119 | oss->irq_pending &= ~OSS_IP_SCSI; |
647b804c | 120 | m68k_handle_int(IRQ_MAC_SCSI); |
1da177e4 LT |
121 | } else { |
122 | /* FIXME: error check here? */ | |
123 | } | |
124 | return IRQ_HANDLED; | |
125 | } | |
126 | ||
127 | /* | |
128 | * Nubus IRQ handler, OSS style | |
129 | * | |
130 | * Unlike the VIA/RBV this is on its own autovector interrupt level. | |
131 | */ | |
132 | ||
8dfbdf4a | 133 | static irqreturn_t oss_nubus_irq(int irq, void *dev_id) |
1da177e4 LT |
134 | { |
135 | int events, irq_bit, i; | |
136 | ||
137 | events = oss->irq_pending & OSS_IP_NUBUS; | |
138 | if (!events) | |
139 | return IRQ_NONE; | |
140 | ||
141 | #ifdef DEBUG_NUBUS_INT | |
142 | if (console_loglevel > 7) { | |
143 | printk("oss_nubus_irq: events = 0x%04X\n", events); | |
144 | } | |
145 | #endif | |
146 | /* There are only six slots on the OSS, not seven */ | |
147 | ||
67dfb153 FT |
148 | i = 6; |
149 | irq_bit = 0x40; | |
150 | do { | |
151 | --i; | |
152 | irq_bit >>= 1; | |
1da177e4 | 153 | if (events & irq_bit) { |
1da177e4 | 154 | oss->irq_pending &= ~irq_bit; |
647b804c | 155 | m68k_handle_int(NUBUS_SOURCE_BASE + i); |
1da177e4 | 156 | } |
67dfb153 | 157 | } while(events & (irq_bit - 1)); |
1da177e4 LT |
158 | return IRQ_HANDLED; |
159 | } | |
160 | ||
161 | /* | |
162 | * Enable an OSS interrupt | |
163 | * | |
164 | * It looks messy but it's rather straightforward. The switch() statement | |
165 | * just maps the machspec interrupt numbers to the right OSS interrupt | |
166 | * source (if the OSS handles that interrupt) and then sets the interrupt | |
167 | * level for that source to nonzero, thus enabling the interrupt. | |
168 | */ | |
169 | ||
170 | void oss_irq_enable(int irq) { | |
171 | #ifdef DEBUG_IRQUSE | |
172 | printk("oss_irq_enable(%d)\n", irq); | |
173 | #endif | |
174 | switch(irq) { | |
175 | case IRQ_SCC: | |
176 | case IRQ_SCCA: | |
177 | case IRQ_SCCB: | |
178 | oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC; | |
179 | break; | |
180 | case IRQ_MAC_ADB: | |
181 | oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM; | |
182 | break; | |
183 | case IRQ_MAC_SCSI: | |
184 | oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI; | |
185 | break; | |
186 | case IRQ_NUBUS_9: | |
187 | case IRQ_NUBUS_A: | |
188 | case IRQ_NUBUS_B: | |
189 | case IRQ_NUBUS_C: | |
190 | case IRQ_NUBUS_D: | |
191 | case IRQ_NUBUS_E: | |
192 | irq -= NUBUS_SOURCE_BASE; | |
193 | oss->irq_level[irq] = OSS_IRQLEV_NUBUS; | |
194 | break; | |
195 | #ifdef DEBUG_IRQUSE | |
196 | default: | |
f85e7cdc | 197 | printk("%s unknown irq %d\n", __func__, irq); |
1da177e4 LT |
198 | break; |
199 | #endif | |
200 | } | |
201 | } | |
202 | ||
203 | /* | |
204 | * Disable an OSS interrupt | |
205 | * | |
206 | * Same as above except we set the source's interrupt level to zero, | |
207 | * to disable the interrupt. | |
208 | */ | |
209 | ||
210 | void oss_irq_disable(int irq) { | |
211 | #ifdef DEBUG_IRQUSE | |
212 | printk("oss_irq_disable(%d)\n", irq); | |
213 | #endif | |
214 | switch(irq) { | |
215 | case IRQ_SCC: | |
216 | case IRQ_SCCA: | |
217 | case IRQ_SCCB: | |
218 | oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_DISABLED; | |
219 | break; | |
220 | case IRQ_MAC_ADB: | |
221 | oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_DISABLED; | |
222 | break; | |
223 | case IRQ_MAC_SCSI: | |
224 | oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED; | |
225 | break; | |
226 | case IRQ_NUBUS_9: | |
227 | case IRQ_NUBUS_A: | |
228 | case IRQ_NUBUS_B: | |
229 | case IRQ_NUBUS_C: | |
230 | case IRQ_NUBUS_D: | |
231 | case IRQ_NUBUS_E: | |
232 | irq -= NUBUS_SOURCE_BASE; | |
233 | oss->irq_level[irq] = OSS_IRQLEV_DISABLED; | |
234 | break; | |
235 | #ifdef DEBUG_IRQUSE | |
236 | default: | |
f85e7cdc | 237 | printk("%s unknown irq %d\n", __func__, irq); |
1da177e4 LT |
238 | break; |
239 | #endif | |
240 | } | |
241 | } | |
242 | ||
243 | /* | |
244 | * Clear an OSS interrupt | |
245 | * | |
246 | * Not sure if this works or not but it's the only method I could | |
247 | * think of based on the contents of the mac_oss structure. | |
248 | */ | |
249 | ||
250 | void oss_irq_clear(int irq) { | |
251 | /* FIXME: how to do this on OSS? */ | |
252 | switch(irq) { | |
253 | case IRQ_SCC: | |
254 | case IRQ_SCCA: | |
255 | case IRQ_SCCB: | |
256 | oss->irq_pending &= ~OSS_IP_IOPSCC; | |
257 | break; | |
258 | case IRQ_MAC_ADB: | |
259 | oss->irq_pending &= ~OSS_IP_IOPISM; | |
260 | break; | |
261 | case IRQ_MAC_SCSI: | |
262 | oss->irq_pending &= ~OSS_IP_SCSI; | |
263 | break; | |
264 | case IRQ_NUBUS_9: | |
265 | case IRQ_NUBUS_A: | |
266 | case IRQ_NUBUS_B: | |
267 | case IRQ_NUBUS_C: | |
268 | case IRQ_NUBUS_D: | |
269 | case IRQ_NUBUS_E: | |
270 | irq -= NUBUS_SOURCE_BASE; | |
271 | oss->irq_pending &= ~(1 << irq); | |
272 | break; | |
273 | } | |
274 | } | |
275 | ||
276 | /* | |
277 | * Check to see if a specific OSS interrupt is pending | |
278 | */ | |
279 | ||
280 | int oss_irq_pending(int irq) | |
281 | { | |
282 | switch(irq) { | |
283 | case IRQ_SCC: | |
284 | case IRQ_SCCA: | |
285 | case IRQ_SCCB: | |
286 | return oss->irq_pending & OSS_IP_IOPSCC; | |
287 | break; | |
288 | case IRQ_MAC_ADB: | |
289 | return oss->irq_pending & OSS_IP_IOPISM; | |
290 | break; | |
291 | case IRQ_MAC_SCSI: | |
292 | return oss->irq_pending & OSS_IP_SCSI; | |
293 | break; | |
294 | case IRQ_NUBUS_9: | |
295 | case IRQ_NUBUS_A: | |
296 | case IRQ_NUBUS_B: | |
297 | case IRQ_NUBUS_C: | |
298 | case IRQ_NUBUS_D: | |
299 | case IRQ_NUBUS_E: | |
300 | irq -= NUBUS_SOURCE_BASE; | |
301 | return oss->irq_pending & (1 << irq); | |
302 | break; | |
303 | } | |
304 | return 0; | |
305 | } |