irq.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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 (j = 0; j < NR_CPUS; j++)
  126. if (cpu_online(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 17 less than NR_IRQS so that when we
  243. * offset them by 16 (to reserve the first 16 for ISA interrupts)
  244. * we don't end up with an interrupt number >= NR_IRQS.
  245. */
  246. #define MIN_VIRT_IRQ 3
  247. #define MAX_VIRT_IRQ (NR_IRQS - NUM_ISA_INTERRUPTS - 1)
  248. #define NR_VIRT_IRQS (MAX_VIRT_IRQ - MIN_VIRT_IRQ + 1)
  249. void
  250. virt_irq_init(void)
  251. {
  252. int i;
  253. for (i = 0; i < NR_IRQS; i++)
  254. virt_irq_to_real_map[i] = UNDEFINED_IRQ;
  255. }
  256. /* Create a mapping for a real_irq if it doesn't already exist.
  257. * Return the virtual irq as a convenience.
  258. */
  259. int virt_irq_create_mapping(unsigned int real_irq)
  260. {
  261. unsigned int virq, first_virq;
  262. static int warned;
  263. if (ppc64_interrupt_controller == IC_OPEN_PIC)
  264. return real_irq; /* no mapping for openpic (for now) */
  265. if (ppc64_interrupt_controller == IC_CELL_PIC)
  266. return real_irq; /* no mapping for iic either */
  267. /* don't map interrupts < MIN_VIRT_IRQ */
  268. if (real_irq < MIN_VIRT_IRQ) {
  269. virt_irq_to_real_map[real_irq] = real_irq;
  270. return real_irq;
  271. }
  272. /* map to a number between MIN_VIRT_IRQ and MAX_VIRT_IRQ */
  273. virq = real_irq;
  274. if (virq > MAX_VIRT_IRQ)
  275. virq = (virq % NR_VIRT_IRQS) + MIN_VIRT_IRQ;
  276. /* search for this number or a free slot */
  277. first_virq = virq;
  278. while (virt_irq_to_real_map[virq] != UNDEFINED_IRQ) {
  279. if (virt_irq_to_real_map[virq] == real_irq)
  280. return virq;
  281. if (++virq > MAX_VIRT_IRQ)
  282. virq = MIN_VIRT_IRQ;
  283. if (virq == first_virq)
  284. goto nospace; /* oops, no free slots */
  285. }
  286. virt_irq_to_real_map[virq] = real_irq;
  287. return virq;
  288. nospace:
  289. if (!warned) {
  290. printk(KERN_CRIT "Interrupt table is full\n");
  291. printk(KERN_CRIT "Increase NR_IRQS (currently %d) "
  292. "in your kernel sources and rebuild.\n", NR_IRQS);
  293. warned = 1;
  294. }
  295. return NO_IRQ;
  296. }
  297. /*
  298. * In most cases will get a hit on the very first slot checked in the
  299. * virt_irq_to_real_map. Only when there are a large number of
  300. * IRQs will this be expensive.
  301. */
  302. unsigned int real_irq_to_virt_slowpath(unsigned int real_irq)
  303. {
  304. unsigned int virq;
  305. unsigned int first_virq;
  306. virq = real_irq;
  307. if (virq > MAX_VIRT_IRQ)
  308. virq = (virq % NR_VIRT_IRQS) + MIN_VIRT_IRQ;
  309. first_virq = virq;
  310. do {
  311. if (virt_irq_to_real_map[virq] == real_irq)
  312. return virq;
  313. virq++;
  314. if (virq >= MAX_VIRT_IRQ)
  315. virq = 0;
  316. } while (first_virq != virq);
  317. return NO_IRQ;
  318. }
  319. #endif /* CONFIG_PPC64 */
  320. #ifdef CONFIG_IRQSTACKS
  321. struct thread_info *softirq_ctx[NR_CPUS];
  322. struct thread_info *hardirq_ctx[NR_CPUS];
  323. void irq_ctx_init(void)
  324. {
  325. struct thread_info *tp;
  326. int i;
  327. for_each_cpu(i) {
  328. memset((void *)softirq_ctx[i], 0, THREAD_SIZE);
  329. tp = softirq_ctx[i];
  330. tp->cpu = i;
  331. tp->preempt_count = SOFTIRQ_OFFSET;
  332. memset((void *)hardirq_ctx[i], 0, THREAD_SIZE);
  333. tp = hardirq_ctx[i];
  334. tp->cpu = i;
  335. tp->preempt_count = HARDIRQ_OFFSET;
  336. }
  337. }
  338. static inline void do_softirq_onstack(void)
  339. {
  340. struct thread_info *curtp, *irqtp;
  341. curtp = current_thread_info();
  342. irqtp = softirq_ctx[smp_processor_id()];
  343. irqtp->task = curtp->task;
  344. call_do_softirq(irqtp);
  345. irqtp->task = NULL;
  346. }
  347. #else
  348. #define do_softirq_onstack() __do_softirq()
  349. #endif /* CONFIG_IRQSTACKS */
  350. void do_softirq(void)
  351. {
  352. unsigned long flags;
  353. if (in_interrupt())
  354. return;
  355. local_irq_save(flags);
  356. if (local_softirq_pending()) {
  357. account_system_vtime(current);
  358. local_bh_disable();
  359. do_softirq_onstack();
  360. account_system_vtime(current);
  361. __local_bh_enable();
  362. }
  363. local_irq_restore(flags);
  364. }
  365. EXPORT_SYMBOL(do_softirq);
  366. #ifdef CONFIG_PPC64
  367. static int __init setup_noirqdistrib(char *str)
  368. {
  369. distribute_irqs = 0;
  370. return 1;
  371. }
  372. __setup("noirqdistrib", setup_noirqdistrib);
  373. #endif /* CONFIG_PPC64 */