irq.c 11 KB

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