2 * arch/ppc/kernel/irq.c
4 * Derived from arch/i386/kernel/irq.c
5 * Copyright (C) 1992 Linus Torvalds
6 * Adapted from arch/i386 by Gary Thomas
7 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
8 * Updated and modified by Cort Dougan (cort@cs.nmt.edu)
9 * Copyright (C) 1996 Cort Dougan
10 * Adapted for Power Macintosh by Paul Mackerras
11 * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
12 * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
19 * This file contains the code used by various IRQ handling routines:
20 * asking for different IRQ's should be done through these routines
21 * instead of just grabbing them. Thus setups with different IRQ numbers
22 * shouldn't result in any weird surprises, and installing new handlers
26 #include <linux/errno.h>
27 #include <linux/module.h>
28 #include <linux/threads.h>
29 #include <linux/kernel_stat.h>
30 #include <linux/signal.h>
31 #include <linux/sched.h>
32 #include <linux/ioport.h>
33 #include <linux/interrupt.h>
34 #include <linux/timex.h>
35 #include <linux/config.h>
36 #include <linux/init.h>
37 #include <linux/slab.h>
38 #include <linux/pci.h>
39 #include <linux/delay.h>
40 #include <linux/irq.h>
41 #include <linux/proc_fs.h>
42 #include <linux/random.h>
43 #include <linux/kallsyms.h>
44 #include <linux/profile.h>
45 #include <linux/bitops.h>
47 #include <asm/uaccess.h>
48 #include <asm/system.h>
50 #include <asm/pgtable.h>
52 #include <asm/cache.h>
54 #include <asm/ptrace.h>
55 #include <asm/iseries/it_lp_queue.h>
56 #include <asm/machdep.h>
60 extern void iSeries_smp_message_recv( struct pt_regs * );
63 extern irq_desc_t irq_desc[NR_IRQS];
64 EXPORT_SYMBOL(irq_desc);
66 int distribute_irqs = 1;
67 int __irq_offset_value;
68 int ppc_spurious_interrupts;
69 u64 ppc64_interrupt_controller;
71 int show_interrupts(struct seq_file *p, void *v)
73 int i = *(loff_t *) v, j;
74 struct irqaction * action;
80 for (j=0; j<NR_CPUS; j++) {
82 seq_printf(p, "CPU%d ",j);
88 desc = get_irq_desc(i);
89 spin_lock_irqsave(&desc->lock, flags);
90 action = desc->action;
91 if (!action || !action->handler)
93 seq_printf(p, "%3d: ", i);
95 for (j = 0; j < NR_CPUS; j++) {
97 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
100 seq_printf(p, "%10u ", kstat_irqs(i));
101 #endif /* CONFIG_SMP */
103 seq_printf(p, " %s ", desc->handler->typename );
105 seq_printf(p, " None ");
106 seq_printf(p, "%s", (desc->status & IRQ_LEVEL) ? "Level " : "Edge ");
107 seq_printf(p, " %s",action->name);
108 for (action=action->next; action; action = action->next)
109 seq_printf(p, ", %s", action->name);
112 spin_unlock_irqrestore(&desc->lock, flags);
113 } else if (i == NR_IRQS)
114 seq_printf(p, "BAD: %10u\n", ppc_spurious_interrupts);
118 #ifdef CONFIG_HOTPLUG_CPU
119 void fixup_irqs(cpumask_t map)
127 if (irq_desc[irq].status & IRQ_PER_CPU)
130 cpus_and(mask, irq_affinity[irq], map);
131 if (any_online_cpu(mask) == NR_CPUS) {
132 printk("Breaking affinity for irq %i\n", irq);
135 if (irq_desc[irq].handler->set_affinity)
136 irq_desc[irq].handler->set_affinity(irq, mask);
137 else if (irq_desc[irq].action && !(warned++))
138 printk("Cannot set affinity for irq %i\n", irq);
147 #ifdef CONFIG_PPC_ISERIES
148 void do_IRQ(struct pt_regs *regs)
150 struct paca_struct *lpaca;
154 #ifdef CONFIG_DEBUG_STACKOVERFLOW
155 /* Debugging check for stack overflow: is there less than 2KB free? */
159 sp = __get_SP() & (THREAD_SIZE-1);
161 if (unlikely(sp < (sizeof(struct thread_info) + 2048))) {
162 printk("do_IRQ: stack overflow: %ld\n",
163 sp - sizeof(struct thread_info));
171 if (lpaca->lppaca.int_dword.fields.ipi_cnt) {
172 lpaca->lppaca.int_dword.fields.ipi_cnt = 0;
173 iSeries_smp_message_recv(regs);
175 #endif /* CONFIG_SMP */
176 if (hvlpevent_is_pending())
177 process_hvlpevents(regs);
181 if (lpaca->lppaca.int_dword.fields.decr_int) {
182 lpaca->lppaca.int_dword.fields.decr_int = 0;
183 /* Signal a fake decrementer interrupt */
184 timer_interrupt(regs);
188 #else /* CONFIG_PPC_ISERIES */
190 void do_IRQ(struct pt_regs *regs)
193 #ifdef CONFIG_IRQSTACKS
194 struct thread_info *curtp, *irqtp;
199 #ifdef CONFIG_DEBUG_STACKOVERFLOW
200 /* Debugging check for stack overflow: is there less than 2KB free? */
204 sp = __get_SP() & (THREAD_SIZE-1);
206 if (unlikely(sp < (sizeof(struct thread_info) + 2048))) {
207 printk("do_IRQ: stack overflow: %ld\n",
208 sp - sizeof(struct thread_info));
214 irq = ppc_md.get_irq(regs);
217 #ifdef CONFIG_IRQSTACKS
218 /* Switch to the irq stack to handle this */
219 curtp = current_thread_info();
220 irqtp = hardirq_ctx[smp_processor_id()];
221 if (curtp != irqtp) {
222 irqtp->task = curtp->task;
224 call___do_IRQ(irq, regs, irqtp);
227 set_bits(irqtp->flags, &curtp->flags);
232 /* That's not SMP safe ... but who cares ? */
233 ppc_spurious_interrupts++;
237 #endif /* CONFIG_PPC_ISERIES */
239 void __init init_IRQ(void)
252 #ifndef CONFIG_PPC_ISERIES
254 * Virtual IRQ mapping code, used on systems with XICS interrupt controllers.
257 #define UNDEFINED_IRQ 0xffffffff
258 unsigned int virt_irq_to_real_map[NR_IRQS];
261 * Don't use virtual irqs 0, 1, 2 for devices.
262 * The pcnet32 driver considers interrupt numbers < 2 to be invalid,
263 * and 2 is the XICS IPI interrupt.
264 * We limit virtual irqs to 17 less than NR_IRQS so that when we
265 * offset them by 16 (to reserve the first 16 for ISA interrupts)
266 * we don't end up with an interrupt number >= NR_IRQS.
268 #define MIN_VIRT_IRQ 3
269 #define MAX_VIRT_IRQ (NR_IRQS - NUM_ISA_INTERRUPTS - 1)
270 #define NR_VIRT_IRQS (MAX_VIRT_IRQ - MIN_VIRT_IRQ + 1)
276 for (i = 0; i < NR_IRQS; i++)
277 virt_irq_to_real_map[i] = UNDEFINED_IRQ;
280 /* Create a mapping for a real_irq if it doesn't already exist.
281 * Return the virtual irq as a convenience.
283 int virt_irq_create_mapping(unsigned int real_irq)
285 unsigned int virq, first_virq;
288 if (ppc64_interrupt_controller == IC_OPEN_PIC)
289 return real_irq; /* no mapping for openpic (for now) */
291 if (ppc64_interrupt_controller == IC_CELL_PIC)
292 return real_irq; /* no mapping for iic either */
294 /* don't map interrupts < MIN_VIRT_IRQ */
295 if (real_irq < MIN_VIRT_IRQ) {
296 virt_irq_to_real_map[real_irq] = real_irq;
300 /* map to a number between MIN_VIRT_IRQ and MAX_VIRT_IRQ */
302 if (virq > MAX_VIRT_IRQ)
303 virq = (virq % NR_VIRT_IRQS) + MIN_VIRT_IRQ;
305 /* search for this number or a free slot */
307 while (virt_irq_to_real_map[virq] != UNDEFINED_IRQ) {
308 if (virt_irq_to_real_map[virq] == real_irq)
310 if (++virq > MAX_VIRT_IRQ)
312 if (virq == first_virq)
313 goto nospace; /* oops, no free slots */
316 virt_irq_to_real_map[virq] = real_irq;
321 printk(KERN_CRIT "Interrupt table is full\n");
322 printk(KERN_CRIT "Increase NR_IRQS (currently %d) "
323 "in your kernel sources and rebuild.\n", NR_IRQS);
330 * In most cases will get a hit on the very first slot checked in the
331 * virt_irq_to_real_map. Only when there are a large number of
332 * IRQs will this be expensive.
334 unsigned int real_irq_to_virt_slowpath(unsigned int real_irq)
337 unsigned int first_virq;
341 if (virq > MAX_VIRT_IRQ)
342 virq = (virq % NR_VIRT_IRQS) + MIN_VIRT_IRQ;
347 if (virt_irq_to_real_map[virq] == real_irq)
352 if (virq >= MAX_VIRT_IRQ)
355 } while (first_virq != virq);
361 #endif /* CONFIG_PPC_ISERIES */
363 #ifdef CONFIG_IRQSTACKS
364 struct thread_info *softirq_ctx[NR_CPUS];
365 struct thread_info *hardirq_ctx[NR_CPUS];
367 void irq_ctx_init(void)
369 struct thread_info *tp;
373 memset((void *)softirq_ctx[i], 0, THREAD_SIZE);
376 tp->preempt_count = SOFTIRQ_OFFSET;
378 memset((void *)hardirq_ctx[i], 0, THREAD_SIZE);
381 tp->preempt_count = HARDIRQ_OFFSET;
385 void do_softirq(void)
388 struct thread_info *curtp, *irqtp;
393 local_irq_save(flags);
395 if (local_softirq_pending()) {
396 curtp = current_thread_info();
397 irqtp = softirq_ctx[smp_processor_id()];
398 irqtp->task = curtp->task;
399 call_do_softirq(irqtp);
403 local_irq_restore(flags);
405 EXPORT_SYMBOL(do_softirq);
407 #endif /* CONFIG_IRQSTACKS */
409 static int __init setup_noirqdistrib(char *str)
415 __setup("noirqdistrib", setup_noirqdistrib);