Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Derived from arch/i386/kernel/irq.c |
3 | * Copyright (C) 1992 Linus Torvalds | |
4 | * Adapted from arch/i386 by Gary Thomas | |
5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | |
756e7104 SR |
6 | * Updated and modified by Cort Dougan <cort@fsmlabs.com> |
7 | * Copyright (C) 1996-2001 Cort Dougan | |
1da177e4 LT |
8 | * Adapted for Power Macintosh by Paul Mackerras |
9 | * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au) | |
10 | * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk). | |
756e7104 | 11 | * |
1da177e4 LT |
12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU General Public License | |
14 | * as published by the Free Software Foundation; either version | |
15 | * 2 of the License, or (at your option) any later version. | |
16 | * | |
17 | * This file contains the code used by various IRQ handling routines: | |
18 | * asking for different IRQ's should be done through these routines | |
19 | * instead of just grabbing them. Thus setups with different IRQ numbers | |
20 | * shouldn't result in any weird surprises, and installing new handlers | |
21 | * should be easier. | |
756e7104 SR |
22 | * |
23 | * The MPC8xx has an interrupt mask in the SIU. If a bit is set, the | |
24 | * interrupt is _enabled_. As expected, IRQ0 is bit 0 in the 32-bit | |
25 | * mask register (of which only 16 are defined), hence the weird shifting | |
26 | * and complement of the cached_irq_mask. I want to be able to stuff | |
27 | * this right into the SIU SMASK register. | |
28 | * Many of the prep/chrp functions are conditional compiled on CONFIG_8xx | |
29 | * to reduce code space and undefined function references. | |
1da177e4 LT |
30 | */ |
31 | ||
1da177e4 LT |
32 | #include <linux/module.h> |
33 | #include <linux/threads.h> | |
34 | #include <linux/kernel_stat.h> | |
35 | #include <linux/signal.h> | |
36 | #include <linux/sched.h> | |
756e7104 | 37 | #include <linux/ptrace.h> |
1da177e4 LT |
38 | #include <linux/ioport.h> |
39 | #include <linux/interrupt.h> | |
40 | #include <linux/timex.h> | |
41 | #include <linux/config.h> | |
42 | #include <linux/init.h> | |
43 | #include <linux/slab.h> | |
1da177e4 LT |
44 | #include <linux/delay.h> |
45 | #include <linux/irq.h> | |
756e7104 SR |
46 | #include <linux/seq_file.h> |
47 | #include <linux/cpumask.h> | |
1da177e4 LT |
48 | #include <linux/profile.h> |
49 | #include <linux/bitops.h> | |
50 | ||
51 | #include <asm/uaccess.h> | |
52 | #include <asm/system.h> | |
53 | #include <asm/io.h> | |
54 | #include <asm/pgtable.h> | |
55 | #include <asm/irq.h> | |
56 | #include <asm/cache.h> | |
57 | #include <asm/prom.h> | |
58 | #include <asm/ptrace.h> | |
1da177e4 | 59 | #include <asm/machdep.h> |
a50b56d2 | 60 | #ifdef CONFIG_PPC_ISERIES |
1da177e4 | 61 | #include <asm/paca.h> |
756e7104 | 62 | #endif |
1da177e4 | 63 | |
868accb7 SR |
64 | int __irq_offset_value; |
65 | #ifdef CONFIG_PPC32 | |
66 | EXPORT_SYMBOL(__irq_offset_value); | |
67 | #endif | |
68 | ||
756e7104 SR |
69 | static int ppc_spurious_interrupts; |
70 | ||
756e7104 SR |
71 | #ifdef CONFIG_PPC32 |
72 | #define NR_MASK_WORDS ((NR_IRQS + 31) / 32) | |
73 | ||
74 | unsigned long ppc_cached_irq_mask[NR_MASK_WORDS]; | |
75 | atomic_t ppc_n_lost_interrupts; | |
76 | ||
77 | #ifdef CONFIG_TAU_INT | |
78 | extern int tau_initialized; | |
79 | extern int tau_interrupts(int); | |
80 | #endif | |
81 | ||
82 | #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_MERGE) | |
83 | extern atomic_t ipi_recv; | |
84 | extern atomic_t ipi_sent; | |
85 | #endif | |
86 | #endif /* CONFIG_PPC32 */ | |
87 | ||
88 | #ifdef CONFIG_PPC64 | |
1da177e4 LT |
89 | EXPORT_SYMBOL(irq_desc); |
90 | ||
91 | int distribute_irqs = 1; | |
1da177e4 | 92 | u64 ppc64_interrupt_controller; |
756e7104 | 93 | #endif /* CONFIG_PPC64 */ |
1da177e4 LT |
94 | |
95 | int show_interrupts(struct seq_file *p, void *v) | |
96 | { | |
756e7104 SR |
97 | int i = *(loff_t *)v, j; |
98 | struct irqaction *action; | |
1da177e4 LT |
99 | irq_desc_t *desc; |
100 | unsigned long flags; | |
101 | ||
102 | if (i == 0) { | |
756e7104 SR |
103 | seq_puts(p, " "); |
104 | for_each_online_cpu(j) | |
105 | seq_printf(p, "CPU%d ", j); | |
1da177e4 LT |
106 | seq_putc(p, '\n'); |
107 | } | |
108 | ||
109 | if (i < NR_IRQS) { | |
110 | desc = get_irq_desc(i); | |
111 | spin_lock_irqsave(&desc->lock, flags); | |
112 | action = desc->action; | |
113 | if (!action || !action->handler) | |
114 | goto skip; | |
115 | seq_printf(p, "%3d: ", i); | |
116 | #ifdef CONFIG_SMP | |
756e7104 SR |
117 | for_each_online_cpu(j) |
118 | seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]); | |
1da177e4 LT |
119 | #else |
120 | seq_printf(p, "%10u ", kstat_irqs(i)); | |
121 | #endif /* CONFIG_SMP */ | |
122 | if (desc->handler) | |
756e7104 | 123 | seq_printf(p, " %s ", desc->handler->typename); |
1da177e4 | 124 | else |
756e7104 | 125 | seq_puts(p, " None "); |
1da177e4 | 126 | seq_printf(p, "%s", (desc->status & IRQ_LEVEL) ? "Level " : "Edge "); |
756e7104 SR |
127 | seq_printf(p, " %s", action->name); |
128 | for (action = action->next; action; action = action->next) | |
1da177e4 LT |
129 | seq_printf(p, ", %s", action->name); |
130 | seq_putc(p, '\n'); | |
131 | skip: | |
132 | spin_unlock_irqrestore(&desc->lock, flags); | |
756e7104 SR |
133 | } else if (i == NR_IRQS) { |
134 | #ifdef CONFIG_PPC32 | |
135 | #ifdef CONFIG_TAU_INT | |
136 | if (tau_initialized){ | |
137 | seq_puts(p, "TAU: "); | |
138 | for (j = 0; j < NR_CPUS; j++) | |
139 | if (cpu_online(j)) | |
140 | seq_printf(p, "%10u ", tau_interrupts(j)); | |
141 | seq_puts(p, " PowerPC Thermal Assist (cpu temp)\n"); | |
142 | } | |
143 | #endif | |
144 | #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_MERGE) | |
145 | /* should this be per processor send/receive? */ | |
146 | seq_printf(p, "IPI (recv/sent): %10u/%u\n", | |
147 | atomic_read(&ipi_recv), atomic_read(&ipi_sent)); | |
148 | #endif | |
149 | #endif /* CONFIG_PPC32 */ | |
1da177e4 | 150 | seq_printf(p, "BAD: %10u\n", ppc_spurious_interrupts); |
756e7104 | 151 | } |
1da177e4 LT |
152 | return 0; |
153 | } | |
154 | ||
155 | #ifdef CONFIG_HOTPLUG_CPU | |
156 | void fixup_irqs(cpumask_t map) | |
157 | { | |
158 | unsigned int irq; | |
159 | static int warned; | |
160 | ||
161 | for_each_irq(irq) { | |
162 | cpumask_t mask; | |
163 | ||
164 | if (irq_desc[irq].status & IRQ_PER_CPU) | |
165 | continue; | |
166 | ||
167 | cpus_and(mask, irq_affinity[irq], map); | |
168 | if (any_online_cpu(mask) == NR_CPUS) { | |
169 | printk("Breaking affinity for irq %i\n", irq); | |
170 | mask = map; | |
171 | } | |
172 | if (irq_desc[irq].handler->set_affinity) | |
173 | irq_desc[irq].handler->set_affinity(irq, mask); | |
174 | else if (irq_desc[irq].action && !(warned++)) | |
175 | printk("Cannot set affinity for irq %i\n", irq); | |
176 | } | |
177 | ||
178 | local_irq_enable(); | |
179 | mdelay(1); | |
180 | local_irq_disable(); | |
181 | } | |
182 | #endif | |
183 | ||
1da177e4 LT |
184 | void do_IRQ(struct pt_regs *regs) |
185 | { | |
186 | int irq; | |
b709c083 SR |
187 | #ifdef CONFIG_IRQSTACKS |
188 | struct thread_info *curtp, *irqtp; | |
189 | #endif | |
1da177e4 | 190 | |
756e7104 | 191 | irq_enter(); |
1da177e4 LT |
192 | |
193 | #ifdef CONFIG_DEBUG_STACKOVERFLOW | |
194 | /* Debugging check for stack overflow: is there less than 2KB free? */ | |
195 | { | |
196 | long sp; | |
197 | ||
198 | sp = __get_SP() & (THREAD_SIZE-1); | |
199 | ||
200 | if (unlikely(sp < (sizeof(struct thread_info) + 2048))) { | |
201 | printk("do_IRQ: stack overflow: %ld\n", | |
202 | sp - sizeof(struct thread_info)); | |
203 | dump_stack(); | |
204 | } | |
205 | } | |
206 | #endif | |
207 | ||
756e7104 SR |
208 | /* |
209 | * Every platform is required to implement ppc_md.get_irq. | |
210 | * This function will either return an irq number or -1 to | |
211 | * indicate there are no more pending. | |
212 | * The value -2 is for buggy hardware and means that this IRQ | |
213 | * has already been handled. -- Tom | |
214 | */ | |
1da177e4 LT |
215 | irq = ppc_md.get_irq(regs); |
216 | ||
b709c083 SR |
217 | if (irq >= 0) { |
218 | #ifdef CONFIG_IRQSTACKS | |
219 | /* Switch to the irq stack to handle this */ | |
220 | curtp = current_thread_info(); | |
221 | irqtp = hardirq_ctx[smp_processor_id()]; | |
222 | if (curtp != irqtp) { | |
223 | irqtp->task = curtp->task; | |
224 | irqtp->flags = 0; | |
d4be4f37 | 225 | call___do_IRQ(irq, regs, irqtp); |
b709c083 SR |
226 | irqtp->task = NULL; |
227 | if (irqtp->flags) | |
228 | set_bits(irqtp->flags, &curtp->flags); | |
229 | } else | |
230 | #endif | |
d4be4f37 | 231 | __do_IRQ(irq, regs); |
e199500c SR |
232 | } else if (irq != -2) |
233 | /* That's not SMP safe ... but who cares ? */ | |
234 | ppc_spurious_interrupts++; | |
235 | ||
756e7104 | 236 | irq_exit(); |
756e7104 | 237 | |
e199500c | 238 | #ifdef CONFIG_PPC_ISERIES |
3356bb9f DG |
239 | if (get_lppaca()->int_dword.fields.decr_int) { |
240 | get_lppaca()->int_dword.fields.decr_int = 0; | |
241 | /* Signal a fake decrementer interrupt */ | |
242 | timer_interrupt(regs); | |
e199500c SR |
243 | } |
244 | #endif | |
245 | } | |
1da177e4 LT |
246 | |
247 | void __init init_IRQ(void) | |
248 | { | |
756e7104 | 249 | #ifdef CONFIG_PPC64 |
1da177e4 LT |
250 | static int once = 0; |
251 | ||
252 | if (once) | |
253 | return; | |
254 | ||
255 | once++; | |
256 | ||
756e7104 | 257 | #endif |
1da177e4 | 258 | ppc_md.init_IRQ(); |
756e7104 | 259 | #ifdef CONFIG_PPC64 |
1da177e4 | 260 | irq_ctx_init(); |
756e7104 | 261 | #endif |
1da177e4 LT |
262 | } |
263 | ||
756e7104 | 264 | #ifdef CONFIG_PPC64 |
1da177e4 LT |
265 | /* |
266 | * Virtual IRQ mapping code, used on systems with XICS interrupt controllers. | |
267 | */ | |
268 | ||
269 | #define UNDEFINED_IRQ 0xffffffff | |
270 | unsigned int virt_irq_to_real_map[NR_IRQS]; | |
271 | ||
272 | /* | |
273 | * Don't use virtual irqs 0, 1, 2 for devices. | |
274 | * The pcnet32 driver considers interrupt numbers < 2 to be invalid, | |
275 | * and 2 is the XICS IPI interrupt. | |
276 | * We limit virtual irqs to 17 less than NR_IRQS so that when we | |
277 | * offset them by 16 (to reserve the first 16 for ISA interrupts) | |
278 | * we don't end up with an interrupt number >= NR_IRQS. | |
279 | */ | |
280 | #define MIN_VIRT_IRQ 3 | |
281 | #define MAX_VIRT_IRQ (NR_IRQS - NUM_ISA_INTERRUPTS - 1) | |
282 | #define NR_VIRT_IRQS (MAX_VIRT_IRQ - MIN_VIRT_IRQ + 1) | |
283 | ||
284 | void | |
285 | virt_irq_init(void) | |
286 | { | |
287 | int i; | |
288 | for (i = 0; i < NR_IRQS; i++) | |
289 | virt_irq_to_real_map[i] = UNDEFINED_IRQ; | |
290 | } | |
291 | ||
292 | /* Create a mapping for a real_irq if it doesn't already exist. | |
293 | * Return the virtual irq as a convenience. | |
294 | */ | |
295 | int virt_irq_create_mapping(unsigned int real_irq) | |
296 | { | |
297 | unsigned int virq, first_virq; | |
298 | static int warned; | |
299 | ||
300 | if (ppc64_interrupt_controller == IC_OPEN_PIC) | |
301 | return real_irq; /* no mapping for openpic (for now) */ | |
302 | ||
f3f66f59 | 303 | if (ppc64_interrupt_controller == IC_CELL_PIC) |
fef1c772 AB |
304 | return real_irq; /* no mapping for iic either */ |
305 | ||
1da177e4 LT |
306 | /* don't map interrupts < MIN_VIRT_IRQ */ |
307 | if (real_irq < MIN_VIRT_IRQ) { | |
308 | virt_irq_to_real_map[real_irq] = real_irq; | |
309 | return real_irq; | |
310 | } | |
311 | ||
312 | /* map to a number between MIN_VIRT_IRQ and MAX_VIRT_IRQ */ | |
313 | virq = real_irq; | |
314 | if (virq > MAX_VIRT_IRQ) | |
315 | virq = (virq % NR_VIRT_IRQS) + MIN_VIRT_IRQ; | |
316 | ||
317 | /* search for this number or a free slot */ | |
318 | first_virq = virq; | |
319 | while (virt_irq_to_real_map[virq] != UNDEFINED_IRQ) { | |
320 | if (virt_irq_to_real_map[virq] == real_irq) | |
321 | return virq; | |
322 | if (++virq > MAX_VIRT_IRQ) | |
323 | virq = MIN_VIRT_IRQ; | |
324 | if (virq == first_virq) | |
325 | goto nospace; /* oops, no free slots */ | |
326 | } | |
327 | ||
328 | virt_irq_to_real_map[virq] = real_irq; | |
329 | return virq; | |
330 | ||
331 | nospace: | |
332 | if (!warned) { | |
333 | printk(KERN_CRIT "Interrupt table is full\n"); | |
334 | printk(KERN_CRIT "Increase NR_IRQS (currently %d) " | |
335 | "in your kernel sources and rebuild.\n", NR_IRQS); | |
336 | warned = 1; | |
337 | } | |
338 | return NO_IRQ; | |
339 | } | |
340 | ||
341 | /* | |
342 | * In most cases will get a hit on the very first slot checked in the | |
343 | * virt_irq_to_real_map. Only when there are a large number of | |
344 | * IRQs will this be expensive. | |
345 | */ | |
346 | unsigned int real_irq_to_virt_slowpath(unsigned int real_irq) | |
347 | { | |
348 | unsigned int virq; | |
349 | unsigned int first_virq; | |
350 | ||
351 | virq = real_irq; | |
352 | ||
353 | if (virq > MAX_VIRT_IRQ) | |
354 | virq = (virq % NR_VIRT_IRQS) + MIN_VIRT_IRQ; | |
355 | ||
356 | first_virq = virq; | |
357 | ||
358 | do { | |
359 | if (virt_irq_to_real_map[virq] == real_irq) | |
360 | return virq; | |
361 | ||
362 | virq++; | |
363 | ||
364 | if (virq >= MAX_VIRT_IRQ) | |
365 | virq = 0; | |
366 | ||
367 | } while (first_virq != virq); | |
368 | ||
369 | return NO_IRQ; | |
370 | ||
371 | } | |
372 | ||
1da177e4 LT |
373 | #ifdef CONFIG_IRQSTACKS |
374 | struct thread_info *softirq_ctx[NR_CPUS]; | |
375 | struct thread_info *hardirq_ctx[NR_CPUS]; | |
376 | ||
377 | void irq_ctx_init(void) | |
378 | { | |
379 | struct thread_info *tp; | |
380 | int i; | |
381 | ||
382 | for_each_cpu(i) { | |
383 | memset((void *)softirq_ctx[i], 0, THREAD_SIZE); | |
384 | tp = softirq_ctx[i]; | |
385 | tp->cpu = i; | |
386 | tp->preempt_count = SOFTIRQ_OFFSET; | |
387 | ||
388 | memset((void *)hardirq_ctx[i], 0, THREAD_SIZE); | |
389 | tp = hardirq_ctx[i]; | |
390 | tp->cpu = i; | |
391 | tp->preempt_count = HARDIRQ_OFFSET; | |
392 | } | |
393 | } | |
394 | ||
395 | void do_softirq(void) | |
396 | { | |
397 | unsigned long flags; | |
398 | struct thread_info *curtp, *irqtp; | |
399 | ||
400 | if (in_interrupt()) | |
401 | return; | |
402 | ||
403 | local_irq_save(flags); | |
404 | ||
405 | if (local_softirq_pending()) { | |
406 | curtp = current_thread_info(); | |
407 | irqtp = softirq_ctx[smp_processor_id()]; | |
408 | irqtp->task = curtp->task; | |
409 | call_do_softirq(irqtp); | |
410 | irqtp->task = NULL; | |
411 | } | |
412 | ||
413 | local_irq_restore(flags); | |
414 | } | |
415 | EXPORT_SYMBOL(do_softirq); | |
416 | ||
417 | #endif /* CONFIG_IRQSTACKS */ | |
418 | ||
419 | static int __init setup_noirqdistrib(char *str) | |
420 | { | |
421 | distribute_irqs = 0; | |
422 | return 1; | |
423 | } | |
424 | ||
425 | __setup("noirqdistrib", setup_noirqdistrib); | |
756e7104 | 426 | #endif /* CONFIG_PPC64 */ |