irq.c 5.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6
/*
 *  linux/arch/arm/kernel/irq.c
 *
 *  Copyright (C) 1992 Linus Torvalds
 *  Modifications for ARM processor Copyright (C) 1995-2000 Russell King.
 *
7 8 9 10
 *  Support for Dynamic Tick Timer Copyright (C) 2004-2005 Nokia Corporation.
 *  Dynamic Tick Timer written by Tony Lindgren <tony@atomide.com> and
 *  Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>.
 *
L
Linus Torvalds 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *  This file contains the code used by various IRQ handling routines:
 *  asking for different IRQ's should be done through these routines
 *  instead of just grabbing them. Thus setups with different IRQ numbers
 *  shouldn't result in any weird surprises, and installing new handlers
 *  should be easier.
 *
 *  IRQ's are in fact implemented a bit like signal handlers for the kernel.
 *  Naturally it's not a 1:1 relation, but there are similarities.
 */
#include <linux/kernel_stat.h>
#include <linux/signal.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
28
#include <linux/irq.h>
29
#include <linux/irqchip.h>
L
Linus Torvalds 已提交
30 31 32 33 34 35 36 37
#include <linux/random.h>
#include <linux/smp.h>
#include <linux/init.h>
#include <linux/seq_file.h>
#include <linux/errno.h>
#include <linux/list.h>
#include <linux/kallsyms.h>
#include <linux/proc_fs.h>
A
Arnd Bergmann 已提交
38
#include <linux/export.h>
L
Linus Torvalds 已提交
39

40
#include <asm/exception.h>
41
#include <asm/mach/arch.h>
42
#include <asm/mach/irq.h>
43
#include <asm/mach/time.h>
L
Linus Torvalds 已提交
44

45
unsigned long irq_err_count;
L
Linus Torvalds 已提交
46

47
int arch_show_interrupts(struct seq_file *p, int prec)
L
Linus Torvalds 已提交
48
{
49
#ifdef CONFIG_FIQ
50
	show_fiq_list(p, prec);
L
Linus Torvalds 已提交
51 52
#endif
#ifdef CONFIG_SMP
53
	show_ipi_list(p, prec);
L
Linus Torvalds 已提交
54
#endif
55
	seq_printf(p, "%*s: %10lu\n", prec, "Err", irq_err_count);
L
Linus Torvalds 已提交
56 57 58 59
	return 0;
}

/*
60 61 62 63
 * handle_IRQ handles all hardware IRQ's.  Decoded IRQs should
 * not come via this function.  Instead, they should provide their
 * own 'handler'.  Used by platform code implementing C-based 1st
 * level decoding.
L
Linus Torvalds 已提交
64
 */
65
void handle_IRQ(unsigned int irq, struct pt_regs *regs)
L
Linus Torvalds 已提交
66
{
L
Linus Torvalds 已提交
67
	struct pt_regs *old_regs = set_irq_regs(regs);
68 69

	irq_enter();
L
Linus Torvalds 已提交
70 71 72 73 74

	/*
	 * Some hardware gives randomly wrong interrupts.  Rather
	 * than crashing, do something sensible.
	 */
75
	if (unlikely(irq >= nr_irqs)) {
76 77 78 79
		if (printk_ratelimit())
			printk(KERN_WARNING "Bad IRQ%u\n", irq);
		ack_bad_irq(irq);
	} else {
80
		generic_handle_irq(irq);
81
	}
L
Linus Torvalds 已提交
82 83

	irq_exit();
L
Linus Torvalds 已提交
84
	set_irq_regs(old_regs);
L
Linus Torvalds 已提交
85 86
}

87 88 89 90 91 92 93 94 95
/*
 * asm_do_IRQ is the interface to be used from assembly code.
 */
asmlinkage void __exception_irq_entry
asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
{
	handle_IRQ(irq, regs);
}

L
Linus Torvalds 已提交
96 97
void set_irq_flags(unsigned int irq, unsigned int iflags)
{
98
	unsigned long clr = 0, set = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
L
Linus Torvalds 已提交
99

100
	if (irq >= nr_irqs) {
L
Linus Torvalds 已提交
101 102 103 104
		printk(KERN_ERR "Trying to set irq flags for IRQ%d\n", irq);
		return;
	}

105
	if (iflags & IRQF_VALID)
106
		clr |= IRQ_NOREQUEST;
107
	if (iflags & IRQF_PROBE)
108
		clr |= IRQ_NOPROBE;
109
	if (!(iflags & IRQF_NOAUTOEN))
110 111 112
		clr |= IRQ_NOAUTOEN;
	/* Order is clear bits in "clr" then set bits in "set" */
	irq_modify_status(irq, clr, set & ~clr);
L
Linus Torvalds 已提交
113
}
A
Arnd Bergmann 已提交
114
EXPORT_SYMBOL_GPL(set_irq_flags);
L
Linus Torvalds 已提交
115 116 117

void __init init_IRQ(void)
{
118 119 120 121
	if (IS_ENABLED(CONFIG_OF) && !machine_desc->init_irq)
		irqchip_init();
	else
		machine_desc->init_irq();
L
Linus Torvalds 已提交
122 123
}

124 125 126 127 128 129 130 131 132 133
#ifdef CONFIG_MULTI_IRQ_HANDLER
void __init set_handle_irq(void (*handle_irq)(struct pt_regs *))
{
	if (handle_arch_irq)
		return;

	handle_arch_irq = handle_irq;
}
#endif

134 135 136
#ifdef CONFIG_SPARSE_IRQ
int __init arch_probe_nr_irqs(void)
{
137
	nr_irqs = machine_desc->nr_irqs ? machine_desc->nr_irqs : NR_IRQS;
138
	return nr_irqs;
139 140 141
}
#endif

142
#ifdef CONFIG_HOTPLUG_CPU
143

144
static bool migrate_one_irq(struct irq_desc *desc)
145
{
146
	struct irq_data *d = irq_desc_get_irq_data(desc);
147
	const struct cpumask *affinity = d->affinity;
148
	struct irq_chip *c;
149
	bool ret = false;
150

151 152 153 154 155 156 157
	/*
	 * If this is a per-CPU interrupt, or the affinity does not
	 * include this CPU, then we have nothing to do.
	 */
	if (irqd_is_per_cpu(d) || !cpumask_test_cpu(smp_processor_id(), affinity))
		return false;

158
	if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) {
159
		affinity = cpu_online_mask;
160 161 162
		ret = true;
	}

163
	c = irq_data_get_irq_chip(d);
164
	if (!c->irq_set_affinity)
165
		pr_debug("IRQ%u: unable to set affinity\n", d->irq);
166 167
	else if (c->irq_set_affinity(d, affinity, true) == IRQ_SET_MASK_OK && ret)
		cpumask_copy(d->affinity, affinity);
168 169

	return ret;
170 171
}

172
/*
173 174
 * The current CPU has been marked offline.  Migrate IRQs off this CPU.
 * If the affinity settings do not allow other CPUs, force them onto any
175
 * available CPU.
176 177 178
 *
 * Note: we must iterate over all IRQs, whether they have an attached
 * action structure or not, as we need to get chained interrupts too.
179 180 181
 */
void migrate_irqs(void)
{
182
	unsigned int i;
183
	struct irq_desc *desc;
184 185 186
	unsigned long flags;

	local_irq_save(flags);
187

188
	for_each_irq_desc(i, desc) {
189
		bool affinity_broken;
190

191
		raw_spin_lock(&desc->lock);
192
		affinity_broken = migrate_one_irq(desc);
193 194 195
		raw_spin_unlock(&desc->lock);

		if (affinity_broken && printk_ratelimit())
196 197
			pr_warning("IRQ%u no longer affine to CPU%u\n", i,
				smp_processor_id());
198
	}
199 200

	local_irq_restore(flags);
201 202
}
#endif /* CONFIG_HOTPLUG_CPU */