irq.c 11 KB

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