x86/efi: Enforce CONFIG_RELOCATABLE for EFI boot stub
[linux/fpc-iii.git] / arch / metag / kernel / irq.c
blob2a2c9d55187e075375e892abbc4e23139f63bf86
1 /*
2 * Linux/Meta general interrupt handling code
4 */
6 #include <linux/kernel.h>
7 #include <linux/interrupt.h>
8 #include <linux/init.h>
9 #include <linux/irqchip/metag-ext.h>
10 #include <linux/irqchip/metag.h>
11 #include <linux/irqdomain.h>
12 #include <linux/ratelimit.h>
14 #include <asm/core_reg.h>
15 #include <asm/mach/arch.h>
16 #include <asm/uaccess.h>
18 #ifdef CONFIG_4KSTACKS
19 union irq_ctx {
20 struct thread_info tinfo;
21 u32 stack[THREAD_SIZE/sizeof(u32)];
24 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
25 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
26 #endif
28 static struct irq_domain *root_domain;
30 static unsigned int startup_meta_irq(struct irq_data *data)
32 tbi_startup_interrupt(data->hwirq);
33 return 0;
36 static void shutdown_meta_irq(struct irq_data *data)
38 tbi_shutdown_interrupt(data->hwirq);
41 void do_IRQ(int irq, struct pt_regs *regs)
43 struct pt_regs *old_regs = set_irq_regs(regs);
44 #ifdef CONFIG_4KSTACKS
45 struct irq_desc *desc;
46 union irq_ctx *curctx, *irqctx;
47 u32 *isp;
48 #endif
50 irq_enter();
52 irq = irq_linear_revmap(root_domain, irq);
54 #ifdef CONFIG_DEBUG_STACKOVERFLOW
55 /* Debugging check for stack overflow: is there less than 1KB free? */
57 unsigned long sp;
59 sp = __core_reg_get(A0StP);
60 sp &= THREAD_SIZE - 1;
62 if (unlikely(sp > (THREAD_SIZE - 1024)))
63 pr_err("Stack overflow in do_IRQ: %ld\n", sp);
65 #endif
68 #ifdef CONFIG_4KSTACKS
69 curctx = (union irq_ctx *) current_thread_info();
70 irqctx = hardirq_ctx[smp_processor_id()];
73 * this is where we switch to the IRQ stack. However, if we are
74 * already using the IRQ stack (because we interrupted a hardirq
75 * handler) we can't do that and just have to keep using the
76 * current stack (which is the irq stack already after all)
78 if (curctx != irqctx) {
79 /* build the stack frame on the IRQ stack */
80 isp = (u32 *) ((char *)irqctx + sizeof(struct thread_info));
81 irqctx->tinfo.task = curctx->tinfo.task;
84 * Copy the softirq bits in preempt_count so that the
85 * softirq checks work in the hardirq context.
87 irqctx->tinfo.preempt_count =
88 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
89 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
91 desc = irq_to_desc(irq);
93 asm volatile (
94 "MOV D0.5,%0\n"
95 "MOV D1Ar1,%1\n"
96 "MOV D1RtP,%2\n"
97 "MOV D0Ar2,%3\n"
98 "SWAP A0StP,D0.5\n"
99 "SWAP PC,D1RtP\n"
100 "MOV A0StP,D0.5\n"
102 : "r" (isp), "r" (irq), "r" (desc->handle_irq),
103 "r" (desc)
104 : "memory", "cc", "D1Ar1", "D0Ar2", "D1Ar3", "D0Ar4",
105 "D1Ar5", "D0Ar6", "D0Re0", "D1Re0", "D0.4", "D1RtP",
106 "D0.5"
108 } else
109 #endif
110 generic_handle_irq(irq);
112 irq_exit();
114 set_irq_regs(old_regs);
117 #ifdef CONFIG_4KSTACKS
119 static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
121 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
124 * allocate per-cpu stacks for hardirq and for softirq processing
126 void irq_ctx_init(int cpu)
128 union irq_ctx *irqctx;
130 if (hardirq_ctx[cpu])
131 return;
133 irqctx = (union irq_ctx *) &hardirq_stack[cpu * THREAD_SIZE];
134 irqctx->tinfo.task = NULL;
135 irqctx->tinfo.exec_domain = NULL;
136 irqctx->tinfo.cpu = cpu;
137 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
138 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
140 hardirq_ctx[cpu] = irqctx;
142 irqctx = (union irq_ctx *) &softirq_stack[cpu * THREAD_SIZE];
143 irqctx->tinfo.task = NULL;
144 irqctx->tinfo.exec_domain = NULL;
145 irqctx->tinfo.cpu = cpu;
146 irqctx->tinfo.preempt_count = 0;
147 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
149 softirq_ctx[cpu] = irqctx;
151 pr_info("CPU %u irqstacks, hard=%p soft=%p\n",
152 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
155 void irq_ctx_exit(int cpu)
157 hardirq_ctx[smp_processor_id()] = NULL;
160 extern asmlinkage void __do_softirq(void);
162 asmlinkage void do_softirq(void)
164 unsigned long flags;
165 struct thread_info *curctx;
166 union irq_ctx *irqctx;
167 u32 *isp;
169 if (in_interrupt())
170 return;
172 local_irq_save(flags);
174 if (local_softirq_pending()) {
175 curctx = current_thread_info();
176 irqctx = softirq_ctx[smp_processor_id()];
177 irqctx->tinfo.task = curctx->task;
179 /* build the stack frame on the softirq stack */
180 isp = (u32 *) ((char *)irqctx + sizeof(struct thread_info));
182 asm volatile (
183 "MOV D0.5,%0\n"
184 "SWAP A0StP,D0.5\n"
185 "CALLR D1RtP,___do_softirq\n"
186 "MOV A0StP,D0.5\n"
188 : "r" (isp)
189 : "memory", "cc", "D1Ar1", "D0Ar2", "D1Ar3", "D0Ar4",
190 "D1Ar5", "D0Ar6", "D0Re0", "D1Re0", "D0.4", "D1RtP",
191 "D0.5"
194 * Shouldn't happen, we returned above if in_interrupt():
196 WARN_ON_ONCE(softirq_count());
199 local_irq_restore(flags);
201 #endif
203 static struct irq_chip meta_irq_type = {
204 .name = "META-IRQ",
205 .irq_startup = startup_meta_irq,
206 .irq_shutdown = shutdown_meta_irq,
210 * tbisig_map() - Map a TBI signal number to a virtual IRQ number.
211 * @hw: Number of the TBI signal. Must be in range.
213 * Returns: The virtual IRQ number of the TBI signal number IRQ specified by
214 * @hw.
216 int tbisig_map(unsigned int hw)
218 return irq_create_mapping(root_domain, hw);
222 * metag_tbisig_map() - map a tbi signal to a Linux virtual IRQ number
223 * @d: root irq domain
224 * @irq: virtual irq number
225 * @hw: hardware irq number (TBI signal number)
227 * This sets up a virtual irq for a specified TBI signal number.
229 static int metag_tbisig_map(struct irq_domain *d, unsigned int irq,
230 irq_hw_number_t hw)
232 #ifdef CONFIG_SMP
233 irq_set_chip_and_handler(irq, &meta_irq_type, handle_percpu_irq);
234 #else
235 irq_set_chip_and_handler(irq, &meta_irq_type, handle_simple_irq);
236 #endif
237 return 0;
240 static const struct irq_domain_ops metag_tbisig_domain_ops = {
241 .map = metag_tbisig_map,
245 * void init_IRQ(void)
247 * Parameters: None
249 * Returns: Nothing
251 * This function should be called during kernel startup to initialize
252 * the IRQ handling routines.
254 void __init init_IRQ(void)
256 root_domain = irq_domain_add_linear(NULL, 32,
257 &metag_tbisig_domain_ops, NULL);
258 if (unlikely(!root_domain))
259 panic("init_IRQ: cannot add root IRQ domain");
261 irq_ctx_init(smp_processor_id());
263 init_internal_IRQ();
264 init_external_IRQ();
266 if (machine_desc->init_irq)
267 machine_desc->init_irq();
270 int __init arch_probe_nr_irqs(void)
272 if (machine_desc->nr_irqs)
273 nr_irqs = machine_desc->nr_irqs;
274 return 0;
277 #ifdef CONFIG_HOTPLUG_CPU
278 static void route_irq(struct irq_data *data, unsigned int irq, unsigned int cpu)
280 struct irq_desc *desc = irq_to_desc(irq);
281 struct irq_chip *chip = irq_data_get_irq_chip(data);
282 unsigned long flags;
284 raw_spin_lock_irqsave(&desc->lock, flags);
285 if (chip->irq_set_affinity)
286 chip->irq_set_affinity(data, cpumask_of(cpu), false);
287 raw_spin_unlock_irqrestore(&desc->lock, flags);
291 * The CPU has been marked offline. Migrate IRQs off this CPU. If
292 * the affinity settings do not allow other CPUs, force them onto any
293 * available CPU.
295 void migrate_irqs(void)
297 unsigned int i, cpu = smp_processor_id();
298 struct irq_desc *desc;
300 for_each_irq_desc(i, desc) {
301 struct irq_data *data = irq_desc_get_irq_data(desc);
302 unsigned int newcpu;
304 if (irqd_is_per_cpu(data))
305 continue;
307 if (!cpumask_test_cpu(cpu, data->affinity))
308 continue;
310 newcpu = cpumask_any_and(data->affinity, cpu_online_mask);
312 if (newcpu >= nr_cpu_ids) {
313 pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
314 i, cpu);
316 cpumask_setall(data->affinity);
317 newcpu = cpumask_any_and(data->affinity,
318 cpu_online_mask);
321 route_irq(data, i, newcpu);
324 #endif /* CONFIG_HOTPLUG_CPU */