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/macintosh.h>
25 #include <asm/macints.h>
26 #include <asm/mac_via.h>
27 #include <asm/mac_oss.h>
30 volatile struct mac_oss *oss;
32 static irqreturn_t oss_irq(int, void *);
33 static irqreturn_t oss_nubus_irq(int, void *);
35 extern irqreturn_t via1_irq(int, void *);
40 * The OSS "detection" code is actually in via_init() which is always called
41 * before us. Thus we can count on oss_present being valid on entry.
44 void __init oss_init(void)
48 if (!oss_present) return;
50 oss = (struct mac_oss *) OSS_BASE;
52 /* Disable all interrupts. Unlike a VIA it looks like we */
53 /* do this by setting the source's interrupt level to zero. */
55 for (i = 0; i <= OSS_NUM_SOURCES; i++) {
56 oss->irq_level[i] = OSS_IRQLEV_DISABLED;
58 /* If we disable VIA1 here, we never really handle it... */
59 oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
63 * Register the OSS and NuBus interrupt dispatchers.
66 void __init oss_register_interrupts(void)
68 if (request_irq(OSS_IRQLEV_SCSI, oss_irq, 0, "scsi", (void *)oss))
69 pr_err("Couldn't register %s interrupt\n", "scsi");
70 if (request_irq(OSS_IRQLEV_NUBUS, oss_nubus_irq, 0, "nubus",
72 pr_err("Couldn't register %s interrupt\n", "nubus");
73 if (request_irq(OSS_IRQLEV_SOUND, oss_irq, 0, "sound", (void *)oss))
74 pr_err("Couldn't register %s interrupt\n", "sound");
75 if (request_irq(OSS_IRQLEV_VIA1, via1_irq, 0, "via1", (void *)via1))
76 pr_err("Couldn't register %s interrupt\n", "via1");
80 * Initialize OSS for Nubus access
83 void __init oss_nubus_init(void)
88 * Handle miscellaneous OSS interrupts. Right now that's just sound
89 * and SCSI; everything else is routed to its own autovector IRQ.
92 static irqreturn_t oss_irq(int irq, void *dev_id)
96 events = oss->irq_pending & (OSS_IP_SOUND|OSS_IP_SCSI);
101 if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
102 printk("oss_irq: irq %d events = 0x%04X\n", irq,
103 (int) oss->irq_pending);
106 /* FIXME: how do you clear a pending IRQ? */
108 if (events & OSS_IP_SOUND) {
109 oss->irq_pending &= ~OSS_IP_SOUND;
110 /* FIXME: call sound handler */
111 } else if (events & OSS_IP_SCSI) {
112 oss->irq_pending &= ~OSS_IP_SCSI;
113 generic_handle_irq(IRQ_MAC_SCSI);
115 /* FIXME: error check here? */
121 * Nubus IRQ handler, OSS style
123 * Unlike the VIA/RBV this is on its own autovector interrupt level.
126 static irqreturn_t oss_nubus_irq(int irq, void *dev_id)
128 int events, irq_bit, i;
130 events = oss->irq_pending & OSS_IP_NUBUS;
134 #ifdef DEBUG_NUBUS_INT
135 if (console_loglevel > 7) {
136 printk("oss_nubus_irq: events = 0x%04X\n", events);
139 /* There are only six slots on the OSS, not seven */
146 if (events & irq_bit) {
147 oss->irq_pending &= ~irq_bit;
148 generic_handle_irq(NUBUS_SOURCE_BASE + i);
150 } while(events & (irq_bit - 1));
155 * Enable an OSS interrupt
157 * It looks messy but it's rather straightforward. The switch() statement
158 * just maps the machspec interrupt numbers to the right OSS interrupt
159 * source (if the OSS handles that interrupt) and then sets the interrupt
160 * level for that source to nonzero, thus enabling the interrupt.
163 void oss_irq_enable(int irq) {
165 printk("oss_irq_enable(%d)\n", irq);
169 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
172 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
175 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
183 irq -= NUBUS_SOURCE_BASE;
184 oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
188 printk("%s unknown irq %d\n", __func__, irq);
195 * Disable an OSS interrupt
197 * Same as above except we set the source's interrupt level to zero,
198 * to disable the interrupt.
201 void oss_irq_disable(int irq) {
203 printk("oss_irq_disable(%d)\n", irq);
207 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_DISABLED;
210 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_DISABLED;
213 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED;
221 irq -= NUBUS_SOURCE_BASE;
222 oss->irq_level[irq] = OSS_IRQLEV_DISABLED;
226 printk("%s unknown irq %d\n", __func__, irq);
233 * Clear an OSS interrupt
235 * Not sure if this works or not but it's the only method I could
236 * think of based on the contents of the mac_oss structure.
239 void oss_irq_clear(int irq) {
240 /* FIXME: how to do this on OSS? */
243 oss->irq_pending &= ~OSS_IP_IOPSCC;
246 oss->irq_pending &= ~OSS_IP_IOPISM;
249 oss->irq_pending &= ~OSS_IP_SCSI;
257 irq -= NUBUS_SOURCE_BASE;
258 oss->irq_pending &= ~(1 << irq);
264 * Check to see if a specific OSS interrupt is pending
267 int oss_irq_pending(int irq)
271 return oss->irq_pending & OSS_IP_IOPSCC;
274 return oss->irq_pending & OSS_IP_IOPISM;
277 return oss->irq_pending & OSS_IP_SCSI;
285 irq -= NUBUS_SOURCE_BASE;
286 return oss->irq_pending & (1 << irq);