ARM: simplify early machine init hooks
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / kernel / irq.c
bloba591971dbf7b75bf662a9c405054a5623b286b3b
1 /*
2 * linux/arch/arm/kernel/irq.c
4 * Copyright (C) 1992 Linus Torvalds
5 * Modifications for ARM processor Copyright (C) 1995-2000 Russell King.
7 * Support for Dynamic Tick Timer Copyright (C) 2004-2005 Nokia Corporation.
8 * Dynamic Tick Timer written by Tony Lindgren <tony@atomide.com> and
9 * Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This file contains the code used by various IRQ handling routines:
16 * asking for different IRQ's should be done through these routines
17 * instead of just grabbing them. Thus setups with different IRQ numbers
18 * shouldn't result in any weird surprises, and installing new handlers
19 * should be easier.
21 * IRQ's are in fact implemented a bit like signal handlers for the kernel.
22 * Naturally it's not a 1:1 relation, but there are similarities.
24 #include <linux/kernel_stat.h>
25 #include <linux/module.h>
26 #include <linux/signal.h>
27 #include <linux/ioport.h>
28 #include <linux/interrupt.h>
29 #include <linux/irq.h>
30 #include <linux/random.h>
31 #include <linux/smp.h>
32 #include <linux/init.h>
33 #include <linux/seq_file.h>
34 #include <linux/errno.h>
35 #include <linux/list.h>
36 #include <linux/kallsyms.h>
37 #include <linux/proc_fs.h>
39 #include <asm/system.h>
40 #include <asm/mach/arch.h>
41 #include <asm/mach/irq.h>
42 #include <asm/mach/time.h>
45 * No architecture-specific irq_finish function defined in arm/arch/irqs.h.
47 #ifndef irq_finish
48 #define irq_finish(irq) do { } while (0)
49 #endif
51 unsigned long irq_err_count;
53 int show_interrupts(struct seq_file *p, void *v)
55 int i = *(loff_t *) v, cpu;
56 struct irq_desc *desc;
57 struct irqaction * action;
58 unsigned long flags;
60 if (i == 0) {
61 char cpuname[12];
63 seq_printf(p, " ");
64 for_each_present_cpu(cpu) {
65 sprintf(cpuname, "CPU%d", cpu);
66 seq_printf(p, " %10s", cpuname);
68 seq_putc(p, '\n');
71 if (i < nr_irqs) {
72 desc = irq_to_desc(i);
73 raw_spin_lock_irqsave(&desc->lock, flags);
74 action = desc->action;
75 if (!action)
76 goto unlock;
78 seq_printf(p, "%3d: ", i);
79 for_each_present_cpu(cpu)
80 seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));
81 seq_printf(p, " %10s", desc->chip->name ? : "-");
82 seq_printf(p, " %s", action->name);
83 for (action = action->next; action; action = action->next)
84 seq_printf(p, ", %s", action->name);
86 seq_putc(p, '\n');
87 unlock:
88 raw_spin_unlock_irqrestore(&desc->lock, flags);
89 } else if (i == nr_irqs) {
90 #ifdef CONFIG_FIQ
91 show_fiq_list(p, v);
92 #endif
93 #ifdef CONFIG_SMP
94 show_ipi_list(p);
95 show_local_irqs(p);
96 #endif
97 seq_printf(p, "Err: %10lu\n", irq_err_count);
99 return 0;
103 * do_IRQ handles all hardware IRQ's. Decoded IRQs should not
104 * come via this function. Instead, they should provide their
105 * own 'handler'
107 asmlinkage void __exception asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
109 struct pt_regs *old_regs = set_irq_regs(regs);
111 irq_enter();
114 * Some hardware gives randomly wrong interrupts. Rather
115 * than crashing, do something sensible.
117 if (unlikely(irq >= nr_irqs)) {
118 if (printk_ratelimit())
119 printk(KERN_WARNING "Bad IRQ%u\n", irq);
120 ack_bad_irq(irq);
121 } else {
122 generic_handle_irq(irq);
125 /* AT91 specific workaround */
126 irq_finish(irq);
128 irq_exit();
129 set_irq_regs(old_regs);
132 void set_irq_flags(unsigned int irq, unsigned int iflags)
134 struct irq_desc *desc;
135 unsigned long flags;
137 if (irq >= nr_irqs) {
138 printk(KERN_ERR "Trying to set irq flags for IRQ%d\n", irq);
139 return;
142 desc = irq_to_desc(irq);
143 raw_spin_lock_irqsave(&desc->lock, flags);
144 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
145 if (iflags & IRQF_VALID)
146 desc->status &= ~IRQ_NOREQUEST;
147 if (iflags & IRQF_PROBE)
148 desc->status &= ~IRQ_NOPROBE;
149 if (!(iflags & IRQF_NOAUTOEN))
150 desc->status &= ~IRQ_NOAUTOEN;
151 raw_spin_unlock_irqrestore(&desc->lock, flags);
154 void __init init_IRQ(void)
156 machine_desc->init_irq();
159 #ifdef CONFIG_SPARSE_IRQ
160 int __init arch_probe_nr_irqs(void)
162 nr_irqs = machine_desc->nr_irqs ? machine_desc->nr_irqs : NR_IRQS;
163 return nr_irqs;
165 #endif
167 #ifdef CONFIG_HOTPLUG_CPU
169 static void route_irq(struct irq_desc *desc, unsigned int irq, unsigned int cpu)
171 pr_debug("IRQ%u: moving from cpu%u to cpu%u\n", irq, desc->node, cpu);
173 raw_spin_lock_irq(&desc->lock);
174 desc->chip->set_affinity(irq, cpumask_of(cpu));
175 raw_spin_unlock_irq(&desc->lock);
179 * The CPU has been marked offline. Migrate IRQs off this CPU. If
180 * the affinity settings do not allow other CPUs, force them onto any
181 * available CPU.
183 void migrate_irqs(void)
185 unsigned int i, cpu = smp_processor_id();
186 struct irq_desc *desc;
188 for_each_irq_desc(i, desc) {
189 if (desc->node == cpu) {
190 unsigned int newcpu = cpumask_any_and(desc->affinity,
191 cpu_online_mask);
192 if (newcpu >= nr_cpu_ids) {
193 if (printk_ratelimit())
194 printk(KERN_INFO "IRQ%u no longer affine to CPU%u\n",
195 i, cpu);
197 cpumask_setall(desc->affinity);
198 newcpu = cpumask_any_and(desc->affinity,
199 cpu_online_mask);
202 route_irq(desc, i, newcpu);
206 #endif /* CONFIG_HOTPLUG_CPU */