blob: 4070268aa769826c46bb3c5328f398a71abc0283 [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>
25#include <linux/slab.h>
26#include <linux/kernel_stat.h>
27
28#include <asm/errno.h>
Ralf Baechle937a8012006-10-07 19:44:33 +010029#include <asm/irq_regs.h>
Andrew Isaacsonf137e462005-10-19 23:56:38 -070030#include <asm/signal.h>
31#include <asm/system.h>
Andrew Isaacsonf137e462005-10-19 23:56:38 -070032#include <asm/io.h>
33
34#include <asm/sibyte/bcm1480_regs.h>
35#include <asm/sibyte/bcm1480_int.h>
36#include <asm/sibyte/bcm1480_scd.h>
37
38#include <asm/sibyte/sb1250_uart.h>
39#include <asm/sibyte/sb1250.h>
40
41/*
42 * These are the routines that handle all the low level interrupt stuff.
43 * Actions handled here are: initialization of the interrupt map, requesting of
44 * interrupt lines by handlers, dispatching if interrupts to handlers, probing
45 * for interrupt lines
46 */
47
48
Andrew Isaacsonf137e462005-10-19 23:56:38 -070049static void end_bcm1480_irq(unsigned int irq);
50static void enable_bcm1480_irq(unsigned int irq);
51static void disable_bcm1480_irq(unsigned int irq);
Andrew Isaacsonf137e462005-10-19 23:56:38 -070052static void ack_bcm1480_irq(unsigned int irq);
53#ifdef CONFIG_SMP
Yinghai Lud5dedd42009-04-27 17:59:21 -070054static int bcm1480_set_affinity(unsigned int irq, const struct cpumask *mask);
Andrew Isaacsonf137e462005-10-19 23:56:38 -070055#endif
56
57#ifdef CONFIG_PCI
58extern unsigned long ht_eoi_space;
59#endif
60
Ralf Baechle94dee172006-07-02 14:41:42 +010061static struct irq_chip bcm1480_irq_type = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +090062 .name = "BCM1480-IMR",
Andrew Isaacsonf137e462005-10-19 23:56:38 -070063 .ack = ack_bcm1480_irq,
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +090064 .mask = disable_bcm1480_irq,
65 .mask_ack = ack_bcm1480_irq,
66 .unmask = enable_bcm1480_irq,
Andrew Isaacsonf137e462005-10-19 23:56:38 -070067 .end = end_bcm1480_irq,
68#ifdef CONFIG_SMP
69 .set_affinity = bcm1480_set_affinity
70#endif
71};
72
73/* Store the CPU id (not the logical number) */
74int bcm1480_irq_owner[BCM1480_NR_IRQS];
75
76DEFINE_SPINLOCK(bcm1480_imr_lock);
77
78void bcm1480_mask_irq(int cpu, int irq)
79{
Ralf Baechlefbd0ed32007-08-29 00:38:13 +010080 unsigned long flags, hl_spacing;
81 u64 cur_ints;
Andrew Isaacsonf137e462005-10-19 23:56:38 -070082
83 spin_lock_irqsave(&bcm1480_imr_lock, flags);
84 hl_spacing = 0;
85 if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
86 hl_spacing = BCM1480_IMR_HL_SPACING;
87 irq -= BCM1480_NR_IRQS_HALF;
88 }
89 cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
90 cur_ints |= (((u64) 1) << irq);
91 ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
92 spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
93}
94
95void bcm1480_unmask_irq(int cpu, int irq)
96{
Ralf Baechlefbd0ed32007-08-29 00:38:13 +010097 unsigned long flags, hl_spacing;
98 u64 cur_ints;
Andrew Isaacsonf137e462005-10-19 23:56:38 -070099
100 spin_lock_irqsave(&bcm1480_imr_lock, flags);
101 hl_spacing = 0;
102 if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
103 hl_spacing = BCM1480_IMR_HL_SPACING;
104 irq -= BCM1480_NR_IRQS_HALF;
105 }
106 cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
107 cur_ints &= ~(((u64) 1) << irq);
108 ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
109 spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
110}
111
112#ifdef CONFIG_SMP
Yinghai Lud5dedd42009-04-27 17:59:21 -0700113static int bcm1480_set_affinity(unsigned int irq, const struct cpumask *mask)
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700114{
Martin Michlmayr76e1dae2006-02-20 04:57:00 +0000115 int i = 0, old_cpu, cpu, int_on, k;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700116 u64 cur_ints;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700117 unsigned long flags;
118 unsigned int irq_dirty;
119
Rusty Russell0de26522008-12-13 21:20:26 +1030120 i = cpumask_first(mask);
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700121
122 /* Convert logical CPU to physical CPU */
123 cpu = cpu_logical_map(i);
124
125 /* Protect against other affinity changers and IMR manipulation */
Thomas Bogendoerfer5d81b832009-05-04 23:51:54 +0200126 spin_lock_irqsave(&bcm1480_imr_lock, flags);
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700127
128 /* Swizzle each CPU's IMR (but leave the IP selection alone) */
129 old_cpu = bcm1480_irq_owner[irq];
130 irq_dirty = irq;
131 if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
132 irq_dirty -= BCM1480_NR_IRQS_HALF;
133 }
134
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700135 for (k=0; k<2; k++) { /* Loop through high and low interrupt mask register */
136 cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
137 int_on = !(cur_ints & (((u64) 1) << irq_dirty));
138 if (int_on) {
139 /* If it was on, mask it */
140 cur_ints |= (((u64) 1) << irq_dirty);
141 ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
142 }
143 bcm1480_irq_owner[irq] = cpu;
144 if (int_on) {
145 /* unmask for the new CPU */
146 cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
147 cur_ints &= ~(((u64) 1) << irq_dirty);
148 ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
149 }
150 }
Thomas Bogendoerfer5d81b832009-05-04 23:51:54 +0200151 spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
Yinghai Lud5dedd42009-04-27 17:59:21 -0700152
153 return 0;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700154}
155#endif
156
157
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700158/*****************************************************************************/
159
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700160static void disable_bcm1480_irq(unsigned int irq)
161{
162 bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
163}
164
165static void enable_bcm1480_irq(unsigned int irq)
166{
167 bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
168}
169
170
171static void ack_bcm1480_irq(unsigned int irq)
172{
173 u64 pending;
174 unsigned int irq_dirty;
Martin Michlmayr76e1dae2006-02-20 04:57:00 +0000175 int k;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700176
177 /*
178 * If the interrupt was an HT interrupt, now is the time to
179 * clear it. NOTE: we assume the HT bridge was set up to
180 * deliver the interrupts to all CPUs (which makes affinity
181 * changing easier for us)
182 */
183 irq_dirty = irq;
184 if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
185 irq_dirty -= BCM1480_NR_IRQS_HALF;
186 }
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700187 for (k=0; k<2; k++) { /* Loop through high and low LDT interrupts */
188 pending = __raw_readq(IOADDR(A_BCM1480_IMR_REGISTER(bcm1480_irq_owner[irq],
189 R_BCM1480_IMR_LDT_INTERRUPT_H + (k*BCM1480_IMR_HL_SPACING))));
190 pending &= ((u64)1 << (irq_dirty));
191 if (pending) {
192#ifdef CONFIG_SMP
193 int i;
194 for (i=0; i<NR_CPUS; i++) {
195 /*
196 * Clear for all CPUs so an affinity switch
197 * doesn't find an old status
198 */
199 __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(cpu_logical_map(i),
200 R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
201 }
202#else
203 __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(0, R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
204#endif
205
206 /*
207 * Generate EOI. For Pass 1 parts, EOI is a nop. For
208 * Pass 2, the LDT world may be edge-triggered, but
209 * this EOI shouldn't hurt. If they are
210 * level-sensitive, the EOI is required.
211 */
212#ifdef CONFIG_PCI
213 if (ht_eoi_space)
214 *(uint32_t *)(ht_eoi_space+(irq<<16)+(7<<2)) = 0;
215#endif
216 }
217 }
218 bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
219}
220
221
222static void end_bcm1480_irq(unsigned int irq)
223{
224 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
225 bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
226 }
227}
228
229
230void __init init_bcm1480_irqs(void)
231{
232 int i;
233
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +0900234 for (i = 0; i < BCM1480_NR_IRQS; i++) {
Ralf Baechlec87e0902009-03-30 14:49:44 +0200235 set_irq_chip_and_handler(i, &bcm1480_irq_type, handle_level_irq);
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +0900236 bcm1480_irq_owner[i] = 0;
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700237 }
238}
239
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700240/*
241 * init_IRQ is called early in the boot sequence from init/main.c. It
242 * is responsible for setting up the interrupt mapper and installing the
243 * handler that will be responsible for dispatching interrupts to the
244 * "right" place.
245 */
246/*
247 * For now, map all interrupts to IP[2]. We could save
248 * some cycles by parceling out system interrupts to different
249 * IP lines, but keep it simple for bringup. We'll also direct
250 * all interrupts to a single CPU; we should probably route
251 * PCI and LDT to one cpu and everything else to the other
252 * to balance the load a bit.
253 *
254 * On the second cpu, everything is set to IP5, which is
255 * ignored, EXCEPT the mailbox interrupt. That one is
256 * set to IP[2] so it is handled. This is needed so we
257 * can do cross-cpu function calls, as requred by SMP
258 */
259
260#define IMR_IP2_VAL K_BCM1480_INT_MAP_I0
261#define IMR_IP3_VAL K_BCM1480_INT_MAP_I1
262#define IMR_IP4_VAL K_BCM1480_INT_MAP_I2
263#define IMR_IP5_VAL K_BCM1480_INT_MAP_I3
264#define IMR_IP6_VAL K_BCM1480_INT_MAP_I4
265
266void __init arch_init_irq(void)
267{
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700268 unsigned int i, cpu;
269 u64 tmp;
270 unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
271 STATUSF_IP1 | STATUSF_IP0;
272
273 /* Default everything to IP2 */
274 /* Start with _high registers which has no bit 0 interrupt source */
275 for (i = 1; i < BCM1480_NR_IRQS_HALF; i++) { /* was I0 */
276 for (cpu = 0; cpu < 4; cpu++) {
277 __raw_writeq(IMR_IP2_VAL,
278 IOADDR(A_BCM1480_IMR_REGISTER(cpu,
279 R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) + (i << 3)));
280 }
281 }
282
283 /* Now do _low registers */
284 for (i = 0; i < BCM1480_NR_IRQS_HALF; i++) {
285 for (cpu = 0; cpu < 4; cpu++) {
286 __raw_writeq(IMR_IP2_VAL,
287 IOADDR(A_BCM1480_IMR_REGISTER(cpu,
288 R_BCM1480_IMR_INTERRUPT_MAP_BASE_L) + (i << 3)));
289 }
290 }
291
292 init_bcm1480_irqs();
293
294 /*
295 * Map the high 16 bits of mailbox_0 registers to IP[3], for
296 * inter-cpu messages
297 */
298 /* Was I1 */
299 for (cpu = 0; cpu < 4; cpu++) {
300 __raw_writeq(IMR_IP3_VAL, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
301 (K_BCM1480_INT_MBOX_0_0 << 3)));
302 }
303
304
305 /* Clear the mailboxes. The firmware may leave them dirty */
306 for (cpu = 0; cpu < 4; cpu++) {
307 __raw_writeq(0xffffffffffffffffULL,
308 IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_0_CLR_CPU)));
309 __raw_writeq(0xffffffffffffffffULL,
310 IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_1_CLR_CPU)));
311 }
312
313
314 /* Mask everything except the high 16 bit of mailbox_0 registers for all cpus */
315 tmp = ~((u64) 0) ^ ( (((u64) 1) << K_BCM1480_INT_MBOX_0_0));
316 for (cpu = 0; cpu < 4; cpu++) {
317 __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_H)));
318 }
319 tmp = ~((u64) 0);
320 for (cpu = 0; cpu < 4; cpu++) {
321 __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_L)));
322 }
323
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700324 /*
325 * Note that the timer interrupts are also mapped, but this is
326 * done in bcm1480_time_init(). Also, the profiling driver
327 * does its own management of IP7.
328 */
329
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700330 /* Enable necessary IPs, disable the rest */
331 change_c0_status(ST0_IM, imask);
Andrew Isaacsonf137e462005-10-19 23:56:38 -0700332}
333
Ralf Baechle937a8012006-10-07 19:44:33 +0100334extern void bcm1480_mailbox_interrupt(void);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100335
Ralf Baechled0453362007-10-22 10:38:44 +0100336static inline void dispatch_ip2(void)
337{
338 unsigned long long mask_h, mask_l;
339 unsigned int cpu = smp_processor_id();
340 unsigned long base;
341
342 /*
343 * Default...we've hit an IP[2] interrupt, which means we've got to
344 * check the 1480 interrupt registers to figure out what to do. Need
345 * to detect which CPU we're on, now that smp_affinity is supported.
346 */
347 base = A_BCM1480_IMR_MAPPER(cpu);
348 mask_h = __raw_readq(
349 IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_H));
350 mask_l = __raw_readq(
351 IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_L));
352
353 if (mask_h) {
354 if (mask_h ^ 1)
355 do_IRQ(fls64(mask_h) - 1);
356 else if (mask_l)
357 do_IRQ(63 + fls64(mask_l));
358 }
359}
360
Ralf Baechle937a8012006-10-07 19:44:33 +0100361asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100362{
Ralf Baechlea8401fa2007-11-05 00:29:45 +0000363 unsigned int cpu = smp_processor_id();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100364 unsigned int pending;
365
366#ifdef CONFIG_SIBYTE_BCM1480_PROF
367 /* Set compare to count to silence count/compare timer interrupts */
368 write_c0_compare(read_c0_count());
369#endif
370
Ralf Baechle34c2dd02006-10-03 14:42:02 +0100371 pending = read_c0_cause() & read_c0_status();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100372
373#ifdef CONFIG_SIBYTE_BCM1480_PROF
374 if (pending & CAUSEF_IP7) /* Cpu performance counter interrupt */
Ralf Baechle937a8012006-10-07 19:44:33 +0100375 sbprof_cpu_intr();
Thiemo Seufer6e61e852006-07-05 14:26:38 +0100376 else
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100377#endif
378
Ralf Baechled0453362007-10-22 10:38:44 +0100379 if (pending & CAUSEF_IP4)
Ralf Baechlea8401fa2007-11-05 00:29:45 +0000380 do_IRQ(K_BCM1480_INT_TIMER_0 + cpu);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100381#ifdef CONFIG_SMP
Thiemo Seufer6e61e852006-07-05 14:26:38 +0100382 else if (pending & CAUSEF_IP3)
Ralf Baechle937a8012006-10-07 19:44:33 +0100383 bcm1480_mailbox_interrupt();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100384#endif
385
Ralf Baechled0453362007-10-22 10:38:44 +0100386 else if (pending & CAUSEF_IP2)
387 dispatch_ip2();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100388}