1
2
3
4
5#include <linux/kernel.h>
6#include <linux/init.h>
7#include <linux/linkage.h>
8#include <linux/interrupt.h>
9#include <linux/spinlock.h>
10#include <linux/smp.h>
11#include <linux/mm.h>
12#include <linux/kernel_stat.h>
13
14#include <asm/errno.h>
15#include <asm/signal.h>
16#include <asm/time.h>
17#include <asm/io.h>
18
19#include <asm/sibyte/sb1250_regs.h>
20#include <asm/sibyte/sb1250_int.h>
21#include <asm/sibyte/sb1250_uart.h>
22#include <asm/sibyte/sb1250_scd.h>
23#include <asm/sibyte/sb1250.h>
24
25
26
27
28
29
30
31
32#ifdef CONFIG_SIBYTE_HAS_LDT
33extern unsigned long ldt_eoi_space;
34#endif
35
36
37int sb1250_irq_owner[SB1250_NR_IRQS];
38
39static DEFINE_RAW_SPINLOCK(sb1250_imr_lock);
40
41void sb1250_mask_irq(int cpu, int irq)
42{
43 unsigned long flags;
44 u64 cur_ints;
45
46 raw_spin_lock_irqsave(&sb1250_imr_lock, flags);
47 cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
48 R_IMR_INTERRUPT_MASK));
49 cur_ints |= (((u64) 1) << irq);
50 ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
51 R_IMR_INTERRUPT_MASK));
52 raw_spin_unlock_irqrestore(&sb1250_imr_lock, flags);
53}
54
55void sb1250_unmask_irq(int cpu, int irq)
56{
57 unsigned long flags;
58 u64 cur_ints;
59
60 raw_spin_lock_irqsave(&sb1250_imr_lock, flags);
61 cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
62 R_IMR_INTERRUPT_MASK));
63 cur_ints &= ~(((u64) 1) << irq);
64 ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
65 R_IMR_INTERRUPT_MASK));
66 raw_spin_unlock_irqrestore(&sb1250_imr_lock, flags);
67}
68
69#ifdef CONFIG_SMP
70static int sb1250_set_affinity(struct irq_data *d, const struct cpumask *mask,
71 bool force)
72{
73 int i = 0, old_cpu, cpu, int_on;
74 unsigned int irq = d->irq;
75 u64 cur_ints;
76 unsigned long flags;
77
78 i = cpumask_first_and(mask, cpu_online_mask);
79
80
81 cpu = cpu_logical_map(i);
82
83
84 raw_spin_lock_irqsave(&sb1250_imr_lock, flags);
85
86
87 old_cpu = sb1250_irq_owner[irq];
88 cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(old_cpu) +
89 R_IMR_INTERRUPT_MASK));
90 int_on = !(cur_ints & (((u64) 1) << irq));
91 if (int_on) {
92
93 cur_ints |= (((u64) 1) << irq);
94 ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(old_cpu) +
95 R_IMR_INTERRUPT_MASK));
96 }
97 sb1250_irq_owner[irq] = cpu;
98 if (int_on) {
99
100 cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
101 R_IMR_INTERRUPT_MASK));
102 cur_ints &= ~(((u64) 1) << irq);
103 ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
104 R_IMR_INTERRUPT_MASK));
105 }
106 raw_spin_unlock_irqrestore(&sb1250_imr_lock, flags);
107
108 return 0;
109}
110#endif
111
112static void disable_sb1250_irq(struct irq_data *d)
113{
114 unsigned int irq = d->irq;
115
116 sb1250_mask_irq(sb1250_irq_owner[irq], irq);
117}
118
119static void enable_sb1250_irq(struct irq_data *d)
120{
121 unsigned int irq = d->irq;
122
123 sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
124}
125
126
127static void ack_sb1250_irq(struct irq_data *d)
128{
129 unsigned int irq = d->irq;
130#ifdef CONFIG_SIBYTE_HAS_LDT
131 u64 pending;
132
133
134
135
136
137
138
139 pending = __raw_readq(IOADDR(A_IMR_REGISTER(sb1250_irq_owner[irq],
140 R_IMR_LDT_INTERRUPT)));
141 pending &= ((u64)1 << (irq));
142 if (pending) {
143 int i;
144 for (i=0; i<NR_CPUS; i++) {
145 int cpu;
146#ifdef CONFIG_SMP
147 cpu = cpu_logical_map(i);
148#else
149 cpu = i;
150#endif
151
152
153
154
155 __raw_writeq(pending,
156 IOADDR(A_IMR_REGISTER(cpu,
157 R_IMR_LDT_INTERRUPT_CLR)));
158 }
159
160
161
162
163
164
165
166 *(uint32_t *)(ldt_eoi_space+(irq<<16)+(7<<2)) = 0;
167 }
168#endif
169 sb1250_mask_irq(sb1250_irq_owner[irq], irq);
170}
171
172static struct irq_chip sb1250_irq_type = {
173 .name = "SB1250-IMR",
174 .irq_mask_ack = ack_sb1250_irq,
175 .irq_unmask = enable_sb1250_irq,
176 .irq_mask = disable_sb1250_irq,
177#ifdef CONFIG_SMP
178 .irq_set_affinity = sb1250_set_affinity
179#endif
180};
181
182void __init init_sb1250_irqs(void)
183{
184 int i;
185
186 for (i = 0; i < SB1250_NR_IRQS; i++) {
187 irq_set_chip_and_handler(i, &sb1250_irq_type,
188 handle_level_irq);
189 sb1250_irq_owner[i] = 0;
190 }
191}
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214#define IMR_IP2_VAL K_INT_MAP_I0
215#define IMR_IP3_VAL K_INT_MAP_I1
216#define IMR_IP4_VAL K_INT_MAP_I2
217#define IMR_IP5_VAL K_INT_MAP_I3
218#define IMR_IP6_VAL K_INT_MAP_I4
219
220void __init arch_init_irq(void)
221{
222
223 unsigned int i;
224 u64 tmp;
225 unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
226 STATUSF_IP1 | STATUSF_IP0;
227
228
229 for (i = 0; i < SB1250_NR_IRQS; i++) {
230 __raw_writeq(IMR_IP2_VAL,
231 IOADDR(A_IMR_REGISTER(0,
232 R_IMR_INTERRUPT_MAP_BASE) +
233 (i << 3)));
234 __raw_writeq(IMR_IP2_VAL,
235 IOADDR(A_IMR_REGISTER(1,
236 R_IMR_INTERRUPT_MAP_BASE) +
237 (i << 3)));
238 }
239
240 init_sb1250_irqs();
241
242
243
244
245
246
247 __raw_writeq(IMR_IP3_VAL,
248 IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
249 (K_INT_MBOX_0 << 3)));
250 __raw_writeq(IMR_IP3_VAL,
251 IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MAP_BASE) +
252 (K_INT_MBOX_0 << 3)));
253
254
255 __raw_writeq(0xffffffffffffffffULL,
256 IOADDR(A_IMR_REGISTER(0, R_IMR_MAILBOX_CLR_CPU)));
257 __raw_writeq(0xffffffffffffffffULL,
258 IOADDR(A_IMR_REGISTER(1, R_IMR_MAILBOX_CLR_CPU)));
259
260
261 tmp = ~((u64) 0) ^ (((u64) 1) << K_INT_MBOX_0);
262 __raw_writeq(tmp, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MASK)));
263 __raw_writeq(tmp, IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MASK)));
264
265
266
267
268
269
270
271
272 change_c0_status(ST0_IM, imask);
273}
274
275extern void sb1250_mailbox_interrupt(void);
276
277static inline void dispatch_ip2(void)
278{
279 unsigned int cpu = smp_processor_id();
280 unsigned long long mask;
281
282
283
284
285
286
287 mask = __raw_readq(IOADDR(A_IMR_REGISTER(cpu,
288 R_IMR_INTERRUPT_STATUS_BASE)));
289 if (mask)
290 do_IRQ(fls64(mask) - 1);
291}
292
293asmlinkage void plat_irq_dispatch(void)
294{
295 unsigned int cpu = smp_processor_id();
296 unsigned int pending;
297
298
299
300
301
302
303
304
305
306
307
308 pending = read_c0_cause() & read_c0_status() & ST0_IM;
309
310 if (pending & CAUSEF_IP7)
311 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
312 else if (pending & CAUSEF_IP4)
313 do_IRQ(K_INT_TIMER_0 + cpu);
314
315#ifdef CONFIG_SMP
316 else if (pending & CAUSEF_IP3)
317 sb1250_mailbox_interrupt();
318#endif
319
320 else if (pending & CAUSEF_IP2)
321 dispatch_ip2();
322 else
323 spurious_interrupt();
324}
325