blob: 9006063e73691da7b68449955a135f7c9317e2cd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/alpha/kernel/irq.c
3 *
4 * Copyright (C) 1995 Linus Torvalds
5 *
6 * This file contains the code used by various IRQ handling routines:
7 * asking for different IRQ's should be done through these routines
8 * instead of just grabbing them. Thus setups with different IRQ numbers
9 * shouldn't result in any weird surprises, and installing new handlers
10 * should be easier.
11 */
12
13#include <linux/config.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/errno.h>
17#include <linux/kernel_stat.h>
18#include <linux/signal.h>
19#include <linux/sched.h>
20#include <linux/ptrace.h>
21#include <linux/interrupt.h>
22#include <linux/slab.h>
23#include <linux/random.h>
24#include <linux/init.h>
25#include <linux/irq.h>
26#include <linux/proc_fs.h>
27#include <linux/seq_file.h>
28#include <linux/profile.h>
29#include <linux/bitops.h>
30
31#include <asm/system.h>
32#include <asm/io.h>
33#include <asm/uaccess.h>
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035volatile unsigned long irq_err_count;
36
Ivan Kokshaysky0595bf32006-01-06 00:12:22 -080037void ack_bad_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 irq_err_count++;
40 printk(KERN_CRIT "Unexpected IRQ trap at vector %u\n", irq);
41}
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static char irq_user_affinity[NR_IRQS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Ivan Kokshaysky0595bf32006-01-06 00:12:22 -080046int
47select_smp_affinity(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
49 static int last_cpu;
50 int cpu = last_cpu + 1;
51
Ivan Kokshaysky0595bf32006-01-06 00:12:22 -080052 if (!irq_desc[irq].handler->set_affinity || irq_user_affinity[irq])
53 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 while (!cpu_possible(cpu))
56 cpu = (cpu < (NR_CPUS-1) ? cpu + 1 : 0);
57 last_cpu = cpu;
58
59 irq_affinity[irq] = cpumask_of_cpu(cpu);
60 irq_desc[irq].handler->set_affinity(irq, cpumask_of_cpu(cpu));
Ivan Kokshaysky0595bf32006-01-06 00:12:22 -080061 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#endif /* CONFIG_SMP */
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065int
66show_interrupts(struct seq_file *p, void *v)
67{
68#ifdef CONFIG_SMP
69 int j;
70#endif
Eric Sesterhennc5e3d982006-02-01 03:06:13 -080071 int irq = *(loff_t *) v;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 struct irqaction * action;
73 unsigned long flags;
74
75#ifdef CONFIG_SMP
Eric Sesterhennc5e3d982006-02-01 03:06:13 -080076 if (irq == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 seq_puts(p, " ");
Eric Sesterhennc5e3d982006-02-01 03:06:13 -080078 for_each_online_cpu(j)
79 seq_printf(p, "CPU%d ", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 seq_putc(p, '\n');
81 }
82#endif
83
Eric Sesterhennc5e3d982006-02-01 03:06:13 -080084 if (irq < ACTUAL_NR_IRQS) {
85 spin_lock_irqsave(&irq_desc[irq].lock, flags);
86 action = irq_desc[irq].action;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 if (!action)
88 goto unlock;
Eric Sesterhennc5e3d982006-02-01 03:06:13 -080089 seq_printf(p, "%3d: ", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#ifndef CONFIG_SMP
Eric Sesterhennc5e3d982006-02-01 03:06:13 -080091 seq_printf(p, "%10u ", kstat_irqs(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#else
Eric Sesterhennc5e3d982006-02-01 03:06:13 -080093 for_each_online_cpu(j)
94 seq_printf(p, "%10u ", kstat_cpu(j).irqs[irq]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#endif
Eric Sesterhennc5e3d982006-02-01 03:06:13 -080096 seq_printf(p, " %14s", irq_desc[irq].handler->typename);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 seq_printf(p, " %c%s",
98 (action->flags & SA_INTERRUPT)?'+':' ',
99 action->name);
100
101 for (action=action->next; action; action = action->next) {
102 seq_printf(p, ", %c%s",
103 (action->flags & SA_INTERRUPT)?'+':' ',
104 action->name);
105 }
106
107 seq_putc(p, '\n');
108unlock:
Eric Sesterhennc5e3d982006-02-01 03:06:13 -0800109 spin_unlock_irqrestore(&irq_desc[irq].lock, flags);
110 } else if (irq == ACTUAL_NR_IRQS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#ifdef CONFIG_SMP
112 seq_puts(p, "IPI: ");
Eric Sesterhennc5e3d982006-02-01 03:06:13 -0800113 for_each_online_cpu(j)
114 seq_printf(p, "%10lu ", cpu_data[j].ipi_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 seq_putc(p, '\n');
116#endif
117 seq_printf(p, "ERR: %10lu\n", irq_err_count);
118 }
119 return 0;
120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/*
123 * handle_irq handles all normal device IRQ's (the special
124 * SMP cross-CPU interrupts have their own specific
125 * handlers).
126 */
127
128#define MAX_ILLEGAL_IRQS 16
129
130void
131handle_irq(int irq, struct pt_regs * regs)
132{
133 /*
134 * We ack quickly, we don't want the irq controller
135 * thinking we're snobs just because some other CPU has
136 * disabled global interrupts (we have already done the
137 * INT_ACK cycles, it's too late to try to pretend to the
138 * controller that we aren't taking the interrupt).
139 *
140 * 0 return value means that this irq is already being
141 * handled by some other CPU. (or is disabled)
142 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 static unsigned int illegal_count=0;
144
145 if ((unsigned) irq > ACTUAL_NR_IRQS && illegal_count < MAX_ILLEGAL_IRQS ) {
146 irq_err_count++;
147 illegal_count++;
148 printk(KERN_CRIT "device_interrupt: invalid interrupt %d\n",
149 irq);
150 return;
151 }
152
153 irq_enter();
Ivan Kokshaysky0595bf32006-01-06 00:12:22 -0800154 local_irq_disable();
155 __do_IRQ(irq, regs);
156 local_irq_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 irq_exit();
158}