9
9
* Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
12
#include <linux/errno.h>
13
#include <linux/linkage.h>
14
#include <linux/kernel_stat.h>
15
#include <linux/signal.h>
16
#include <linux/sched.h>
17
#include <linux/ptrace.h>
18
#include <linux/smp.h>
19
#include <linux/interrupt.h>
20
#include <linux/init.h>
21
#include <linux/ioport.h>
23
#include <linux/of_device.h>
25
#include <asm/ptrace.h>
26
#include <asm/processor.h>
27
#include <asm/system.h>
29
#include <asm/vaddrs.h>
30
12
#include <asm/timer.h>
31
#include <asm/openprom.h>
32
#include <asm/oplib.h>
33
13
#include <asm/traps.h>
34
14
#include <asm/pgalloc.h>
35
15
#include <asm/pgtable.h>
37
16
#include <asm/irq.h>
38
17
#include <asm/io.h>
39
18
#include <asm/cacheflush.h>
43
struct sun4m_irq_percpu {
49
struct sun4m_irq_global {
57
/* Code in entry.S needs to get at these register mappings. */
58
struct sun4m_irq_percpu __iomem *sun4m_irq_percpu[SUN4M_NCPUS];
59
struct sun4m_irq_global __iomem *sun4m_irq_global;
61
/* Dave Redman (djhr@tadpole.co.uk)
62
* The sun4m interrupt registers.
64
#define SUN4M_INT_ENABLE 0x80000000
65
#define SUN4M_INT_E14 0x00000080
66
#define SUN4M_INT_E10 0x00080000
68
#define SUN4M_HARD_INT(x) (0x000000001 << (x))
69
#define SUN4M_SOFT_INT(x) (0x000010000 << (x))
71
#define SUN4M_INT_MASKALL 0x80000000 /* mask all interrupts */
72
#define SUN4M_INT_MODULE_ERR 0x40000000 /* module error */
73
#define SUN4M_INT_M2S_WRITE_ERR 0x20000000 /* write buffer error */
74
#define SUN4M_INT_ECC_ERR 0x10000000 /* ecc memory error */
75
#define SUN4M_INT_VME_ERR 0x08000000 /* vme async error */
76
#define SUN4M_INT_FLOPPY 0x00400000 /* floppy disk */
77
#define SUN4M_INT_MODULE 0x00200000 /* module interrupt */
78
#define SUN4M_INT_VIDEO 0x00100000 /* onboard video */
79
#define SUN4M_INT_REALTIME 0x00080000 /* system timer */
80
#define SUN4M_INT_SCSI 0x00040000 /* onboard scsi */
81
#define SUN4M_INT_AUDIO 0x00020000 /* audio/isdn */
82
#define SUN4M_INT_ETHERNET 0x00010000 /* onboard ethernet */
83
#define SUN4M_INT_SERIAL 0x00008000 /* serial ports */
84
#define SUN4M_INT_KBDMS 0x00004000 /* keyboard/mouse */
85
#define SUN4M_INT_SBUSBITS 0x00003F80 /* sbus int bits */
86
#define SUN4M_INT_VMEBITS 0x0000007F /* vme int bits */
88
#define SUN4M_INT_ERROR (SUN4M_INT_MODULE_ERR | \
89
SUN4M_INT_M2S_WRITE_ERR | \
93
#define SUN4M_INT_SBUS(x) (1 << (x+7))
94
#define SUN4M_INT_VME(x) (1 << (x))
96
/* Interrupt levels used by OBP */
97
#define OBP_INT_LEVEL_SOFT 0x10
98
#define OBP_INT_LEVEL_ONBOARD 0x20
99
#define OBP_INT_LEVEL_SBUS 0x30
100
#define OBP_INT_LEVEL_VME 0x40
102
/* Interrupt level assignment on sun4m:
23
/* Sample sun4m IRQ layout:
27
* 0x26 - Lance ethernet
31
* 0x33 - Parallel port, SBUS level 1
34
* 0x39 - Audio, Graphics card, SBUS level 4
38
* Each interrupt source has a mask bit in the interrupt registers.
39
* When the mask bit is set, this blocks interrupt deliver. So you
40
* clear the bit to enable the interrupt.
42
* Interrupts numbered less than 0x10 are software triggered interrupts
43
* and unused by Linux.
45
* Interrupt level assignment on sun4m:
105
48
* ------------------------------------------------------------
107
50
* 2 softint-2, VME/SBUS level 1
108
51
* 3 softint-3, VME/SBUS level 2
109
52
* 4 softint-4, onboard SCSI
152
95
* power: 0x22 onboard power device (XXX unknown mask bit XXX)
155
static unsigned long irq_mask[0x50] = {
157
0, SUN4M_SOFT_INT(1),
158
SUN4M_SOFT_INT(2), SUN4M_SOFT_INT(3),
159
SUN4M_SOFT_INT(4), SUN4M_SOFT_INT(5),
160
SUN4M_SOFT_INT(6), SUN4M_SOFT_INT(7),
161
SUN4M_SOFT_INT(8), SUN4M_SOFT_INT(9),
162
SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
163
SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
164
SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
166
0, SUN4M_SOFT_INT(1),
167
SUN4M_SOFT_INT(2), SUN4M_SOFT_INT(3),
168
SUN4M_SOFT_INT(4), SUN4M_SOFT_INT(5),
169
SUN4M_SOFT_INT(6), SUN4M_SOFT_INT(7),
170
SUN4M_SOFT_INT(8), SUN4M_SOFT_INT(9),
171
SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
172
SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
173
SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
99
/* Code in entry.S needs to get at these register mappings. */
100
struct sun4m_irq_percpu __iomem *sun4m_irq_percpu[SUN4M_NCPUS];
101
struct sun4m_irq_global __iomem *sun4m_irq_global;
103
struct sun4m_handler_data {
108
/* Dave Redman (djhr@tadpole.co.uk)
109
* The sun4m interrupt registers.
111
#define SUN4M_INT_ENABLE 0x80000000
112
#define SUN4M_INT_E14 0x00000080
113
#define SUN4M_INT_E10 0x00080000
115
#define SUN4M_HARD_INT(x) (0x000000001 << (x))
116
#define SUN4M_SOFT_INT(x) (0x000010000 << (x))
118
#define SUN4M_INT_MASKALL 0x80000000 /* mask all interrupts */
119
#define SUN4M_INT_MODULE_ERR 0x40000000 /* module error */
120
#define SUN4M_INT_M2S_WRITE_ERR 0x20000000 /* write buffer error */
121
#define SUN4M_INT_ECC_ERR 0x10000000 /* ecc memory error */
122
#define SUN4M_INT_VME_ERR 0x08000000 /* vme async error */
123
#define SUN4M_INT_FLOPPY 0x00400000 /* floppy disk */
124
#define SUN4M_INT_MODULE 0x00200000 /* module interrupt */
125
#define SUN4M_INT_VIDEO 0x00100000 /* onboard video */
126
#define SUN4M_INT_REALTIME 0x00080000 /* system timer */
127
#define SUN4M_INT_SCSI 0x00040000 /* onboard scsi */
128
#define SUN4M_INT_AUDIO 0x00020000 /* audio/isdn */
129
#define SUN4M_INT_ETHERNET 0x00010000 /* onboard ethernet */
130
#define SUN4M_INT_SERIAL 0x00008000 /* serial ports */
131
#define SUN4M_INT_KBDMS 0x00004000 /* keyboard/mouse */
132
#define SUN4M_INT_SBUSBITS 0x00003F80 /* sbus int bits */
133
#define SUN4M_INT_VMEBITS 0x0000007F /* vme int bits */
135
#define SUN4M_INT_ERROR (SUN4M_INT_MODULE_ERR | \
136
SUN4M_INT_M2S_WRITE_ERR | \
137
SUN4M_INT_ECC_ERR | \
140
#define SUN4M_INT_SBUS(x) (1 << (x+7))
141
#define SUN4M_INT_VME(x) (1 << (x))
143
/* Interrupt levels used by OBP */
144
#define OBP_INT_LEVEL_SOFT 0x10
145
#define OBP_INT_LEVEL_ONBOARD 0x20
146
#define OBP_INT_LEVEL_SBUS 0x30
147
#define OBP_INT_LEVEL_VME 0x40
149
#define SUN4M_TIMER_IRQ (OBP_INT_LEVEL_ONBOARD | 10)
150
#define SUN4M_PROFILE_IRQ (OBP_INT_LEVEL_ONBOARD | 14)
152
static unsigned long sun4m_imask[0x50] = {
154
0, SUN4M_SOFT_INT(1),
155
SUN4M_SOFT_INT(2), SUN4M_SOFT_INT(3),
156
SUN4M_SOFT_INT(4), SUN4M_SOFT_INT(5),
157
SUN4M_SOFT_INT(6), SUN4M_SOFT_INT(7),
158
SUN4M_SOFT_INT(8), SUN4M_SOFT_INT(9),
159
SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
160
SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
161
SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
163
0, SUN4M_SOFT_INT(1),
164
SUN4M_SOFT_INT(2), SUN4M_SOFT_INT(3),
165
SUN4M_SOFT_INT(4), SUN4M_SOFT_INT(5),
166
SUN4M_SOFT_INT(6), SUN4M_SOFT_INT(7),
167
SUN4M_SOFT_INT(8), SUN4M_SOFT_INT(9),
168
SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
169
SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
170
SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
176
173
SUN4M_INT_SCSI, 0, SUN4M_INT_ETHERNET, 0,
177
174
SUN4M_INT_VIDEO, SUN4M_INT_MODULE,
178
175
SUN4M_INT_REALTIME, SUN4M_INT_FLOPPY,
179
176
(SUN4M_INT_SERIAL | SUN4M_INT_KBDMS),
180
SUN4M_INT_AUDIO, 0, SUN4M_INT_MODULE_ERR,
177
SUN4M_INT_AUDIO, SUN4M_INT_E14, SUN4M_INT_MODULE_ERR,
182
179
0, 0, SUN4M_INT_SBUS(0), SUN4M_INT_SBUS(1),
183
180
0, SUN4M_INT_SBUS(2), 0, SUN4M_INT_SBUS(3),
184
181
0, SUN4M_INT_SBUS(4), 0, SUN4M_INT_SBUS(5),
185
182
0, SUN4M_INT_SBUS(6), 0, 0,
187
184
0, 0, SUN4M_INT_VME(0), SUN4M_INT_VME(1),
188
185
0, SUN4M_INT_VME(2), 0, SUN4M_INT_VME(3),
189
186
0, SUN4M_INT_VME(4), 0, SUN4M_INT_VME(5),
190
187
0, SUN4M_INT_VME(6), 0, 0
193
static unsigned long sun4m_get_irqmask(unsigned int irq)
198
mask = irq_mask[irq];
203
printk(KERN_ERR "sun4m_get_irqmask: IRQ%d has no valid mask!\n",
209
static void sun4m_disable_irq(unsigned int irq_nr)
211
unsigned long mask, flags;
212
int cpu = smp_processor_id();
214
mask = sun4m_get_irqmask(irq_nr);
215
local_irq_save(flags);
217
sbus_writel(mask, &sun4m_irq_global->mask_set);
219
sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
220
local_irq_restore(flags);
223
static void sun4m_enable_irq(unsigned int irq_nr)
225
unsigned long mask, flags;
226
int cpu = smp_processor_id();
228
/* Dreadful floppy hack. When we use 0x2b instead of
229
* 0x0b the system blows (it starts to whistle!).
230
* So we continue to use 0x0b. Fixme ASAP. --P3
232
if (irq_nr != 0x0b) {
233
mask = sun4m_get_irqmask(irq_nr);
234
local_irq_save(flags);
236
sbus_writel(mask, &sun4m_irq_global->mask_clear);
238
sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
239
local_irq_restore(flags);
241
local_irq_save(flags);
242
sbus_writel(SUN4M_INT_FLOPPY, &sun4m_irq_global->mask_clear);
243
local_irq_restore(flags);
247
static unsigned long cpu_pil_to_imask[16] = {
250
/*2*/ SUN4M_INT_SBUS(0) | SUN4M_INT_VME(0),
251
/*3*/ SUN4M_INT_SBUS(1) | SUN4M_INT_VME(1),
252
/*4*/ SUN4M_INT_SCSI,
253
/*5*/ SUN4M_INT_SBUS(2) | SUN4M_INT_VME(2),
254
/*6*/ SUN4M_INT_ETHERNET,
255
/*7*/ SUN4M_INT_SBUS(3) | SUN4M_INT_VME(3),
256
/*8*/ SUN4M_INT_VIDEO,
257
/*9*/ SUN4M_INT_SBUS(4) | SUN4M_INT_VME(4) | SUN4M_INT_MODULE_ERR,
258
/*10*/ SUN4M_INT_REALTIME,
259
/*11*/ SUN4M_INT_SBUS(5) | SUN4M_INT_VME(5) | SUN4M_INT_FLOPPY,
260
/*12*/ SUN4M_INT_SERIAL | SUN4M_INT_KBDMS,
261
/*13*/ SUN4M_INT_SBUS(6) | SUN4M_INT_VME(6) | SUN4M_INT_AUDIO,
262
/*14*/ SUN4M_INT_E14,
263
/*15*/ SUN4M_INT_ERROR
190
static void sun4m_mask_irq(struct irq_data *data)
192
struct sun4m_handler_data *handler_data = data->handler_data;
193
int cpu = smp_processor_id();
195
if (handler_data->mask) {
198
local_irq_save(flags);
199
if (handler_data->percpu) {
200
sbus_writel(handler_data->mask, &sun4m_irq_percpu[cpu]->set);
202
sbus_writel(handler_data->mask, &sun4m_irq_global->mask_set);
204
local_irq_restore(flags);
208
static void sun4m_unmask_irq(struct irq_data *data)
210
struct sun4m_handler_data *handler_data = data->handler_data;
211
int cpu = smp_processor_id();
213
if (handler_data->mask) {
216
local_irq_save(flags);
217
if (handler_data->percpu) {
218
sbus_writel(handler_data->mask, &sun4m_irq_percpu[cpu]->clear);
220
sbus_writel(handler_data->mask, &sun4m_irq_global->mask_clear);
222
local_irq_restore(flags);
226
static unsigned int sun4m_startup_irq(struct irq_data *data)
229
sun4m_unmask_irq(data);
233
static void sun4m_shutdown_irq(struct irq_data *data)
235
sun4m_mask_irq(data);
236
irq_unlink(data->irq);
239
static struct irq_chip sun4m_irq = {
241
.irq_startup = sun4m_startup_irq,
242
.irq_shutdown = sun4m_shutdown_irq,
243
.irq_mask = sun4m_mask_irq,
244
.irq_unmask = sun4m_unmask_irq,
266
/* We assume the caller has disabled local interrupts when these are called,
267
* or else very bizarre behavior will result.
269
static void sun4m_disable_pil_irq(unsigned int pil)
271
sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_set);
274
static void sun4m_enable_pil_irq(unsigned int pil)
276
sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_clear);
248
static unsigned int sun4m_build_device_irq(struct platform_device *op,
249
unsigned int real_irq)
251
struct sun4m_handler_data *handler_data;
255
if (real_irq >= OBP_INT_LEVEL_VME) {
256
prom_printf("Bogus sun4m IRQ %u\n", real_irq);
259
pil = (real_irq & 0xf);
260
irq = irq_alloc(real_irq, pil);
265
handler_data = irq_get_handler_data(irq);
266
if (unlikely(handler_data))
269
handler_data = kzalloc(sizeof(struct sun4m_handler_data), GFP_ATOMIC);
270
if (unlikely(!handler_data)) {
271
prom_printf("IRQ: kzalloc(sun4m_handler_data) failed.\n");
275
handler_data->mask = sun4m_imask[real_irq];
276
handler_data->percpu = real_irq < OBP_INT_LEVEL_ONBOARD;
277
irq_set_chip_and_handler_name(irq, &sun4m_irq,
278
handle_level_irq, "level");
279
irq_set_handler_data(irq, handler_data);
279
285
#ifdef CONFIG_SMP
280
286
static void sun4m_send_ipi(int cpu, int level)
282
unsigned long mask = sun4m_get_irqmask(level);
283
sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
288
sbus_writel(SUN4M_SOFT_INT(level), &sun4m_irq_percpu[cpu]->set);
286
291
static void sun4m_clear_ipi(int cpu, int level)
288
unsigned long mask = sun4m_get_irqmask(level);
289
sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
293
sbus_writel(SUN4M_SOFT_INT(level), &sun4m_irq_percpu[cpu]->clear);
292
296
static void sun4m_set_udt(int cpu)