3 * Written by Joshua M. Thompson (funaho@jurai.org)
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.
9 * 990502 (jmt) - Major rewrite for new interrupt architecture as well as some
10 * recent insights into OSS operational details.
11 * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped
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.
17 #include <linux/types.h>
18 #include <linux/kernel.h>
20 #include <linux/delay.h>
21 #include <linux/init.h>
23 #include <asm/bootinfo.h>
24 #include <asm/machw.h>
25 #include <asm/macintosh.h>
26 #include <asm/macints.h>
27 #include <asm/mac_via.h>
28 #include <asm/mac_oss.h>
31 volatile struct mac_oss *oss;
33 irqreturn_t oss_irq(int, void *);
34 irqreturn_t oss_nubus_irq(int, void *);
36 extern irqreturn_t via1_irq(int, void *);
37 extern irqreturn_t mac_scc_dispatch(int, void *);
42 * The OSS "detection" code is actually in via_init() which is always called
43 * before us. Thus we can count on oss_present being valid on entry.
46 void __init oss_init(void)
50 if (!oss_present) return;
52 oss = (struct mac_oss *) OSS_BASE;
54 /* Disable all interrupts. Unlike a VIA it looks like we */
55 /* do this by setting the source's interrupt level to zero. */
57 for (i = 0; i <= OSS_NUM_SOURCES; i++) {
58 oss->irq_level[i] = OSS_IRQLEV_DISABLED;
60 /* If we disable VIA1 here, we never really handle it... */
61 oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
65 * Register the OSS and NuBus interrupt dispatchers.
68 void __init oss_register_interrupts(void)
70 request_irq(OSS_IRQLEV_SCSI, oss_irq, IRQ_FLG_LOCK,
71 "scsi", (void *) oss);
72 request_irq(OSS_IRQLEV_IOPSCC, mac_scc_dispatch, IRQ_FLG_LOCK,
73 "scc", mac_scc_dispatch);
74 request_irq(OSS_IRQLEV_NUBUS, oss_nubus_irq, IRQ_FLG_LOCK,
75 "nubus", (void *) oss);
76 request_irq(OSS_IRQLEV_SOUND, oss_irq, IRQ_FLG_LOCK,
77 "sound", (void *) oss);
78 request_irq(OSS_IRQLEV_VIA1, via1_irq, IRQ_FLG_LOCK,
79 "via1", (void *) via1);
83 * Initialize OSS for Nubus access
86 void __init oss_nubus_init(void)
91 * Handle miscellaneous OSS interrupts. Right now that's just sound
92 * and SCSI; everything else is routed to its own autovector IRQ.
95 irqreturn_t oss_irq(int irq, void *dev_id)
99 events = oss->irq_pending & (OSS_IP_SOUND|OSS_IP_SCSI);
104 if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
105 printk("oss_irq: irq %d events = 0x%04X\n", irq,
106 (int) oss->irq_pending);
109 /* FIXME: how do you clear a pending IRQ? */
111 if (events & OSS_IP_SOUND) {
112 oss->irq_pending &= ~OSS_IP_SOUND;
113 /* FIXME: call sound handler */
114 } else if (events & OSS_IP_SCSI) {
115 oss->irq_pending &= ~OSS_IP_SCSI;
116 m68k_handle_int(IRQ_MAC_SCSI);
118 /* FIXME: error check here? */
124 * Nubus IRQ handler, OSS style
126 * Unlike the VIA/RBV this is on its own autovector interrupt level.
129 irqreturn_t oss_nubus_irq(int irq, void *dev_id)
131 int events, irq_bit, i;
133 events = oss->irq_pending & OSS_IP_NUBUS;
137 #ifdef DEBUG_NUBUS_INT
138 if (console_loglevel > 7) {
139 printk("oss_nubus_irq: events = 0x%04X\n", events);
142 /* There are only six slots on the OSS, not seven */
149 if (events & irq_bit) {
150 oss->irq_pending &= ~irq_bit;
151 m68k_handle_int(NUBUS_SOURCE_BASE + i);
153 } while(events & (irq_bit - 1));
158 * Enable an OSS interrupt
160 * It looks messy but it's rather straightforward. The switch() statement
161 * just maps the machspec interrupt numbers to the right OSS interrupt
162 * source (if the OSS handles that interrupt) and then sets the interrupt
163 * level for that source to nonzero, thus enabling the interrupt.
166 void oss_irq_enable(int irq) {
168 printk("oss_irq_enable(%d)\n", irq);
174 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
177 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
180 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
188 irq -= NUBUS_SOURCE_BASE;
189 oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
193 printk("%s unknown irq %d\n", __func__, irq);
200 * Disable an OSS interrupt
202 * Same as above except we set the source's interrupt level to zero,
203 * to disable the interrupt.
206 void oss_irq_disable(int irq) {
208 printk("oss_irq_disable(%d)\n", irq);
214 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_DISABLED;
217 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_DISABLED;
220 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED;
228 irq -= NUBUS_SOURCE_BASE;
229 oss->irq_level[irq] = OSS_IRQLEV_DISABLED;
233 printk("%s unknown irq %d\n", __func__, irq);
240 * Clear an OSS interrupt
242 * Not sure if this works or not but it's the only method I could
243 * think of based on the contents of the mac_oss structure.
246 void oss_irq_clear(int irq) {
247 /* FIXME: how to do this on OSS? */
252 oss->irq_pending &= ~OSS_IP_IOPSCC;
255 oss->irq_pending &= ~OSS_IP_IOPISM;
258 oss->irq_pending &= ~OSS_IP_SCSI;
266 irq -= NUBUS_SOURCE_BASE;
267 oss->irq_pending &= ~(1 << irq);
273 * Check to see if a specific OSS interrupt is pending
276 int oss_irq_pending(int irq)
282 return oss->irq_pending & OSS_IP_IOPSCC;
285 return oss->irq_pending & OSS_IP_IOPISM;
288 return oss->irq_pending & OSS_IP_SCSI;
296 irq -= NUBUS_SOURCE_BASE;
297 return oss->irq_pending & (1 << irq);