irq.c 11 KB

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