blob: 373fbbc8425c5494461d581f32bdb994c05068d9 [file] [log] [blame]
Andrew Isaacsonf137e462005-10-19 23:56:38 -07001/*
2 * Copyright (C) 2000,2001,2002,2003,2004 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
Andrew Isaacsonf137e462005-10-19 23:56:38 -070018#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/linkage.h>
21#include <linux/interrupt.h>
Ralf Baechle631330f2009-06-19 14:05:26 +010022#include <linux/smp.h>
Andrew Isaacsonf137e462005-10-19 23:56:38 -070023#include <linux/spinlock.h>
24#include <linux/mm.h>
Andrew Isaacsonf137e462005-10-19 23:56:38 -070025#include <linux/kernel_stat.h>
26
27#include <asm/errno.h>
Ralf Baechle937a8012006-10-07 19:44:33 +010028#include <asm/irq_regs.h>
Andrew Isaacsonf137e462005-10-19 23:56:38 -070029#include <asm/signal.h>
Andrew Isaacsonf137e462005-10-19 23:56:38 -070030#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 * These are the routines that handle all the low level interrupt stuff.
41 * Actions handled here are: initialization of the interrupt map, requesting of
42 * interrupt lines by handlers, dispatching if interrupts to handlers, probing
43 * for interrupt lines
44 */
45
Andrew Isaacsonf137e462005-10-19 23:56:38 -070046#ifdef CONFIG_PCI
47extern unsigned long ht_eoi_space;
48#endif
49
Andrew Isaacsonf137e462005-10-19 23:56:38 -070050/* Store the CPU id (not the logical number) */
51int bcm1480_irq_owner[BCM1480_NR_IRQS];
52
Ralf Baechleed14bbb2010-02-27 12:53:32 +010053static DEFINE_RAW_SPINLOCK(bcm1480_imr_lock);
Andrew Isaacsonf137e462005-10-19 23:56:38 -070054
55void bcm1480_mask_irq(int cpu, int irq)
56{
Ralf Baechlefbd0ed32007-08-29 00:38:13 +010057 unsigned long flags, hl_spacing;
58 u64 cur_ints;
Andrew Isaacsonf137e462005-10-19 23:56:38 -070059
Ralf Baechleed14bbb2010-02-27 12:53:32 +010060 raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
Andrew Isaacsonf137e462005-10-19 23:56:38 -070061 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));
Ralf Baechleed14bbb2010-02-27 12:53:32 +010069 raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
Andrew Isaacsonf137e462005-10-19 23:56:38 -070070}
71
72void bcm1480_unmask_irq(int cpu, int irq)
73{
Ralf Baechlefbd0ed32007-08-29 00:38:13 +010074 unsigned long flags, hl_spacing;
75 u64 cur_ints;
Andrew Isaacsonf137e462005-10-19 23:56:38 -070076
Ralf Baechleed14bbb2010-02-27 12:53:32 +010077 raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
Andrew Isaacsonf137e462005-10-19 23:56:38 -070078 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));
Ralf Baechleed14bbb2010-02-27 12:53:32 +010086 raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
Andrew Isaacsonf137e462005-10-19 23:56:38 -070087}
88
89#ifdef CONFIG_SMP
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +000090static int bcm1480_set_affinity(struct irq_data *d, const struct cpumask *mask,
91 bool force)
Andrew Isaacsonf137e462005-10-19 23:56:38 -070092{
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +000093 unsigned int irq_dirty, irq = d->irq;
Martin Michlmayr76e1dae2006-02-20 04:57:00 +000094 int i = 0, old_cpu, cpu, int_on, k;
Andrew Isaacsonf137e462005-10-19 23:56:38 -070095 u64 cur_ints;
Andrew Isaacsonf137e462005-10-19 23:56:38 -070096 unsigned long flags;
Andrew Isaacsonf137e462005-10-19 23:56:38 -070097
Thomas Gleixner421d1562014-03-04 20:43:39 +000098 i = cpumask_first_and(mask, cpu_online_mask);
Andrew Isaacsonf137e462005-10-19 23:56:38 -070099
100 /* Convert logical CPU to physical CPU */
101 cpu = cpu_logical_map(i);
102
103 /* Protect against other affinity changers and IMR manipulation */
Ralf Baechleed14bbb2010-02-27 12:53:32 +0100104 raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700105
106 /* Swizzle each CPU's IMR (but leave the IP selection alone) */
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
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700113 for (k=0; k<2; k++) { /* Loop through high and low interrupt mask register */
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 /* If it was on, mask it */
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 /* unmask for the new CPU */
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 }
Ralf Baechleed14bbb2010-02-27 12:53:32 +0100129 raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
Yinghai Lud5dedd42009-04-27 17:59:21 -0700130
131 return 0;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700132}
133#endif
134
135
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700136/*****************************************************************************/
137
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +0000138static void disable_bcm1480_irq(struct irq_data *d)
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700139{
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +0000140 unsigned int irq = d->irq;
141
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700142 bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
143}
144
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +0000145static void enable_bcm1480_irq(struct irq_data *d)
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700146{
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +0000147 unsigned int irq = d->irq;
148
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700149 bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
150}
151
152
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +0000153static void ack_bcm1480_irq(struct irq_data *d)
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700154{
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +0000155 unsigned int irq_dirty, irq = d->irq;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700156 u64 pending;
Martin Michlmayr76e1dae2006-02-20 04:57:00 +0000157 int k;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700158
159 /*
160 * If the interrupt was an HT interrupt, now is the time to
161 * clear it. NOTE: we assume the HT bridge was set up to
162 * deliver the interrupts to all CPUs (which makes affinity
163 * changing easier for us)
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 }
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700169 for (k=0; k<2; k++) { /* Loop through high and low LDT interrupts */
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 * Clear for all CPUs so an affinity switch
179 * doesn't find an old status
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 * Generate EOI. For Pass 1 parts, EOI is a nop. For
190 * Pass 2, the LDT world may be edge-triggered, but
191 * this EOI shouldn't hurt. If they are
192 * level-sensitive, the EOI is required.
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
Thomas Gleixnerd6d5d5c42011-03-23 21:09:14 +0000203static 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};
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700212
213void __init init_bcm1480_irqs(void)
214{
215 int i;
216
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +0900217 for (i = 0; i < BCM1480_NR_IRQS; i++) {
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200218 irq_set_chip_and_handler(i, &bcm1480_irq_type,
219 handle_level_irq);
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +0900220 bcm1480_irq_owner[i] = 0;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700221 }
222}
223
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700224/*
225 * init_IRQ is called early in the boot sequence from init/main.c. It
226 * is responsible for setting up the interrupt mapper and installing the
227 * handler that will be responsible for dispatching interrupts to the
228 * "right" place.
229 */
230/*
231 * For now, map all interrupts to IP[2]. We could save
232 * some cycles by parceling out system interrupts to different
233 * IP lines, but keep it simple for bringup. We'll also direct
234 * all interrupts to a single CPU; we should probably route
235 * PCI and LDT to one cpu and everything else to the other
236 * to balance the load a bit.
237 *
238 * On the second cpu, everything is set to IP5, which is
239 * ignored, EXCEPT the mailbox interrupt. That one is
240 * set to IP[2] so it is handled. This is needed so we
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200241 * can do cross-cpu function calls, as required by SMP
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700242 */
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{
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700252 unsigned int i, cpu;
253 u64 tmp;
254 unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
255 STATUSF_IP1 | STATUSF_IP0;
256
257 /* Default everything to IP2 */
258 /* Start with _high registers which has no bit 0 interrupt source */
259 for (i = 1; i < BCM1480_NR_IRQS_HALF; i++) { /* was I0 */
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 /* Now do _low registers */
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 * Map the high 16 bits of mailbox_0 registers to IP[3], for
280 * inter-cpu messages
281 */
282 /* Was I1 */
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)));
Ralf Baechle70342282013-01-22 12:59:30 +0100286 }
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700287
288
Ralf Baechle70342282013-01-22 12:59:30 +0100289 /* Clear the mailboxes. The firmware may leave them dirty */
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700290 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 /* Mask everything except the high 16 bit of mailbox_0 registers for all cpus */
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
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700308 /*
309 * Note that the timer interrupts are also mapped, but this is
Ralf Baechle70342282013-01-22 12:59:30 +0100310 * done in bcm1480_time_init(). Also, the profiling driver
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700311 * does its own management of IP7.
312 */
313
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700314 /* Enable necessary IPs, disable the rest */
315 change_c0_status(ST0_IM, imask);
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700316}
317
Ralf Baechle937a8012006-10-07 19:44:33 +0100318extern void bcm1480_mailbox_interrupt(void);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100319
Ralf Baechled0453362007-10-22 10:38:44 +0100320static 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 * Default...we've hit an IP[2] interrupt, which means we've got to
Ralf Baechle70342282013-01-22 12:59:30 +0100328 * check the 1480 interrupt registers to figure out what to do. Need
Ralf Baechled0453362007-10-22 10:38:44 +0100329 * to detect which CPU we're on, now that smp_affinity is supported.
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
Ralf Baechle937a8012006-10-07 19:44:33 +0100345asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100346{
Ralf Baechlea8401fa2007-11-05 00:29:45 +0000347 unsigned int cpu = smp_processor_id();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100348 unsigned int pending;
349
Ralf Baechle34c2dd02006-10-03 14:42:02 +0100350 pending = read_c0_cause() & read_c0_status();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100351
Ralf Baechled0453362007-10-22 10:38:44 +0100352 if (pending & CAUSEF_IP4)
Ralf Baechlea8401fa2007-11-05 00:29:45 +0000353 do_IRQ(K_BCM1480_INT_TIMER_0 + cpu);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100354#ifdef CONFIG_SMP
Thiemo Seufer6e61e852006-07-05 14:26:38 +0100355 else if (pending & CAUSEF_IP3)
Ralf Baechle937a8012006-10-07 19:44:33 +0100356 bcm1480_mailbox_interrupt();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100357#endif
358
Ralf Baechled0453362007-10-22 10:38:44 +0100359 else if (pending & CAUSEF_IP2)
360 dispatch_ip2();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100361}