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/config.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/linkage.h>
22 #include <linux/interrupt.h>
23 #include <linux/spinlock.h>
24 #include <linux/smp.h>
26 #include <linux/slab.h>
27 #include <linux/kernel_stat.h>
29 #include <asm/errno.h>
30 #include <asm/signal.h>
31 #include <asm/system.h>
32 #include <asm/ptrace.h>
35 #include <asm/sibyte/sb1250_regs.h>
36 #include <asm/sibyte/sb1250_int.h>
37 #include <asm/sibyte/sb1250_uart.h>
38 #include <asm/sibyte/sb1250_scd.h>
39 #include <asm/sibyte/sb1250.h>
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
49 #define shutdown_sb1250_irq disable_sb1250_irq
50 static void end_sb1250_irq(unsigned int irq
);
51 static void enable_sb1250_irq(unsigned int irq
);
52 static void disable_sb1250_irq(unsigned int irq
);
53 static unsigned int startup_sb1250_irq(unsigned int irq
);
54 static void ack_sb1250_irq(unsigned int irq
);
56 static void sb1250_set_affinity(unsigned int irq
, unsigned long mask
);
59 #ifdef CONFIG_SIBYTE_HAS_LDT
60 extern unsigned long ldt_eoi_space
;
64 #include <asm/gdb-stub.h>
65 extern void breakpoint(void);
68 /* kgdb is on when configured. Pass "nokgdb" kernel arg to turn it off */
69 static int kgdb_flag
= 1;
70 static int __init
nokgdb(char *str
)
75 __setup("nokgdb", nokgdb
);
77 /* Default to UART1 */
79 #ifdef CONFIG_SIBYTE_SB1250_DUART
80 extern char sb1250_duart_present
[];
84 static struct hw_interrupt_type sb1250_irq_type
= {
99 /* Store the CPU id (not the logical number) */
100 int sb1250_irq_owner
[SB1250_NR_IRQS
];
102 spinlock_t sb1250_imr_lock
= SPIN_LOCK_UNLOCKED
;
104 void sb1250_mask_irq(int cpu
, int irq
)
109 spin_lock_irqsave(&sb1250_imr_lock
, flags
);
110 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(cpu
) + R_IMR_INTERRUPT_MASK
));
111 cur_ints
|= (((u64
) 1) << irq
);
112 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(cpu
) + R_IMR_INTERRUPT_MASK
));
113 spin_unlock_irqrestore(&sb1250_imr_lock
, flags
);
116 void sb1250_unmask_irq(int cpu
, int irq
)
121 spin_lock_irqsave(&sb1250_imr_lock
, flags
);
122 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(cpu
) + R_IMR_INTERRUPT_MASK
));
123 cur_ints
&= ~(((u64
) 1) << irq
);
124 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(cpu
) + R_IMR_INTERRUPT_MASK
));
125 spin_unlock_irqrestore(&sb1250_imr_lock
, flags
);
129 static void sb1250_set_affinity(unsigned int irq
, unsigned long mask
)
131 int i
= 0, old_cpu
, cpu
, int_on
;
133 irq_desc_t
*desc
= irq_desc
+ irq
;
146 printk("attempted to set irq affinity for irq %d to multiple CPUs\n", irq
);
150 /* Convert logical CPU to physical CPU */
151 cpu
= cpu_logical_map(i
);
153 /* Protect against other affinity changers and IMR manipulation */
154 spin_lock_irqsave(&desc
->lock
, flags
);
155 spin_lock(&sb1250_imr_lock
);
157 /* Swizzle each CPU's IMR (but leave the IP selection alone) */
158 old_cpu
= sb1250_irq_owner
[irq
];
159 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(old_cpu
) + R_IMR_INTERRUPT_MASK
));
160 int_on
= !(cur_ints
& (((u64
) 1) << irq
));
162 /* If it was on, mask it */
163 cur_ints
|= (((u64
) 1) << irq
);
164 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(old_cpu
) + R_IMR_INTERRUPT_MASK
));
166 sb1250_irq_owner
[irq
] = cpu
;
168 /* unmask for the new CPU */
169 cur_ints
= ____raw_readq(IOADDR(A_IMR_MAPPER(cpu
) + R_IMR_INTERRUPT_MASK
));
170 cur_ints
&= ~(((u64
) 1) << irq
);
171 ____raw_writeq(cur_ints
, IOADDR(A_IMR_MAPPER(cpu
) + R_IMR_INTERRUPT_MASK
));
173 spin_unlock(&sb1250_imr_lock
);
174 spin_unlock_irqrestore(&desc
->lock
, flags
);
179 /* Defined in arch/mips/sibyte/sb1250/irq_handler.S */
180 extern void sb1250_irq_handler(void);
182 /*****************************************************************************/
184 static unsigned int startup_sb1250_irq(unsigned int irq
)
186 sb1250_unmask_irq(sb1250_irq_owner
[irq
], irq
);
188 return 0; /* never anything pending */
192 static void disable_sb1250_irq(unsigned int irq
)
194 sb1250_mask_irq(sb1250_irq_owner
[irq
], irq
);
197 static void enable_sb1250_irq(unsigned int irq
)
199 sb1250_unmask_irq(sb1250_irq_owner
[irq
], irq
);
203 static void ack_sb1250_irq(unsigned int irq
)
205 #ifdef CONFIG_SIBYTE_HAS_LDT
209 * If the interrupt was an HT interrupt, now is the time to
210 * clear it. NOTE: we assume the HT bridge was set up to
211 * deliver the interrupts to all CPUs (which makes affinity
212 * changing easier for us)
214 pending
= __raw_readq(IOADDR(A_IMR_REGISTER(sb1250_irq_owner
[irq
],
215 R_IMR_LDT_INTERRUPT
)));
216 pending
&= ((u64
)1 << (irq
));
219 for (i
=0; i
<NR_CPUS
; i
++) {
222 cpu
= cpu_logical_map(i
);
227 * Clear for all CPUs so an affinity switch
228 * doesn't find an old status
230 __raw_writeq(pending
,
231 IOADDR(A_IMR_REGISTER(cpu
, R_IMR_LDT_INTERRUPT_CLR
)));
235 * Generate EOI. For Pass 1 parts, EOI is a nop. For
236 * Pass 2, the LDT world may be edge-triggered, but
237 * this EOI shouldn't hurt. If they are
238 * level-sensitive, the EOI is required.
240 *(uint32_t *)(ldt_eoi_space
+(irq
<<16)+(7<<2)) = 0;
243 sb1250_mask_irq(sb1250_irq_owner
[irq
], irq
);
247 static void end_sb1250_irq(unsigned int irq
)
249 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
))) {
250 sb1250_unmask_irq(sb1250_irq_owner
[irq
], irq
);
255 void __init
init_sb1250_irqs(void)
259 for (i
= 0; i
< NR_IRQS
; i
++) {
260 irq_desc
[i
].status
= IRQ_DISABLED
;
261 irq_desc
[i
].action
= 0;
262 irq_desc
[i
].depth
= 1;
263 if (i
< SB1250_NR_IRQS
) {
264 irq_desc
[i
].handler
= &sb1250_irq_type
;
265 sb1250_irq_owner
[i
] = 0;
267 irq_desc
[i
].handler
= &no_irq_type
;
273 static irqreturn_t
sb1250_dummy_handler(int irq
, void *dev_id
,
274 struct pt_regs
*regs
)
279 static struct irqaction sb1250_dummy_action
= {
280 .handler
= sb1250_dummy_handler
,
282 .mask
= CPU_MASK_NONE
,
283 .name
= "sb1250-private",
288 int sb1250_steal_irq(int irq
)
290 irq_desc_t
*desc
= irq_desc
+ irq
;
294 if (irq
>= SB1250_NR_IRQS
)
297 spin_lock_irqsave(&desc
->lock
,flags
);
298 /* Don't allow sharing at all for these */
299 if (desc
->action
!= NULL
)
302 desc
->action
= &sb1250_dummy_action
;
305 spin_unlock_irqrestore(&desc
->lock
,flags
);
310 * init_IRQ is called early in the boot sequence from init/main.c. It
311 * is responsible for setting up the interrupt mapper and installing the
312 * handler that will be responsible for dispatching interrupts to the
316 * For now, map all interrupts to IP[2]. We could save
317 * some cycles by parceling out system interrupts to different
318 * IP lines, but keep it simple for bringup. We'll also direct
319 * all interrupts to a single CPU; we should probably route
320 * PCI and LDT to one cpu and everything else to the other
321 * to balance the load a bit.
323 * On the second cpu, everything is set to IP5, which is
324 * ignored, EXCEPT the mailbox interrupt. That one is
325 * set to IP[2] so it is handled. This is needed so we
326 * can do cross-cpu function calls, as requred by SMP
329 #define IMR_IP2_VAL K_INT_MAP_I0
330 #define IMR_IP3_VAL K_INT_MAP_I1
331 #define IMR_IP4_VAL K_INT_MAP_I2
332 #define IMR_IP5_VAL K_INT_MAP_I3
333 #define IMR_IP6_VAL K_INT_MAP_I4
335 void __init
init_IRQ(void)
340 unsigned int imask
= STATUSF_IP4
| STATUSF_IP3
| STATUSF_IP2
|
341 STATUSF_IP1
| STATUSF_IP0
;
343 /* Default everything to IP2 */
344 for (i
= 0; i
< SB1250_NR_IRQS
; i
++) { /* was I0 */
345 __raw_writeq(IMR_IP2_VAL
,
346 IOADDR(A_IMR_REGISTER(0,
347 R_IMR_INTERRUPT_MAP_BASE
) +
349 __raw_writeq(IMR_IP2_VAL
,
350 IOADDR(A_IMR_REGISTER(1,
351 R_IMR_INTERRUPT_MAP_BASE
) +
358 * Map the high 16 bits of the mailbox registers to IP[3], for
362 __raw_writeq(IMR_IP3_VAL
, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE
) +
363 (K_INT_MBOX_0
<< 3)));
364 __raw_writeq(IMR_IP3_VAL
, IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MAP_BASE
) +
365 (K_INT_MBOX_0
<< 3)));
367 /* Clear the mailboxes. The firmware may leave them dirty */
368 __raw_writeq(0xffffffffffffffff,
369 IOADDR(A_IMR_REGISTER(0, R_IMR_MAILBOX_CLR_CPU
)));
370 __raw_writeq(0xffffffffffffffff,
371 IOADDR(A_IMR_REGISTER(1, R_IMR_MAILBOX_CLR_CPU
)));
373 /* Mask everything except the mailbox registers for both cpus */
374 tmp
= ~((u64
) 0) ^ (((u64
) 1) << K_INT_MBOX_0
);
375 __raw_writeq(tmp
, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MASK
)));
376 __raw_writeq(tmp
, IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MASK
)));
378 sb1250_steal_irq(K_INT_MBOX_0
);
381 * Note that the timer interrupts are also mapped, but this is
382 * done in sb1250_time_init(). Also, the profiling driver
383 * does its own management of IP7.
387 imask
|= STATUSF_IP6
;
389 /* Enable necessary IPs, disable the rest */
390 change_c0_status(ST0_IM
, imask
);
391 set_except_vector(0, sb1250_irq_handler
);
395 kgdb_irq
= K_INT_UART_0
+ kgdb_port
;
397 #ifdef CONFIG_SIBYTE_SB1250_DUART
398 sb1250_duart_present
[kgdb_port
] = 0;
400 /* Setup uart 1 settings, mapper */
401 __raw_writeq(M_DUART_IMR_BRK
, IOADDR(A_DUART_IMRREG(kgdb_port
)));
403 sb1250_steal_irq(kgdb_irq
);
404 __raw_writeq(IMR_IP6_VAL
,
405 IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE
) +
407 sb1250_unmask_irq(0, kgdb_irq
);
409 prom_printf("Waiting for GDB on UART port %d\n", kgdb_port
);
418 #include <linux/delay.h>
420 #define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
421 #define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
423 void sb1250_kgdb_interrupt(struct pt_regs
*regs
)
426 * Clear break-change status (allow some time for the remote
427 * host to stop the break, since we would see another
428 * interrupt on the end-of-break too)
430 kstat_this_cpu
.irqs
[kgdb_irq
]++;
432 duart_out(R_DUART_CMD
, V_DUART_MISC_CMD_RESET_BREAK_INT
|
433 M_DUART_RX_EN
| M_DUART_TX_EN
);
434 set_async_breakpoint(®s
->cp0_epc
);
437 #endif /* CONFIG_KGDB */