irq.c 10 KB

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