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/smp.h>
23#include <linux/spinlock.h>
24#include <linux/mm.h>
25#include <linux/kernel_stat.h>
26
27#include <asm/errno.h>
28#include <asm/irq_regs.h>
29#include <asm/signal.h>
30#include <asm/io.h>
31
32#include <asm/sibyte/bcm1480_regs.h>
33#include <asm/sibyte/bcm1480_int.h>
34#include <asm/sibyte/bcm1480_scd.h>
35
36#include <asm/sibyte/sb1250_uart.h>
37#include <asm/sibyte/sb1250.h>
38
39
40
41
42
43
44
45
46#ifdef CONFIG_PCI
47extern unsigned long ht_eoi_space;
48#endif
49
50
51int bcm1480_irq_owner[BCM1480_NR_IRQS];
52
53static DEFINE_RAW_SPINLOCK(bcm1480_imr_lock);
54
55void bcm1480_mask_irq(int cpu, int irq)
56{
57 unsigned long flags, hl_spacing;
58 u64 cur_ints;
59
60 raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
61 hl_spacing = 0;
62 if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
63 hl_spacing = BCM1480_IMR_HL_SPACING;
64 irq -= BCM1480_NR_IRQS_HALF;
65 }
66 cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
67 cur_ints |= (((u64) 1) << irq);
68 ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
69 raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
70}
71
72void bcm1480_unmask_irq(int cpu, int irq)
73{
74 unsigned long flags, hl_spacing;
75 u64 cur_ints;
76
77 raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
78 hl_spacing = 0;
79 if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
80 hl_spacing = BCM1480_IMR_HL_SPACING;
81 irq -= BCM1480_NR_IRQS_HALF;
82 }
83 cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
84 cur_ints &= ~(((u64) 1) << irq);
85 ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
86 raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
87}
88
89#ifdef CONFIG_SMP
90static int bcm1480_set_affinity(struct irq_data *d, const struct cpumask *mask,
91 bool force)
92{
93 unsigned int irq_dirty, irq = d->irq;
94 int i = 0, old_cpu, cpu, int_on, k;
95 u64 cur_ints;
96 unsigned long flags;
97
98 i = cpumask_first_and(mask, cpu_online_mask);
99
100
101 cpu = cpu_logical_map(i);
102
103
104 raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
105
106
107 old_cpu = bcm1480_irq_owner[irq];
108 irq_dirty = irq;
109 if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
110 irq_dirty -= BCM1480_NR_IRQS_HALF;
111 }
112
113 for (k=0; k<2; k++) {
114 cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
115 int_on = !(cur_ints & (((u64) 1) << irq_dirty));
116 if (int_on) {
117
118 cur_ints |= (((u64) 1) << irq_dirty);
119 ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
120 }
121 bcm1480_irq_owner[irq] = cpu;
122 if (int_on) {
123
124 cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
125 cur_ints &= ~(((u64) 1) << irq_dirty);
126 ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
127 }
128 }
129 raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
130
131 return 0;
132}
133#endif
134
135
136
137
138static void disable_bcm1480_irq(struct irq_data *d)
139{
140 unsigned int irq = d->irq;
141
142 bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
143}
144
145static void enable_bcm1480_irq(struct irq_data *d)
146{
147 unsigned int irq = d->irq;
148
149 bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
150}
151
152
153static void ack_bcm1480_irq(struct irq_data *d)
154{
155 unsigned int irq_dirty, irq = d->irq;
156 u64 pending;
157 int k;
158
159
160
161
162
163
164
165 irq_dirty = irq;
166 if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
167 irq_dirty -= BCM1480_NR_IRQS_HALF;
168 }
169 for (k=0; k<2; k++) {
170 pending = __raw_readq(IOADDR(A_BCM1480_IMR_REGISTER(bcm1480_irq_owner[irq],
171 R_BCM1480_IMR_LDT_INTERRUPT_H + (k*BCM1480_IMR_HL_SPACING))));
172 pending &= ((u64)1 << (irq_dirty));
173 if (pending) {
174#ifdef CONFIG_SMP
175 int i;
176 for (i=0; i<NR_CPUS; i++) {
177
178
179
180
181 __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(cpu_logical_map(i),
182 R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
183 }
184#else
185 __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(0, R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
186#endif
187
188
189
190
191
192
193
194#ifdef CONFIG_PCI
195 if (ht_eoi_space)
196 *(uint32_t *)(ht_eoi_space+(irq<<16)+(7<<2)) = 0;
197#endif
198 }
199 }
200 bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
201}
202
203static struct irq_chip bcm1480_irq_type = {
204 .name = "BCM1480-IMR",
205 .irq_mask_ack = ack_bcm1480_irq,
206 .irq_mask = disable_bcm1480_irq,
207 .irq_unmask = enable_bcm1480_irq,
208#ifdef CONFIG_SMP
209 .irq_set_affinity = bcm1480_set_affinity
210#endif
211};
212
213void __init init_bcm1480_irqs(void)
214{
215 int i;
216
217 for (i = 0; i < BCM1480_NR_IRQS; i++) {
218 irq_set_chip_and_handler(i, &bcm1480_irq_type,
219 handle_level_irq);
220 bcm1480_irq_owner[i] = 0;
221 }
222}
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244#define IMR_IP2_VAL K_BCM1480_INT_MAP_I0
245#define IMR_IP3_VAL K_BCM1480_INT_MAP_I1
246#define IMR_IP4_VAL K_BCM1480_INT_MAP_I2
247#define IMR_IP5_VAL K_BCM1480_INT_MAP_I3
248#define IMR_IP6_VAL K_BCM1480_INT_MAP_I4
249
250void __init arch_init_irq(void)
251{
252 unsigned int i, cpu;
253 u64 tmp;
254 unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
255 STATUSF_IP1 | STATUSF_IP0;
256
257
258
259 for (i = 1; i < BCM1480_NR_IRQS_HALF; i++) {
260 for (cpu = 0; cpu < 4; cpu++) {
261 __raw_writeq(IMR_IP2_VAL,
262 IOADDR(A_BCM1480_IMR_REGISTER(cpu,
263 R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) + (i << 3)));
264 }
265 }
266
267
268 for (i = 0; i < BCM1480_NR_IRQS_HALF; i++) {
269 for (cpu = 0; cpu < 4; cpu++) {
270 __raw_writeq(IMR_IP2_VAL,
271 IOADDR(A_BCM1480_IMR_REGISTER(cpu,
272 R_BCM1480_IMR_INTERRUPT_MAP_BASE_L) + (i << 3)));
273 }
274 }
275
276 init_bcm1480_irqs();
277
278
279
280
281
282
283 for (cpu = 0; cpu < 4; cpu++) {
284 __raw_writeq(IMR_IP3_VAL, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
285 (K_BCM1480_INT_MBOX_0_0 << 3)));
286 }
287
288
289
290 for (cpu = 0; cpu < 4; cpu++) {
291 __raw_writeq(0xffffffffffffffffULL,
292 IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_0_CLR_CPU)));
293 __raw_writeq(0xffffffffffffffffULL,
294 IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_1_CLR_CPU)));
295 }
296
297
298
299 tmp = ~((u64) 0) ^ ( (((u64) 1) << K_BCM1480_INT_MBOX_0_0));
300 for (cpu = 0; cpu < 4; cpu++) {
301 __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_H)));
302 }
303 tmp = ~((u64) 0);
304 for (cpu = 0; cpu < 4; cpu++) {
305 __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_L)));
306 }
307
308
309
310
311
312
313
314
315 change_c0_status(ST0_IM, imask);
316}
317
318extern void bcm1480_mailbox_interrupt(void);
319
320static inline void dispatch_ip2(void)
321{
322 unsigned long long mask_h, mask_l;
323 unsigned int cpu = smp_processor_id();
324 unsigned long base;
325
326
327
328
329
330
331 base = A_BCM1480_IMR_MAPPER(cpu);
332 mask_h = __raw_readq(
333 IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_H));
334 mask_l = __raw_readq(
335 IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_L));
336
337 if (mask_h) {
338 if (mask_h ^ 1)
339 do_IRQ(fls64(mask_h) - 1);
340 else if (mask_l)
341 do_IRQ(63 + fls64(mask_l));
342 }
343}
344
345asmlinkage void plat_irq_dispatch(void)
346{
347 unsigned int cpu = smp_processor_id();
348 unsigned int pending;
349
350 pending = read_c0_cause() & read_c0_status();
351
352 if (pending & CAUSEF_IP4)
353 do_IRQ(K_BCM1480_INT_TIMER_0 + cpu);
354#ifdef CONFIG_SMP
355 else if (pending & CAUSEF_IP3)
356 bcm1480_mailbox_interrupt();
357#endif
358
359 else if (pending & CAUSEF_IP2)
360 dispatch_ip2();
361}
362