1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/linkage.h>
21#include <linux/interrupt.h>
22#include <linux/spinlock.h>
23#include <linux/smp.h>
24#include <linux/mm.h>
25#include <linux/slab.h>
26#include <linux/kernel_stat.h>
27
28#include <asm/errno.h>
29#include <asm/signal.h>
30#include <asm/system.h>
31#include <asm/time.h>
32#include <asm/io.h>
33
34#include <asm/sibyte/sb1250_regs.h>
35#include <asm/sibyte/sb1250_int.h>
36#include <asm/sibyte/sb1250_uart.h>
37#include <asm/sibyte/sb1250_scd.h>
38#include <asm/sibyte/sb1250.h>
39
40
41
42
43
44
45
46
47
48static void end_sb1250_irq(unsigned int irq);
49static void enable_sb1250_irq(unsigned int irq);
50static void disable_sb1250_irq(unsigned int irq);
51static void ack_sb1250_irq(unsigned int irq);
52#ifdef CONFIG_SMP
53static void sb1250_set_affinity(unsigned int irq, cpumask_t mask);
54#endif
55
56#ifdef CONFIG_SIBYTE_HAS_LDT
57extern unsigned long ldt_eoi_space;
58#endif
59
60#ifdef CONFIG_KGDB
61static int kgdb_irq;
62
63
64int kgdb_port = 1;
65#ifdef CONFIG_SERIAL_SB1250_DUART
66extern char sb1250_duart_present[];
67#endif
68#endif
69
70static struct irq_chip sb1250_irq_type = {
71 .name = "SB1250-IMR",
72 .ack = ack_sb1250_irq,
73 .mask = disable_sb1250_irq,
74 .mask_ack = ack_sb1250_irq,
75 .unmask = enable_sb1250_irq,
76 .end = end_sb1250_irq,
77#ifdef CONFIG_SMP
78 .set_affinity = sb1250_set_affinity
79#endif
80};
81
82
83int sb1250_irq_owner[SB1250_NR_IRQS];
84
85DEFINE_SPINLOCK(sb1250_imr_lock);
86
87void sb1250_mask_irq(int cpu, int irq)
88{
89 unsigned long flags;
90 u64 cur_ints;
91
92 spin_lock_irqsave(&sb1250_imr_lock, flags);
93 cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
94 R_IMR_INTERRUPT_MASK));
95 cur_ints |= (((u64) 1) << irq);
96 ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
97 R_IMR_INTERRUPT_MASK));
98 spin_unlock_irqrestore(&sb1250_imr_lock, flags);
99}
100
101void sb1250_unmask_irq(int cpu, int irq)
102{
103 unsigned long flags;
104 u64 cur_ints;
105
106 spin_lock_irqsave(&sb1250_imr_lock, flags);
107 cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
108 R_IMR_INTERRUPT_MASK));
109 cur_ints &= ~(((u64) 1) << irq);
110 ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
111 R_IMR_INTERRUPT_MASK));
112 spin_unlock_irqrestore(&sb1250_imr_lock, flags);
113}
114
115#ifdef CONFIG_SMP
116static void sb1250_set_affinity(unsigned int irq, cpumask_t mask)
117{
118 int i = 0, old_cpu, cpu, int_on;
119 u64 cur_ints;
120 struct irq_desc *desc = irq_desc + irq;
121 unsigned long flags;
122
123 i = first_cpu(mask);
124
125 if (cpus_weight(mask) > 1) {
126 printk("attempted to set irq affinity for irq %d to multiple CPUs\n", irq);
127 return;
128 }
129
130
131 cpu = cpu_logical_map(i);
132
133
134 spin_lock_irqsave(&desc->lock, flags);
135 spin_lock(&sb1250_imr_lock);
136
137
138 old_cpu = sb1250_irq_owner[irq];
139 cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(old_cpu) +
140 R_IMR_INTERRUPT_MASK));
141 int_on = !(cur_ints & (((u64) 1) << irq));
142 if (int_on) {
143
144 cur_ints |= (((u64) 1) << irq);
145 ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(old_cpu) +
146 R_IMR_INTERRUPT_MASK));
147 }
148 sb1250_irq_owner[irq] = cpu;
149 if (int_on) {
150
151 cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
152 R_IMR_INTERRUPT_MASK));
153 cur_ints &= ~(((u64) 1) << irq);
154 ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
155 R_IMR_INTERRUPT_MASK));
156 }
157 spin_unlock(&sb1250_imr_lock);
158 spin_unlock_irqrestore(&desc->lock, flags);
159}
160#endif
161
162
163
164static void disable_sb1250_irq(unsigned int irq)
165{
166 sb1250_mask_irq(sb1250_irq_owner[irq], irq);
167}
168
169static void enable_sb1250_irq(unsigned int irq)
170{
171 sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
172}
173
174
175static void ack_sb1250_irq(unsigned int irq)
176{
177#ifdef CONFIG_SIBYTE_HAS_LDT
178 u64 pending;
179
180
181
182
183
184
185
186 pending = __raw_readq(IOADDR(A_IMR_REGISTER(sb1250_irq_owner[irq],
187 R_IMR_LDT_INTERRUPT)));
188 pending &= ((u64)1 << (irq));
189 if (pending) {
190 int i;
191 for (i=0; i<NR_CPUS; i++) {
192 int cpu;
193#ifdef CONFIG_SMP
194 cpu = cpu_logical_map(i);
195#else
196 cpu = i;
197#endif
198
199
200
201
202 __raw_writeq(pending,
203 IOADDR(A_IMR_REGISTER(cpu,
204 R_IMR_LDT_INTERRUPT_CLR)));
205 }
206
207
208
209
210
211
212
213 *(uint32_t *)(ldt_eoi_space+(irq<<16)+(7<<2)) = 0;
214 }
215#endif
216 sb1250_mask_irq(sb1250_irq_owner[irq], irq);
217}
218
219
220static void end_sb1250_irq(unsigned int irq)
221{
222 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
223 sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
224 }
225}
226
227
228void __init init_sb1250_irqs(void)
229{
230 int i;
231
232 for (i = 0; i < SB1250_NR_IRQS; i++) {
233 set_irq_chip(i, &sb1250_irq_type);
234 sb1250_irq_owner[i] = 0;
235 }
236}
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259#define IMR_IP2_VAL K_INT_MAP_I0
260#define IMR_IP3_VAL K_INT_MAP_I1
261#define IMR_IP4_VAL K_INT_MAP_I2
262#define IMR_IP5_VAL K_INT_MAP_I3
263#define IMR_IP6_VAL K_INT_MAP_I4
264
265void __init arch_init_irq(void)
266{
267
268 unsigned int i;
269 u64 tmp;
270 unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
271 STATUSF_IP1 | STATUSF_IP0;
272
273
274 for (i = 0; i < SB1250_NR_IRQS; i++) {
275 __raw_writeq(IMR_IP2_VAL,
276 IOADDR(A_IMR_REGISTER(0,
277 R_IMR_INTERRUPT_MAP_BASE) +
278 (i << 3)));
279 __raw_writeq(IMR_IP2_VAL,
280 IOADDR(A_IMR_REGISTER(1,
281 R_IMR_INTERRUPT_MAP_BASE) +
282 (i << 3)));
283 }
284
285 init_sb1250_irqs();
286
287
288
289
290
291
292 __raw_writeq(IMR_IP3_VAL,
293 IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
294 (K_INT_MBOX_0 << 3)));
295 __raw_writeq(IMR_IP3_VAL,
296 IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MAP_BASE) +
297 (K_INT_MBOX_0 << 3)));
298
299
300 __raw_writeq(0xffffffffffffffffULL,
301 IOADDR(A_IMR_REGISTER(0, R_IMR_MAILBOX_CLR_CPU)));
302 __raw_writeq(0xffffffffffffffffULL,
303 IOADDR(A_IMR_REGISTER(1, R_IMR_MAILBOX_CLR_CPU)));
304
305
306 tmp = ~((u64) 0) ^ (((u64) 1) << K_INT_MBOX_0);
307 __raw_writeq(tmp, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MASK)));
308 __raw_writeq(tmp, IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MASK)));
309
310
311
312
313
314
315
316#ifdef CONFIG_KGDB
317 imask |= STATUSF_IP6;
318#endif
319
320 change_c0_status(ST0_IM, imask);
321
322#ifdef CONFIG_KGDB
323 if (kgdb_flag) {
324 kgdb_irq = K_INT_UART_0 + kgdb_port;
325
326#ifdef CONFIG_SERIAL_SB1250_DUART
327 sb1250_duart_present[kgdb_port] = 0;
328#endif
329
330 __raw_writeq(M_DUART_IMR_BRK,
331 IOADDR(A_DUART_IMRREG(kgdb_port)));
332
333 __raw_writeq(IMR_IP6_VAL,
334 IOADDR(A_IMR_REGISTER(0,
335 R_IMR_INTERRUPT_MAP_BASE) +
336 (kgdb_irq << 3)));
337 sb1250_unmask_irq(0, kgdb_irq);
338 }
339#endif
340}
341
342#ifdef CONFIG_KGDB
343
344#include <linux/delay.h>
345
346#define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port, reg)))
347#define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port, reg)))
348
349static void sb1250_kgdb_interrupt(void)
350{
351
352
353
354
355
356 kstat_this_cpu.irqs[kgdb_irq]++;
357 mdelay(500);
358 duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
359 M_DUART_RX_EN | M_DUART_TX_EN);
360 set_async_breakpoint(&get_irq_regs()->cp0_epc);
361}
362
363#endif
364
365extern void sb1250_mailbox_interrupt(void);
366
367static inline void dispatch_ip2(void)
368{
369 unsigned int cpu = smp_processor_id();
370 unsigned long long mask;
371
372
373
374
375
376
377 mask = __raw_readq(IOADDR(A_IMR_REGISTER(cpu,
378 R_IMR_INTERRUPT_STATUS_BASE)));
379 if (mask)
380 do_IRQ(fls64(mask) - 1);
381}
382
383asmlinkage void plat_irq_dispatch(void)
384{
385 unsigned int cpu = smp_processor_id();
386 unsigned int pending;
387
388
389
390
391
392
393
394
395
396
397
398 pending = read_c0_cause() & read_c0_status() & ST0_IM;
399
400 if (pending & CAUSEF_IP7)
401 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
402 else if (pending & CAUSEF_IP4)
403 do_IRQ(K_INT_TIMER_0 + cpu);
404
405#ifdef CONFIG_SMP
406 else if (pending & CAUSEF_IP3)
407 sb1250_mailbox_interrupt();
408#endif
409
410#ifdef CONFIG_KGDB
411 else if (pending & CAUSEF_IP6)
412 sb1250_kgdb_interrupt();
413#endif
414
415 else if (pending & CAUSEF_IP2)
416 dispatch_ip2();
417 else
418 spurious_interrupt();
419}
420