irq.c 9.4 KB

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