irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  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)
  6. * Updated and modified by Cort Dougan <cort@fsmlabs.com>
  7. * Copyright (C) 1996-2001 Cort Dougan
  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).
  11. *
  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.
  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.
  30. */
  31. #include <linux/module.h>
  32. #include <linux/threads.h>
  33. #include <linux/kernel_stat.h>
  34. #include <linux/signal.h>
  35. #include <linux/sched.h>
  36. #include <linux/ptrace.h>
  37. #include <linux/ioport.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/timex.h>
  40. #include <linux/config.h>
  41. #include <linux/init.h>
  42. #include <linux/slab.h>
  43. #include <linux/delay.h>
  44. #include <linux/irq.h>
  45. #include <linux/seq_file.h>
  46. #include <linux/cpumask.h>
  47. #include <linux/profile.h>
  48. #include <linux/bitops.h>
  49. #include <asm/uaccess.h>
  50. #include <asm/system.h>
  51. #include <asm/io.h>
  52. #include <asm/pgtable.h>
  53. #include <asm/irq.h>
  54. #include <asm/cache.h>
  55. #include <asm/prom.h>
  56. #include <asm/ptrace.h>
  57. #include <asm/machdep.h>
  58. #ifdef CONFIG_PPC_ISERIES
  59. #include <asm/paca.h>
  60. #endif
  61. int __irq_offset_value;
  62. #ifdef CONFIG_PPC32
  63. EXPORT_SYMBOL(__irq_offset_value);
  64. #endif
  65. static int ppc_spurious_interrupts;
  66. #ifdef CONFIG_PPC32
  67. #define NR_MASK_WORDS ((NR_IRQS + 31) / 32)
  68. unsigned long ppc_cached_irq_mask[NR_MASK_WORDS];
  69. atomic_t ppc_n_lost_interrupts;
  70. #ifdef CONFIG_TAU_INT
  71. extern int tau_initialized;
  72. extern int tau_interrupts(int);
  73. #endif
  74. #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_MERGE)
  75. extern atomic_t ipi_recv;
  76. extern atomic_t ipi_sent;
  77. #endif
  78. #endif /* CONFIG_PPC32 */
  79. #ifdef CONFIG_PPC64
  80. EXPORT_SYMBOL(irq_desc);
  81. int distribute_irqs = 1;
  82. u64 ppc64_interrupt_controller;
  83. #endif /* CONFIG_PPC64 */
  84. int show_interrupts(struct seq_file *p, void *v)
  85. {
  86. int i = *(loff_t *)v, j;
  87. struct irqaction *action;
  88. irq_desc_t *desc;
  89. unsigned long flags;
  90. if (i == 0) {
  91. seq_puts(p, " ");
  92. for_each_online_cpu(j)
  93. seq_printf(p, "CPU%d ", j);
  94. seq_putc(p, '\n');
  95. }
  96. if (i < NR_IRQS) {
  97. desc = get_irq_desc(i);
  98. spin_lock_irqsave(&desc->lock, flags);
  99. action = desc->action;
  100. if (!action || !action->handler)
  101. goto skip;
  102. seq_printf(p, "%3d: ", i);
  103. #ifdef CONFIG_SMP
  104. for_each_online_cpu(j)
  105. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  106. #else
  107. seq_printf(p, "%10u ", kstat_irqs(i));
  108. #endif /* CONFIG_SMP */
  109. if (desc->handler)
  110. seq_printf(p, " %s ", desc->handler->typename);
  111. else
  112. seq_puts(p, " None ");
  113. seq_printf(p, "%s", (desc->status & IRQ_LEVEL) ? "Level " : "Edge ");
  114. seq_printf(p, " %s", action->name);
  115. for (action = action->next; action; action = action->next)
  116. seq_printf(p, ", %s", action->name);
  117. seq_putc(p, '\n');
  118. skip:
  119. spin_unlock_irqrestore(&desc->lock, flags);
  120. } else if (i == NR_IRQS) {
  121. #ifdef CONFIG_PPC32
  122. #ifdef CONFIG_TAU_INT
  123. if (tau_initialized){
  124. seq_puts(p, "TAU: ");
  125. for_each_online_cpu(j)
  126. seq_printf(p, "%10u ", tau_interrupts(j));
  127. seq_puts(p, " PowerPC Thermal Assist (cpu temp)\n");
  128. }
  129. #endif
  130. #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_MERGE)
  131. /* should this be per processor send/receive? */
  132. seq_printf(p, "IPI (recv/sent): %10u/%u\n",
  133. atomic_read(&ipi_recv), atomic_read(&ipi_sent));
  134. #endif
  135. #endif /* CONFIG_PPC32 */
  136. seq_printf(p, "BAD: %10u\n", ppc_spurious_interrupts);
  137. }
  138. return 0;
  139. }
  140. #ifdef CONFIG_HOTPLUG_CPU
  141. void fixup_irqs(cpumask_t map)
  142. {
  143. unsigned int irq;
  144. static int warned;
  145. for_each_irq(irq) {
  146. cpumask_t mask;
  147. if (irq_desc[irq].status & IRQ_PER_CPU)
  148. continue;
  149. cpus_and(mask, irq_affinity[irq], map);
  150. if (any_online_cpu(mask) == NR_CPUS) {
  151. printk("Breaking affinity for irq %i\n", irq);
  152. mask = map;
  153. }
  154. if (irq_desc[irq].handler->set_affinity)
  155. irq_desc[irq].handler->set_affinity(irq, mask);
  156. else if (irq_desc[irq].action && !(warned++))
  157. printk("Cannot set affinity for irq %i\n", irq);
  158. }
  159. local_irq_enable();
  160. mdelay(1);
  161. local_irq_disable();
  162. }
  163. #endif
  164. void do_IRQ(struct pt_regs *regs)
  165. {
  166. int irq;
  167. #ifdef CONFIG_IRQSTACKS
  168. struct thread_info *curtp, *irqtp;
  169. #endif
  170. irq_enter();
  171. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  172. /* Debugging check for stack overflow: is there less than 2KB free? */
  173. {
  174. long sp;
  175. sp = __get_SP() & (THREAD_SIZE-1);
  176. if (unlikely(sp < (sizeof(struct thread_info) + 2048))) {
  177. printk("do_IRQ: stack overflow: %ld\n",
  178. sp - sizeof(struct thread_info));
  179. dump_stack();
  180. }
  181. }
  182. #endif
  183. /*
  184. * Every platform is required to implement ppc_md.get_irq.
  185. * This function will either return an irq number or -1 to
  186. * indicate there are no more pending.
  187. * The value -2 is for buggy hardware and means that this IRQ
  188. * has already been handled. -- Tom
  189. */
  190. irq = ppc_md.get_irq(regs);
  191. if (irq >= 0) {
  192. #ifdef CONFIG_IRQSTACKS
  193. /* Switch to the irq stack to handle this */
  194. curtp = current_thread_info();
  195. irqtp = hardirq_ctx[smp_processor_id()];
  196. if (curtp != irqtp) {
  197. irqtp->task = curtp->task;
  198. irqtp->flags = 0;
  199. call___do_IRQ(irq, regs, irqtp);
  200. irqtp->task = NULL;
  201. if (irqtp->flags)
  202. set_bits(irqtp->flags, &curtp->flags);
  203. } else
  204. #endif
  205. __do_IRQ(irq, regs);
  206. } else if (irq != -2)
  207. /* That's not SMP safe ... but who cares ? */
  208. ppc_spurious_interrupts++;
  209. irq_exit();
  210. #ifdef CONFIG_PPC_ISERIES
  211. if (get_lppaca()->int_dword.fields.decr_int) {
  212. get_lppaca()->int_dword.fields.decr_int = 0;
  213. /* Signal a fake decrementer interrupt */
  214. timer_interrupt(regs);
  215. }
  216. #endif
  217. }
  218. void __init init_IRQ(void)
  219. {
  220. #ifdef CONFIG_PPC64
  221. static int once = 0;
  222. if (once)
  223. return;
  224. once++;
  225. #endif
  226. ppc_md.init_IRQ();
  227. #ifdef CONFIG_PPC64
  228. irq_ctx_init();
  229. #endif
  230. }
  231. #ifdef CONFIG_PPC64
  232. /*
  233. * Virtual IRQ mapping code, used on systems with XICS interrupt controllers.
  234. */
  235. #define UNDEFINED_IRQ 0xffffffff
  236. unsigned int virt_irq_to_real_map[NR_IRQS];
  237. /*
  238. * Don't use virtual irqs 0, 1, 2 for devices.
  239. * The pcnet32 driver considers interrupt numbers < 2 to be invalid,
  240. * and 2 is the XICS IPI interrupt.
  241. * We limit virtual irqs to __irq_offet_value less than virt_irq_max so
  242. * that when we offset them we don't end up with an interrupt
  243. * number >= virt_irq_max.
  244. */
  245. #define MIN_VIRT_IRQ 3
  246. unsigned int virt_irq_max;
  247. static unsigned int max_virt_irq;
  248. static unsigned int nr_virt_irqs;
  249. void
  250. virt_irq_init(void)
  251. {
  252. int i;
  253. if ((virt_irq_max == 0) || (virt_irq_max > (NR_IRQS - 1)))
  254. virt_irq_max = NR_IRQS - 1;
  255. max_virt_irq = virt_irq_max - __irq_offset_value;
  256. nr_virt_irqs = max_virt_irq - MIN_VIRT_IRQ + 1;
  257. for (i = 0; i < NR_IRQS; i++)
  258. virt_irq_to_real_map[i] = UNDEFINED_IRQ;
  259. }
  260. /* Create a mapping for a real_irq if it doesn't already exist.
  261. * Return the virtual irq as a convenience.
  262. */
  263. int virt_irq_create_mapping(unsigned int real_irq)
  264. {
  265. unsigned int virq, first_virq;
  266. static int warned;
  267. if (ppc64_interrupt_controller == IC_OPEN_PIC)
  268. return real_irq; /* no mapping for openpic (for now) */
  269. if (ppc64_interrupt_controller == IC_CELL_PIC)
  270. return real_irq; /* no mapping for iic either */
  271. /* don't map interrupts < MIN_VIRT_IRQ */
  272. if (real_irq < MIN_VIRT_IRQ) {
  273. virt_irq_to_real_map[real_irq] = real_irq;
  274. return real_irq;
  275. }
  276. /* map to a number between MIN_VIRT_IRQ and max_virt_irq */
  277. virq = real_irq;
  278. if (virq > max_virt_irq)
  279. virq = (virq % nr_virt_irqs) + MIN_VIRT_IRQ;
  280. /* search for this number or a free slot */
  281. first_virq = virq;
  282. while (virt_irq_to_real_map[virq] != UNDEFINED_IRQ) {
  283. if (virt_irq_to_real_map[virq] == real_irq)
  284. return virq;
  285. if (++virq > max_virt_irq)
  286. virq = MIN_VIRT_IRQ;
  287. if (virq == first_virq)
  288. goto nospace; /* oops, no free slots */
  289. }
  290. virt_irq_to_real_map[virq] = real_irq;
  291. return virq;
  292. nospace:
  293. if (!warned) {
  294. printk(KERN_CRIT "Interrupt table is full\n");
  295. printk(KERN_CRIT "Increase virt_irq_max (currently %d) "
  296. "in your kernel sources and rebuild.\n", virt_irq_max);
  297. warned = 1;
  298. }
  299. return NO_IRQ;
  300. }
  301. /*
  302. * In most cases will get a hit on the very first slot checked in the
  303. * virt_irq_to_real_map. Only when there are a large number of
  304. * IRQs will this be expensive.
  305. */
  306. unsigned int real_irq_to_virt_slowpath(unsigned int real_irq)
  307. {
  308. unsigned int virq;
  309. unsigned int first_virq;
  310. virq = real_irq;
  311. if (virq > max_virt_irq)
  312. virq = (virq % nr_virt_irqs) + MIN_VIRT_IRQ;
  313. first_virq = virq;
  314. do {
  315. if (virt_irq_to_real_map[virq] == real_irq)
  316. return virq;
  317. virq++;
  318. if (virq >= max_virt_irq)
  319. virq = 0;
  320. } while (first_virq != virq);
  321. return NO_IRQ;
  322. }
  323. #endif /* CONFIG_PPC64 */
  324. #ifdef CONFIG_IRQSTACKS
  325. struct thread_info *softirq_ctx[NR_CPUS];
  326. struct thread_info *hardirq_ctx[NR_CPUS];
  327. void irq_ctx_init(void)
  328. {
  329. struct thread_info *tp;
  330. int i;
  331. for_each_possible_cpu(i) {
  332. memset((void *)softirq_ctx[i], 0, THREAD_SIZE);
  333. tp = softirq_ctx[i];
  334. tp->cpu = i;
  335. tp->preempt_count = SOFTIRQ_OFFSET;
  336. memset((void *)hardirq_ctx[i], 0, THREAD_SIZE);
  337. tp = hardirq_ctx[i];
  338. tp->cpu = i;
  339. tp->preempt_count = HARDIRQ_OFFSET;
  340. }
  341. }
  342. static inline void do_softirq_onstack(void)
  343. {
  344. struct thread_info *curtp, *irqtp;
  345. curtp = current_thread_info();
  346. irqtp = softirq_ctx[smp_processor_id()];
  347. irqtp->task = curtp->task;
  348. call_do_softirq(irqtp);
  349. irqtp->task = NULL;
  350. }
  351. #else
  352. #define do_softirq_onstack() __do_softirq()
  353. #endif /* CONFIG_IRQSTACKS */
  354. void do_softirq(void)
  355. {
  356. unsigned long flags;
  357. if (in_interrupt())
  358. return;
  359. local_irq_save(flags);
  360. if (local_softirq_pending()) {
  361. account_system_vtime(current);
  362. local_bh_disable();
  363. do_softirq_onstack();
  364. account_system_vtime(current);
  365. __local_bh_enable();
  366. }
  367. local_irq_restore(flags);
  368. }
  369. EXPORT_SYMBOL(do_softirq);
  370. #ifdef CONFIG_PPC64
  371. static int __init setup_noirqdistrib(char *str)
  372. {
  373. distribute_irqs = 0;
  374. return 1;
  375. }
  376. __setup("noirqdistrib", setup_noirqdistrib);
  377. #endif /* CONFIG_PPC64 */