2 * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
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.
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.
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.
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>
25 #include <linux/slab.h>
26 #include <linux/kernel_stat.h>
28 #include <asm/errno.h>
29 #include <asm/gdb-stub.h>
30 #include <asm/signal.h>
31 #include <asm/system.h>
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>
41 * These are the routines that handle all the low level interrupt stuff.
42 * Actions handled here are: initialization of the interrupt map, requesting of
43 * interrupt lines by handlers, dispatching if interrupts to handlers, probing
48 static void end_sb1250_irq(unsigned int irq
);
49 static void enable_sb1250_irq(unsigned int irq
);
50 static void disable_sb1250_irq(unsigned int irq
);
51 static void ack_sb1250_irq(unsigned int irq
);
53 static void sb1250_set_affinity(unsigned int irq
, cpumask_t mask
);
56 #ifdef CONFIG_SIBYTE_HAS_LDT
57 extern unsigned long ldt_eoi_space
;
63 /* Default to UART1 */
65 #ifdef CONFIG_SIBYTE_SB1250_DUART
66 extern char sb1250_duart_present
[];
70 static struct irq_chip sb1250_irq_type
= {
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
,
78 .set_affinity
= sb1250_set_affinity
82 /* Store the CPU id (not the logical number) */
83 int sb1250_irq_owner
[SB1250_NR_IRQS
];
85 DEFINE_SPINLOCK(sb1250_imr_lock
);
87 void sb1250_mask_irq(int cpu
, int irq
)
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
);
101 void sb1250_unmask_irq(int cpu
, int irq
)
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
);
116 static void sb1250_set_affinity(unsigned int irq
, cpumask_t mask
)
118 int i
= 0, old_cpu
, cpu
, int_on
;
124 /* Convert logical CPU to physical CPU */
125 cpu
= cpu_logical_map(i
);
127 /* Protect against other affinity changers and IMR manipulation */
128 spin_lock_irqsave(&sb1250_imr_lock
, flags
);
130 /* Swizzle each CPU's IMR (but leave the IP selection alone) */
131 old_cpu
= sb1250_irq_owner
[irq
];
132 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(old_cpu
) +
133 R_IMR_INTERRUPT_MASK
));
134 int_on
= !(cur_ints
& (((u64
) 1) << irq
));
136 /* If it was on, mask it */
137 cur_ints
|= (((u64
) 1) << irq
);
138 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(old_cpu
) +
139 R_IMR_INTERRUPT_MASK
));
141 sb1250_irq_owner
[irq
] = cpu
;
143 /* unmask for the new CPU */
144 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(cpu
) +
145 R_IMR_INTERRUPT_MASK
));
146 cur_ints
&= ~(((u64
) 1) << irq
);
147 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(cpu
) +
148 R_IMR_INTERRUPT_MASK
));
150 spin_unlock_irqrestore(&sb1250_imr_lock
, flags
);
154 /*****************************************************************************/
156 static void disable_sb1250_irq(unsigned int irq
)
158 sb1250_mask_irq(sb1250_irq_owner
[irq
], irq
);
161 static void enable_sb1250_irq(unsigned int irq
)
163 sb1250_unmask_irq(sb1250_irq_owner
[irq
], irq
);
167 static void ack_sb1250_irq(unsigned int irq
)
169 #ifdef CONFIG_SIBYTE_HAS_LDT
173 * If the interrupt was an HT interrupt, now is the time to
174 * clear it. NOTE: we assume the HT bridge was set up to
175 * deliver the interrupts to all CPUs (which makes affinity
176 * changing easier for us)
178 pending
= __raw_readq(IOADDR(A_IMR_REGISTER(sb1250_irq_owner
[irq
],
179 R_IMR_LDT_INTERRUPT
)));
180 pending
&= ((u64
)1 << (irq
));
183 for (i
=0; i
<NR_CPUS
; i
++) {
186 cpu
= cpu_logical_map(i
);
191 * Clear for all CPUs so an affinity switch
192 * doesn't find an old status
194 __raw_writeq(pending
,
195 IOADDR(A_IMR_REGISTER(cpu
,
196 R_IMR_LDT_INTERRUPT_CLR
)));
200 * Generate EOI. For Pass 1 parts, EOI is a nop. For
201 * Pass 2, the LDT world may be edge-triggered, but
202 * this EOI shouldn't hurt. If they are
203 * level-sensitive, the EOI is required.
205 *(uint32_t *)(ldt_eoi_space
+(irq
<<16)+(7<<2)) = 0;
208 sb1250_mask_irq(sb1250_irq_owner
[irq
], irq
);
212 static void end_sb1250_irq(unsigned int irq
)
214 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
))) {
215 sb1250_unmask_irq(sb1250_irq_owner
[irq
], irq
);
220 void __init
init_sb1250_irqs(void)
224 for (i
= 0; i
< SB1250_NR_IRQS
; i
++) {
225 set_irq_chip(i
, &sb1250_irq_type
);
226 sb1250_irq_owner
[i
] = 0;
231 static irqreturn_t
sb1250_dummy_handler(int irq
, void *dev_id
)
236 static struct irqaction sb1250_dummy_action
= {
237 .handler
= sb1250_dummy_handler
,
239 .mask
= CPU_MASK_NONE
,
240 .name
= "sb1250-private",
245 int sb1250_steal_irq(int irq
)
247 struct irq_desc
*desc
= irq_desc
+ irq
;
251 if (irq
>= SB1250_NR_IRQS
)
254 spin_lock_irqsave(&desc
->lock
,flags
);
255 /* Don't allow sharing at all for these */
256 if (desc
->action
!= NULL
)
259 desc
->action
= &sb1250_dummy_action
;
262 spin_unlock_irqrestore(&desc
->lock
,flags
);
267 * arch_init_irq is called early in the boot sequence from init/main.c via
268 * init_IRQ. It is responsible for setting up the interrupt mapper and
269 * installing the handler that will be responsible for dispatching interrupts
270 * to the "right" place.
273 * For now, map all interrupts to IP[2]. We could save
274 * some cycles by parceling out system interrupts to different
275 * IP lines, but keep it simple for bringup. We'll also direct
276 * all interrupts to a single CPU; we should probably route
277 * PCI and LDT to one cpu and everything else to the other
278 * to balance the load a bit.
280 * On the second cpu, everything is set to IP5, which is
281 * ignored, EXCEPT the mailbox interrupt. That one is
282 * set to IP[2] so it is handled. This is needed so we
283 * can do cross-cpu function calls, as requred by SMP
286 #define IMR_IP2_VAL K_INT_MAP_I0
287 #define IMR_IP3_VAL K_INT_MAP_I1
288 #define IMR_IP4_VAL K_INT_MAP_I2
289 #define IMR_IP5_VAL K_INT_MAP_I3
290 #define IMR_IP6_VAL K_INT_MAP_I4
292 void __init
arch_init_irq(void)
297 unsigned int imask
= STATUSF_IP4
| STATUSF_IP3
| STATUSF_IP2
|
298 STATUSF_IP1
| STATUSF_IP0
;
300 /* Default everything to IP2 */
301 for (i
= 0; i
< SB1250_NR_IRQS
; i
++) { /* was I0 */
302 __raw_writeq(IMR_IP2_VAL
,
303 IOADDR(A_IMR_REGISTER(0,
304 R_IMR_INTERRUPT_MAP_BASE
) +
306 __raw_writeq(IMR_IP2_VAL
,
307 IOADDR(A_IMR_REGISTER(1,
308 R_IMR_INTERRUPT_MAP_BASE
) +
315 * Map the high 16 bits of the mailbox registers to IP[3], for
319 __raw_writeq(IMR_IP3_VAL
,
320 IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE
) +
321 (K_INT_MBOX_0
<< 3)));
322 __raw_writeq(IMR_IP3_VAL
,
323 IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MAP_BASE
) +
324 (K_INT_MBOX_0
<< 3)));
326 /* Clear the mailboxes. The firmware may leave them dirty */
327 __raw_writeq(0xffffffffffffffffULL
,
328 IOADDR(A_IMR_REGISTER(0, R_IMR_MAILBOX_CLR_CPU
)));
329 __raw_writeq(0xffffffffffffffffULL
,
330 IOADDR(A_IMR_REGISTER(1, R_IMR_MAILBOX_CLR_CPU
)));
332 /* Mask everything except the mailbox registers for both cpus */
333 tmp
= ~((u64
) 0) ^ (((u64
) 1) << K_INT_MBOX_0
);
334 __raw_writeq(tmp
, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MASK
)));
335 __raw_writeq(tmp
, IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MASK
)));
337 sb1250_steal_irq(K_INT_MBOX_0
);
340 * Note that the timer interrupts are also mapped, but this is
341 * done in sb1250_time_init(). Also, the profiling driver
342 * does its own management of IP7.
346 imask
|= STATUSF_IP6
;
348 /* Enable necessary IPs, disable the rest */
349 change_c0_status(ST0_IM
, imask
);
353 kgdb_irq
= K_INT_UART_0
+ kgdb_port
;
355 #ifdef CONFIG_SIBYTE_SB1250_DUART
356 sb1250_duart_present
[kgdb_port
] = 0;
358 /* Setup uart 1 settings, mapper */
359 __raw_writeq(M_DUART_IMR_BRK
,
360 IOADDR(A_DUART_IMRREG(kgdb_port
)));
362 sb1250_steal_irq(kgdb_irq
);
363 __raw_writeq(IMR_IP6_VAL
,
364 IOADDR(A_IMR_REGISTER(0,
365 R_IMR_INTERRUPT_MAP_BASE
) +
367 sb1250_unmask_irq(0, kgdb_irq
);
374 #include <linux/delay.h>
376 #define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
377 #define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
379 static void sb1250_kgdb_interrupt(void)
382 * Clear break-change status (allow some time for the remote
383 * host to stop the break, since we would see another
384 * interrupt on the end-of-break too)
386 kstat_this_cpu
.irqs
[kgdb_irq
]++;
388 duart_out(R_DUART_CMD
, V_DUART_MISC_CMD_RESET_BREAK_INT
|
389 M_DUART_RX_EN
| M_DUART_TX_EN
);
390 set_async_breakpoint(&get_irq_regs()->cp0_epc
);
393 #endif /* CONFIG_KGDB */
395 extern void sb1250_timer_interrupt(void);
396 extern void sb1250_mailbox_interrupt(void);
398 asmlinkage
void plat_irq_dispatch(void)
400 unsigned int pending
;
402 #ifdef CONFIG_SIBYTE_SB1250_PROF
403 /* Set compare to count to silence count/compare timer interrupts */
404 write_c0_compare(read_c0_count());
408 * What a pain. We have to be really careful saving the upper 32 bits
409 * of any * register across function calls if we don't want them
410 * trashed--since were running in -o32, the calling routing never saves
411 * the full 64 bits of a register across a function call. Being the
412 * interrupt handler, we're guaranteed that interrupts are disabled
413 * during this code so we don't have to worry about random interrupts
414 * blasting the high 32 bits.
417 pending
= read_c0_cause() & read_c0_status() & ST0_IM
;
419 #ifdef CONFIG_SIBYTE_SB1250_PROF
420 if (pending
& CAUSEF_IP7
) /* Cpu performance counter interrupt */
425 if (pending
& CAUSEF_IP4
)
426 sb1250_timer_interrupt();
429 else if (pending
& CAUSEF_IP3
)
430 sb1250_mailbox_interrupt();
434 else if (pending
& CAUSEF_IP6
) /* KGDB (uart 1) */
435 sb1250_kgdb_interrupt();
438 else if (pending
& CAUSEF_IP2
) {
439 unsigned long long mask
;
442 * Default...we've hit an IP[2] interrupt, which means we've
443 * got to check the 1250 interrupt registers to figure out what
444 * to do. Need to detect which CPU we're on, now that
445 * smp_affinity is supported.
447 mask
= __raw_readq(IOADDR(A_IMR_REGISTER(smp_processor_id(),
448 R_IMR_INTERRUPT_STATUS_BASE
)));
450 do_IRQ(fls64(mask
) - 1);
452 spurious_interrupt();
454 spurious_interrupt();