blob: 55d6592783f55710d0b23cae075f657252826650 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Finn Thainda3fb3c2011-10-24 01:11:18 +11002 * Operating System Services (OSS) chip handling
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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.
Simon Arlott0c79cf62007-10-20 01:20:32 +020011 * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * 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>
Geert Uytterhoevenddc7fd22011-07-13 21:48:30 +020022#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/macintosh.h>
25#include <asm/macints.h>
26#include <asm/mac_via.h>
27#include <asm/mac_oss.h>
28
29int oss_present;
30volatile struct mac_oss *oss;
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/*
33 * Initialize the OSS
34 *
35 * The OSS "detection" code is actually in via_init() which is always called
36 * before us. Thus we can count on oss_present being valid on entry.
37 */
38
39void __init oss_init(void)
40{
41 int i;
42
43 if (!oss_present) return;
44
45 oss = (struct mac_oss *) OSS_BASE;
46
47 /* Disable all interrupts. Unlike a VIA it looks like we */
48 /* do this by setting the source's interrupt level to zero. */
49
Finn Thainb24f6702015-03-30 12:22:30 +110050 for (i = 0; i < OSS_NUM_SOURCES; i++)
Finn Thainda3fb3c2011-10-24 01:11:18 +110051 oss->irq_level[i] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
54/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 * Initialize OSS for Nubus access
56 */
57
58void __init oss_nubus_init(void)
59{
60}
61
62/*
Finn Thainda3fb3c2011-10-24 01:11:18 +110063 * Handle miscellaneous OSS interrupts.
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
65
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +020066static void oss_irq(struct irq_desc *desc)
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020067{
Finn Thainda3fb3c2011-10-24 01:11:18 +110068 int events = oss->irq_pending &
Thomas Gleixner625b86a2015-07-31 21:56:10 +020069 (OSS_IP_IOPSCC | OSS_IP_SCSI | OSS_IP_IOPISM);
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020070
71#ifdef DEBUG_IRQS
72 if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
Thomas Gleixner625b86a2015-07-31 21:56:10 +020073 unsigned int irq = irq_desc_get_irq(desc);
74
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020075 printk("oss_irq: irq %u events = 0x%04X\n", irq,
76 (int) oss->irq_pending);
77 }
78#endif
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020079
Finn Thainda3fb3c2011-10-24 01:11:18 +110080 if (events & OSS_IP_IOPSCC) {
81 oss->irq_pending &= ~OSS_IP_IOPSCC;
82 generic_handle_irq(IRQ_MAC_SCC);
83 }
84
85 if (events & OSS_IP_SCSI) {
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020086 oss->irq_pending &= ~OSS_IP_SCSI;
87 generic_handle_irq(IRQ_MAC_SCSI);
Finn Thainda3fb3c2011-10-24 01:11:18 +110088 }
89
90 if (events & OSS_IP_IOPISM) {
91 oss->irq_pending &= ~OSS_IP_IOPISM;
92 generic_handle_irq(IRQ_MAC_ADB);
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020093 }
94}
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/*
97 * Nubus IRQ handler, OSS style
98 *
99 * Unlike the VIA/RBV this is on its own autovector interrupt level.
100 */
101
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200102static void oss_nubus_irq(struct irq_desc *desc)
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200103{
104 int events, irq_bit, i;
105
106 events = oss->irq_pending & OSS_IP_NUBUS;
107 if (!events)
108 return;
109
110#ifdef DEBUG_NUBUS_INT
111 if (console_loglevel > 7) {
112 printk("oss_nubus_irq: events = 0x%04X\n", events);
113 }
114#endif
115 /* There are only six slots on the OSS, not seven */
116
117 i = 6;
118 irq_bit = 0x40;
119 do {
120 --i;
121 irq_bit >>= 1;
122 if (events & irq_bit) {
123 oss->irq_pending &= ~irq_bit;
124 generic_handle_irq(NUBUS_SOURCE_BASE + i);
125 }
126 } while(events & (irq_bit - 1));
127}
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200128
129/*
130 * Register the OSS and NuBus interrupt dispatchers.
Finn Thainda3fb3c2011-10-24 01:11:18 +1100131 *
132 * This IRQ mapping is laid out with two things in mind: first, we try to keep
133 * things on their own levels to avoid having to do double-dispatches. Second,
134 * the levels match as closely as possible the alternate IRQ mapping mode (aka
135 * "A/UX mode") available on some VIA machines.
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200136 */
137
Finn Thainda3fb3c2011-10-24 01:11:18 +1100138#define OSS_IRQLEV_IOPISM IRQ_AUTO_1
139#define OSS_IRQLEV_SCSI IRQ_AUTO_2
140#define OSS_IRQLEV_NUBUS IRQ_AUTO_3
141#define OSS_IRQLEV_IOPSCC IRQ_AUTO_4
142#define OSS_IRQLEV_VIA1 IRQ_AUTO_6
143
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200144void __init oss_register_interrupts(void)
145{
Finn Thainda3fb3c2011-10-24 01:11:18 +1100146 irq_set_chained_handler(OSS_IRQLEV_IOPISM, oss_irq);
147 irq_set_chained_handler(OSS_IRQLEV_SCSI, oss_irq);
148 irq_set_chained_handler(OSS_IRQLEV_NUBUS, oss_nubus_irq);
149 irq_set_chained_handler(OSS_IRQLEV_IOPSCC, oss_irq);
150 irq_set_chained_handler(OSS_IRQLEV_VIA1, via1_irq);
151
152 /* OSS_VIA1 gets enabled here because it has no machspec interrupt. */
153 oss->irq_level[OSS_VIA1] = IRQ_AUTO_6;
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200154}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156/*
157 * Enable an OSS interrupt
158 *
159 * It looks messy but it's rather straightforward. The switch() statement
160 * just maps the machspec interrupt numbers to the right OSS interrupt
161 * source (if the OSS handles that interrupt) and then sets the interrupt
162 * level for that source to nonzero, thus enabling the interrupt.
163 */
164
165void oss_irq_enable(int irq) {
166#ifdef DEBUG_IRQUSE
167 printk("oss_irq_enable(%d)\n", irq);
168#endif
169 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100170 case IRQ_MAC_SCC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100172 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 case IRQ_MAC_ADB:
174 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100175 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 case IRQ_MAC_SCSI:
177 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100178 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 case IRQ_NUBUS_9:
180 case IRQ_NUBUS_A:
181 case IRQ_NUBUS_B:
182 case IRQ_NUBUS_C:
183 case IRQ_NUBUS_D:
184 case IRQ_NUBUS_E:
185 irq -= NUBUS_SOURCE_BASE;
186 oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100187 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
Finn Thainda3fb3c2011-10-24 01:11:18 +1100189
190 if (IRQ_SRC(irq) == 1)
191 via_irq_enable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
194/*
195 * Disable an OSS interrupt
196 *
197 * Same as above except we set the source's interrupt level to zero,
198 * to disable the interrupt.
199 */
200
201void oss_irq_disable(int irq) {
202#ifdef DEBUG_IRQUSE
203 printk("oss_irq_disable(%d)\n", irq);
204#endif
205 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100206 case IRQ_MAC_SCC:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100207 oss->irq_level[OSS_IOPSCC] = 0;
208 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 case IRQ_MAC_ADB:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100210 oss->irq_level[OSS_IOPISM] = 0;
211 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 case IRQ_MAC_SCSI:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100213 oss->irq_level[OSS_SCSI] = 0;
214 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 case IRQ_NUBUS_9:
216 case IRQ_NUBUS_A:
217 case IRQ_NUBUS_B:
218 case IRQ_NUBUS_C:
219 case IRQ_NUBUS_D:
220 case IRQ_NUBUS_E:
221 irq -= NUBUS_SOURCE_BASE;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100222 oss->irq_level[irq] = 0;
223 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
Finn Thainda3fb3c2011-10-24 01:11:18 +1100225
226 if (IRQ_SRC(irq) == 1)
227 via_irq_disable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}