blob: 3f81892527ad260fe6e0561c1ad71e071623a5e3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Finn Thainda3fb3c2011-10-24 01:11:18 +11003 * Operating System Services (OSS) chip handling
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 Arlott0c79cf62007-10-20 01:20:32 +020012 * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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 Uytterhoevenddc7fd22011-07-13 21:48:30 +020023#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/macintosh.h>
26#include <asm/macints.h>
27#include <asm/mac_via.h>
28#include <asm/mac_oss.h>
29
30int oss_present;
31volatile struct mac_oss *oss;
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/*
34 * Initialize the OSS
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 */
36
37void __init oss_init(void)
38{
39 int i;
40
Finn Thain7a0bb442017-10-26 22:45:24 -040041 if (macintosh_config->ident != MAC_MODEL_IIFX)
42 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44 oss = (struct mac_oss *) OSS_BASE;
Finn Thain7a0bb442017-10-26 22:45:24 -040045 pr_debug("OSS detected at %p", oss);
46 oss_present = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
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 Thainb24f6702015-03-30 12:22:30 +110051 for (i = 0; i < OSS_NUM_SOURCES; i++)
Finn Thainda3fb3c2011-10-24 01:11:18 +110052 oss->irq_level[i] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55/*
Finn Thainda3fb3c2011-10-24 01:11:18 +110056 * Handle miscellaneous OSS interrupts.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
58
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +020059static void oss_irq(struct irq_desc *desc)
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020060{
Finn Thainda3fb3c2011-10-24 01:11:18 +110061 int events = oss->irq_pending &
Thomas Gleixner625b86a2015-07-31 21:56:10 +020062 (OSS_IP_IOPSCC | OSS_IP_SCSI | OSS_IP_IOPISM);
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020063
Finn Thainda3fb3c2011-10-24 01:11:18 +110064 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 Uytterhoeven9145db52011-08-10 12:48:29 +020070 oss->irq_pending &= ~OSS_IP_SCSI;
71 generic_handle_irq(IRQ_MAC_SCSI);
Finn Thainda3fb3c2011-10-24 01:11:18 +110072 }
73
74 if (events & OSS_IP_IOPISM) {
75 oss->irq_pending &= ~OSS_IP_IOPISM;
76 generic_handle_irq(IRQ_MAC_ADB);
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020077 }
78}
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80/*
81 * Nubus IRQ handler, OSS style
82 *
83 * Unlike the VIA/RBV this is on its own autovector interrupt level.
84 */
85
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +020086static void oss_nubus_irq(struct irq_desc *desc)
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020087{
88 int events, irq_bit, i;
89
90 events = oss->irq_pending & OSS_IP_NUBUS;
91 if (!events)
92 return;
93
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020094 /* 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 Uytterhoeven9145db52011-08-10 12:48:29 +0200107
108/*
109 * Register the OSS and NuBus interrupt dispatchers.
Finn Thainda3fb3c2011-10-24 01:11:18 +1100110 *
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 Uytterhoeven9145db52011-08-10 12:48:29 +0200115 */
116
Finn Thainda3fb3c2011-10-24 01:11:18 +1100117#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 Uytterhoeven9145db52011-08-10 12:48:29 +0200123void __init oss_register_interrupts(void)
124{
Finn Thainda3fb3c2011-10-24 01:11:18 +1100125 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 Uytterhoeven9145db52011-08-10 12:48:29 +0200133}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
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
144void oss_irq_enable(int irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100146 case IRQ_MAC_SCC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100148 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 case IRQ_MAC_ADB:
150 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100151 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 case IRQ_MAC_SCSI:
153 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100154 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 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 Thainda3fb3c2011-10-24 01:11:18 +1100163 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
Finn Thainda3fb3c2011-10-24 01:11:18 +1100165
166 if (IRQ_SRC(irq) == 1)
167 via_irq_enable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
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
177void oss_irq_disable(int irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100179 case IRQ_MAC_SCC:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100180 oss->irq_level[OSS_IOPSCC] = 0;
181 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 case IRQ_MAC_ADB:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100183 oss->irq_level[OSS_IOPISM] = 0;
184 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 case IRQ_MAC_SCSI:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100186 oss->irq_level[OSS_SCSI] = 0;
187 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 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 Thainda3fb3c2011-10-24 01:11:18 +1100195 oss->irq_level[irq] = 0;
196 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
Finn Thainda3fb3c2011-10-24 01:11:18 +1100198
199 if (IRQ_SRC(irq) == 1)
200 via_irq_disable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}