1/*
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/kernel.h>
14#include <linux/module.h>
15#include <linux/errno.h>
16#include <linux/kernel_stat.h>
17#include <linux/signal.h>
18#include <linux/sched.h>
19#include <linux/ptrace.h>
20#include <linux/interrupt.h>
21#include <linux/random.h>
22#include <linux/irq.h>
23#include <linux/proc_fs.h>
24#include <linux/seq_file.h>
25#include <linux/profile.h>
26#include <linux/bitops.h>
27
28#include <asm/io.h>
29#include <asm/uaccess.h>
30
31volatile unsigned long irq_err_count;
32DEFINE_PER_CPU(unsigned long, irq_pmi_count);
33
34void ack_bad_irq(unsigned int irq)
35{
36	irq_err_count++;
37	printk(KERN_CRIT "Unexpected IRQ trap at vector %u\n", irq);
38}
39
40#ifdef CONFIG_SMP
41static char irq_user_affinity[NR_IRQS];
42
43int irq_select_affinity(unsigned int irq)
44{
45	struct irq_data *data = irq_get_irq_data(irq);
46	struct irq_chip *chip;
47	static int last_cpu;
48	int cpu = last_cpu + 1;
49
50	if (!data)
51		return 1;
52	chip = irq_data_get_irq_chip(data);
53
54	if (!chip->irq_set_affinity || irq_user_affinity[irq])
55		return 1;
56
57	while (!cpu_possible(cpu) ||
58	       !cpumask_test_cpu(cpu, irq_default_affinity))
59		cpu = (cpu < (NR_CPUS-1) ? cpu + 1 : 0);
60	last_cpu = cpu;
61
62	cpumask_copy(data->affinity, cpumask_of(cpu));
63	chip->irq_set_affinity(data, cpumask_of(cpu), false);
64	return 0;
65}
66#endif /* CONFIG_SMP */
67
68int arch_show_interrupts(struct seq_file *p, int prec)
69{
70	int j;
71
72#ifdef CONFIG_SMP
73	seq_puts(p, "IPI: ");
74	for_each_online_cpu(j)
75		seq_printf(p, "%10lu ", cpu_data[j].ipi_count);
76	seq_putc(p, '\n');
77#endif
78	seq_puts(p, "PMI: ");
79	for_each_online_cpu(j)
80		seq_printf(p, "%10lu ", per_cpu(irq_pmi_count, j));
81	seq_puts(p, "          Performance Monitoring\n");
82	seq_printf(p, "ERR: %10lu\n", irq_err_count);
83	return 0;
84}
85
86/*
87 * handle_irq handles all normal device IRQ's (the special
88 * SMP cross-CPU interrupts have their own specific
89 * handlers).
90 */
91
92#define MAX_ILLEGAL_IRQS 16
93
94void
95handle_irq(int irq)
96{
97	/*
98	 * We ack quickly, we don't want the irq controller
99	 * thinking we're snobs just because some other CPU has
100	 * disabled global interrupts (we have already done the
101	 * INT_ACK cycles, it's too late to try to pretend to the
102	 * controller that we aren't taking the interrupt).
103	 *
104	 * 0 return value means that this irq is already being
105	 * handled by some other CPU. (or is disabled)
106	 */
107	static unsigned int illegal_count=0;
108	struct irq_desc *desc = irq_to_desc(irq);
109
110	if (!desc || ((unsigned) irq > ACTUAL_NR_IRQS &&
111	    illegal_count < MAX_ILLEGAL_IRQS)) {
112		irq_err_count++;
113		illegal_count++;
114		printk(KERN_CRIT "device_interrupt: invalid interrupt %d\n",
115		       irq);
116		return;
117	}
118
119	irq_enter();
120	generic_handle_irq_desc(irq, desc);
121	irq_exit();
122}
123