blob: 921e6c092f2c66260af76bb3180116e8d069f787 [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 Thain317b7492018-01-13 17:44:31 -050056 * Handle OSS interrupts.
57 * XXX how do you clear a pending IRQ? is it even necessary?
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 */
59
Finn Thain317b7492018-01-13 17:44:31 -050060static void oss_iopism_irq(struct irq_desc *desc)
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020061{
Finn Thain317b7492018-01-13 17:44:31 -050062 generic_handle_irq(IRQ_MAC_ADB);
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020063}
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Finn Thain317b7492018-01-13 17:44:31 -050065static void oss_scsi_irq(struct irq_desc *desc)
66{
67 generic_handle_irq(IRQ_MAC_SCSI);
68}
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +020070static void oss_nubus_irq(struct irq_desc *desc)
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020071{
Finn Thain317b7492018-01-13 17:44:31 -050072 u16 events, irq_bit;
73 int irq_num;
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020074
75 events = oss->irq_pending & OSS_IP_NUBUS;
Finn Thain317b7492018-01-13 17:44:31 -050076 irq_num = NUBUS_SOURCE_BASE + 5;
77 irq_bit = OSS_IP_NUBUS5;
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020078 do {
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020079 if (events & irq_bit) {
Finn Thain317b7492018-01-13 17:44:31 -050080 events &= ~irq_bit;
81 generic_handle_irq(irq_num);
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020082 }
Finn Thain317b7492018-01-13 17:44:31 -050083 --irq_num;
84 irq_bit >>= 1;
85 } while (events);
86}
87
88static void oss_iopscc_irq(struct irq_desc *desc)
89{
90 generic_handle_irq(IRQ_MAC_SCC);
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020091}
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020092
93/*
94 * Register the OSS and NuBus interrupt dispatchers.
Finn Thainda3fb3c2011-10-24 01:11:18 +110095 *
96 * This IRQ mapping is laid out with two things in mind: first, we try to keep
97 * things on their own levels to avoid having to do double-dispatches. Second,
98 * the levels match as closely as possible the alternate IRQ mapping mode (aka
99 * "A/UX mode") available on some VIA machines.
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200100 */
101
Finn Thainda3fb3c2011-10-24 01:11:18 +1100102#define OSS_IRQLEV_IOPISM IRQ_AUTO_1
103#define OSS_IRQLEV_SCSI IRQ_AUTO_2
104#define OSS_IRQLEV_NUBUS IRQ_AUTO_3
105#define OSS_IRQLEV_IOPSCC IRQ_AUTO_4
106#define OSS_IRQLEV_VIA1 IRQ_AUTO_6
107
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200108void __init oss_register_interrupts(void)
109{
Finn Thain317b7492018-01-13 17:44:31 -0500110 irq_set_chained_handler(OSS_IRQLEV_IOPISM, oss_iopism_irq);
111 irq_set_chained_handler(OSS_IRQLEV_SCSI, oss_scsi_irq);
Finn Thainda3fb3c2011-10-24 01:11:18 +1100112 irq_set_chained_handler(OSS_IRQLEV_NUBUS, oss_nubus_irq);
Finn Thain317b7492018-01-13 17:44:31 -0500113 irq_set_chained_handler(OSS_IRQLEV_IOPSCC, oss_iopscc_irq);
Finn Thainda3fb3c2011-10-24 01:11:18 +1100114 irq_set_chained_handler(OSS_IRQLEV_VIA1, via1_irq);
115
116 /* OSS_VIA1 gets enabled here because it has no machspec interrupt. */
Finn Thain317b7492018-01-13 17:44:31 -0500117 oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120/*
121 * Enable an OSS interrupt
122 *
123 * It looks messy but it's rather straightforward. The switch() statement
124 * just maps the machspec interrupt numbers to the right OSS interrupt
125 * source (if the OSS handles that interrupt) and then sets the interrupt
126 * level for that source to nonzero, thus enabling the interrupt.
127 */
128
129void oss_irq_enable(int irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100131 case IRQ_MAC_SCC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100133 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 case IRQ_MAC_ADB:
135 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100136 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 case IRQ_MAC_SCSI:
138 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100139 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 case IRQ_NUBUS_9:
141 case IRQ_NUBUS_A:
142 case IRQ_NUBUS_B:
143 case IRQ_NUBUS_C:
144 case IRQ_NUBUS_D:
145 case IRQ_NUBUS_E:
146 irq -= NUBUS_SOURCE_BASE;
147 oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100148 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
Finn Thainda3fb3c2011-10-24 01:11:18 +1100150
151 if (IRQ_SRC(irq) == 1)
152 via_irq_enable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
155/*
156 * Disable an OSS interrupt
157 *
158 * Same as above except we set the source's interrupt level to zero,
159 * to disable the interrupt.
160 */
161
162void oss_irq_disable(int irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100164 case IRQ_MAC_SCC:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100165 oss->irq_level[OSS_IOPSCC] = 0;
166 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 case IRQ_MAC_ADB:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100168 oss->irq_level[OSS_IOPISM] = 0;
169 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case IRQ_MAC_SCSI:
Finn Thainda3fb3c2011-10-24 01:11:18 +1100171 oss->irq_level[OSS_SCSI] = 0;
172 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 case IRQ_NUBUS_9:
174 case IRQ_NUBUS_A:
175 case IRQ_NUBUS_B:
176 case IRQ_NUBUS_C:
177 case IRQ_NUBUS_D:
178 case IRQ_NUBUS_E:
179 irq -= NUBUS_SOURCE_BASE;
Finn Thainda3fb3c2011-10-24 01:11:18 +1100180 oss->irq_level[irq] = 0;
181 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
Finn Thainda3fb3c2011-10-24 01:11:18 +1100183
184 if (IRQ_SRC(irq) == 1)
185 via_irq_disable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}