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/signal.h>
30 #include <asm/system.h>
33 #include <asm/sibyte/sb1250_regs.h>
34 #include <asm/sibyte/sb1250_int.h>
35 #include <asm/sibyte/sb1250_uart.h>
36 #include <asm/sibyte/sb1250_scd.h>
37 #include <asm/sibyte/sb1250.h>
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
47 #define shutdown_sb1250_irq disable_sb1250_irq
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 unsigned int startup_sb1250_irq(unsigned int irq
);
52 static void ack_sb1250_irq(unsigned int irq
);
54 static void sb1250_set_affinity(unsigned int irq
, cpumask_t mask
);
57 #ifdef CONFIG_SIBYTE_HAS_LDT
58 extern unsigned long ldt_eoi_space
;
64 /* Default to UART1 */
66 #ifdef CONFIG_SIBYTE_SB1250_DUART
67 extern char sb1250_duart_present
[];
71 static struct irq_chip sb1250_irq_type
= {
72 .typename
= "SB1250-IMR",
73 .startup
= startup_sb1250_irq
,
74 .shutdown
= shutdown_sb1250_irq
,
75 .enable
= enable_sb1250_irq
,
76 .disable
= disable_sb1250_irq
,
77 .ack
= ack_sb1250_irq
,
78 .end
= end_sb1250_irq
,
80 .set_affinity
= sb1250_set_affinity
84 /* Store the CPU id (not the logical number) */
85 int sb1250_irq_owner
[SB1250_NR_IRQS
];
87 DEFINE_SPINLOCK(sb1250_imr_lock
);
89 void sb1250_mask_irq(int cpu
, int irq
)
94 spin_lock_irqsave(&sb1250_imr_lock
, flags
);
95 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(cpu
) +
96 R_IMR_INTERRUPT_MASK
));
97 cur_ints
|= (((u64
) 1) << irq
);
98 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(cpu
) +
99 R_IMR_INTERRUPT_MASK
));
100 spin_unlock_irqrestore(&sb1250_imr_lock
, flags
);
103 void sb1250_unmask_irq(int cpu
, int irq
)
108 spin_lock_irqsave(&sb1250_imr_lock
, flags
);
109 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(cpu
) +
110 R_IMR_INTERRUPT_MASK
));
111 cur_ints
&= ~(((u64
) 1) << irq
);
112 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(cpu
) +
113 R_IMR_INTERRUPT_MASK
));
114 spin_unlock_irqrestore(&sb1250_imr_lock
, flags
);
118 static void sb1250_set_affinity(unsigned int irq
, cpumask_t mask
)
120 int i
= 0, old_cpu
, cpu
, int_on
;
122 struct irq_desc
*desc
= irq_desc
+ irq
;
127 if (cpus_weight(mask
) > 1) {
128 printk("attempted to set irq affinity for irq %d to multiple CPUs\n", irq
);
132 /* Convert logical CPU to physical CPU */
133 cpu
= cpu_logical_map(i
);
135 /* Protect against other affinity changers and IMR manipulation */
136 spin_lock_irqsave(&desc
->lock
, flags
);
137 spin_lock(&sb1250_imr_lock
);
139 /* Swizzle each CPU's IMR (but leave the IP selection alone) */
140 old_cpu
= sb1250_irq_owner
[irq
];
141 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(old_cpu
) +
142 R_IMR_INTERRUPT_MASK
));
143 int_on
= !(cur_ints
& (((u64
) 1) << irq
));
145 /* If it was on, mask it */
146 cur_ints
|= (((u64
) 1) << irq
);
147 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(old_cpu
) +
148 R_IMR_INTERRUPT_MASK
));
150 sb1250_irq_owner
[irq
] = cpu
;
152 /* unmask for the new CPU */
153 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(cpu
) +
154 R_IMR_INTERRUPT_MASK
));
155 cur_ints
&= ~(((u64
) 1) << irq
);
156 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(cpu
) +
157 R_IMR_INTERRUPT_MASK
));
159 spin_unlock(&sb1250_imr_lock
);
160 spin_unlock_irqrestore(&desc
->lock
, flags
);
164 /*****************************************************************************/
166 static unsigned int startup_sb1250_irq(unsigned int irq
)
168 sb1250_unmask_irq(sb1250_irq_owner
[irq
], irq
);
170 return 0; /* never anything pending */
174 static void disable_sb1250_irq(unsigned int irq
)
176 sb1250_mask_irq(sb1250_irq_owner
[irq
], irq
);
179 static void enable_sb1250_irq(unsigned int irq
)
181 sb1250_unmask_irq(sb1250_irq_owner
[irq
], irq
);
185 static void ack_sb1250_irq(unsigned int irq
)
187 #ifdef CONFIG_SIBYTE_HAS_LDT
191 * If the interrupt was an HT interrupt, now is the time to
192 * clear it. NOTE: we assume the HT bridge was set up to
193 * deliver the interrupts to all CPUs (which makes affinity
194 * changing easier for us)
196 pending
= __raw_readq(IOADDR(A_IMR_REGISTER(sb1250_irq_owner
[irq
],
197 R_IMR_LDT_INTERRUPT
)));
198 pending
&= ((u64
)1 << (irq
));
201 for (i
=0; i
<NR_CPUS
; i
++) {
204 cpu
= cpu_logical_map(i
);
209 * Clear for all CPUs so an affinity switch
210 * doesn't find an old status
212 __raw_writeq(pending
,
213 IOADDR(A_IMR_REGISTER(cpu
,
214 R_IMR_LDT_INTERRUPT_CLR
)));
218 * Generate EOI. For Pass 1 parts, EOI is a nop. For
219 * Pass 2, the LDT world may be edge-triggered, but
220 * this EOI shouldn't hurt. If they are
221 * level-sensitive, the EOI is required.
223 *(uint32_t *)(ldt_eoi_space
+(irq
<<16)+(7<<2)) = 0;
226 sb1250_mask_irq(sb1250_irq_owner
[irq
], irq
);
230 static void end_sb1250_irq(unsigned int irq
)
232 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
))) {
233 sb1250_unmask_irq(sb1250_irq_owner
[irq
], irq
);
238 void __init
init_sb1250_irqs(void)
242 for (i
= 0; i
< NR_IRQS
; i
++) {
243 irq_desc
[i
].status
= IRQ_DISABLED
;
244 irq_desc
[i
].action
= 0;
245 irq_desc
[i
].depth
= 1;
246 if (i
< SB1250_NR_IRQS
) {
247 irq_desc
[i
].chip
= &sb1250_irq_type
;
248 sb1250_irq_owner
[i
] = 0;
250 irq_desc
[i
].chip
= &no_irq_chip
;
256 static irqreturn_t
sb1250_dummy_handler(int irq
, void *dev_id
)
261 static struct irqaction sb1250_dummy_action
= {
262 .handler
= sb1250_dummy_handler
,
264 .mask
= CPU_MASK_NONE
,
265 .name
= "sb1250-private",
270 int sb1250_steal_irq(int irq
)
272 struct irq_desc
*desc
= irq_desc
+ irq
;
276 if (irq
>= SB1250_NR_IRQS
)
279 spin_lock_irqsave(&desc
->lock
,flags
);
280 /* Don't allow sharing at all for these */
281 if (desc
->action
!= NULL
)
284 desc
->action
= &sb1250_dummy_action
;
287 spin_unlock_irqrestore(&desc
->lock
,flags
);
292 * arch_init_irq is called early in the boot sequence from init/main.c via
293 * init_IRQ. It is responsible for setting up the interrupt mapper and
294 * installing the handler that will be responsible for dispatching interrupts
295 * to the "right" place.
298 * For now, map all interrupts to IP[2]. We could save
299 * some cycles by parceling out system interrupts to different
300 * IP lines, but keep it simple for bringup. We'll also direct
301 * all interrupts to a single CPU; we should probably route
302 * PCI and LDT to one cpu and everything else to the other
303 * to balance the load a bit.
305 * On the second cpu, everything is set to IP5, which is
306 * ignored, EXCEPT the mailbox interrupt. That one is
307 * set to IP[2] so it is handled. This is needed so we
308 * can do cross-cpu function calls, as requred by SMP
311 #define IMR_IP2_VAL K_INT_MAP_I0
312 #define IMR_IP3_VAL K_INT_MAP_I1
313 #define IMR_IP4_VAL K_INT_MAP_I2
314 #define IMR_IP5_VAL K_INT_MAP_I3
315 #define IMR_IP6_VAL K_INT_MAP_I4
317 void __init
arch_init_irq(void)
322 unsigned int imask
= STATUSF_IP4
| STATUSF_IP3
| STATUSF_IP2
|
323 STATUSF_IP1
| STATUSF_IP0
;
325 /* Default everything to IP2 */
326 for (i
= 0; i
< SB1250_NR_IRQS
; i
++) { /* was I0 */
327 __raw_writeq(IMR_IP2_VAL
,
328 IOADDR(A_IMR_REGISTER(0,
329 R_IMR_INTERRUPT_MAP_BASE
) +
331 __raw_writeq(IMR_IP2_VAL
,
332 IOADDR(A_IMR_REGISTER(1,
333 R_IMR_INTERRUPT_MAP_BASE
) +
340 * Map the high 16 bits of the mailbox registers to IP[3], for
344 __raw_writeq(IMR_IP3_VAL
,
345 IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE
) +
346 (K_INT_MBOX_0
<< 3)));
347 __raw_writeq(IMR_IP3_VAL
,
348 IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MAP_BASE
) +
349 (K_INT_MBOX_0
<< 3)));
351 /* Clear the mailboxes. The firmware may leave them dirty */
352 __raw_writeq(0xffffffffffffffffULL
,
353 IOADDR(A_IMR_REGISTER(0, R_IMR_MAILBOX_CLR_CPU
)));
354 __raw_writeq(0xffffffffffffffffULL
,
355 IOADDR(A_IMR_REGISTER(1, R_IMR_MAILBOX_CLR_CPU
)));
357 /* Mask everything except the mailbox registers for both cpus */
358 tmp
= ~((u64
) 0) ^ (((u64
) 1) << K_INT_MBOX_0
);
359 __raw_writeq(tmp
, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MASK
)));
360 __raw_writeq(tmp
, IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MASK
)));
362 sb1250_steal_irq(K_INT_MBOX_0
);
365 * Note that the timer interrupts are also mapped, but this is
366 * done in sb1250_time_init(). Also, the profiling driver
367 * does its own management of IP7.
371 imask
|= STATUSF_IP6
;
373 /* Enable necessary IPs, disable the rest */
374 change_c0_status(ST0_IM
, imask
);
378 kgdb_irq
= K_INT_UART_0
+ kgdb_port
;
380 #ifdef CONFIG_SIBYTE_SB1250_DUART
381 sb1250_duart_present
[kgdb_port
] = 0;
383 /* Setup uart 1 settings, mapper */
384 __raw_writeq(M_DUART_IMR_BRK
,
385 IOADDR(A_DUART_IMRREG(kgdb_port
)));
387 sb1250_steal_irq(kgdb_irq
);
388 __raw_writeq(IMR_IP6_VAL
,
389 IOADDR(A_IMR_REGISTER(0,
390 R_IMR_INTERRUPT_MAP_BASE
) +
392 sb1250_unmask_irq(0, kgdb_irq
);
399 #include <linux/delay.h>
401 #define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
402 #define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
404 static void sb1250_kgdb_interrupt(void)
407 * Clear break-change status (allow some time for the remote
408 * host to stop the break, since we would see another
409 * interrupt on the end-of-break too)
411 kstat_this_cpu
.irqs
[kgdb_irq
]++;
413 duart_out(R_DUART_CMD
, V_DUART_MISC_CMD_RESET_BREAK_INT
|
414 M_DUART_RX_EN
| M_DUART_TX_EN
);
415 set_async_breakpoint(&get_irq_regs()->cp0_epc
);
418 #endif /* CONFIG_KGDB */
420 extern void sb1250_timer_interrupt(void);
421 extern void sb1250_mailbox_interrupt(void);
423 asmlinkage
void plat_irq_dispatch(void)
425 unsigned int pending
;
427 #ifdef CONFIG_SIBYTE_SB1250_PROF
428 /* Set compare to count to silence count/compare timer interrupts */
429 write_c0_compare(read_c0_count());
433 * What a pain. We have to be really careful saving the upper 32 bits
434 * of any * register across function calls if we don't want them
435 * trashed--since were running in -o32, the calling routing never saves
436 * the full 64 bits of a register across a function call. Being the
437 * interrupt handler, we're guaranteed that interrupts are disabled
438 * during this code so we don't have to worry about random interrupts
439 * blasting the high 32 bits.
442 pending
= read_c0_cause() & read_c0_status();
444 #ifdef CONFIG_SIBYTE_SB1250_PROF
445 if (pending
& CAUSEF_IP7
) /* Cpu performance counter interrupt */
450 if (pending
& CAUSEF_IP4
)
451 sb1250_timer_interrupt();
454 else if (pending
& CAUSEF_IP3
)
455 sb1250_mailbox_interrupt();
459 else if (pending
& CAUSEF_IP6
) /* KGDB (uart 1) */
460 sb1250_kgdb_interrupt();
463 else if (pending
& CAUSEF_IP2
) {
464 unsigned long long mask
;
467 * Default...we've hit an IP[2] interrupt, which means we've
468 * got to check the 1250 interrupt registers to figure out what
469 * to do. Need to detect which CPU we're on, now that
470 * smp_affinity is supported.
472 mask
= __raw_readq(IOADDR(A_IMR_REGISTER(smp_processor_id(),
473 R_IMR_INTERRUPT_STATUS_BASE
)));
475 do_IRQ(fls64(mask
) - 1);
477 spurious_interrupt();
479 spurious_interrupt();