irq.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Copyright IBM Corp. 2004,2011
  3. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
  4. * Holger Smolinski <Holger.Smolinski@de.ibm.com>,
  5. * Thomas Spatzier <tspat@de.ibm.com>,
  6. *
  7. * This file contains interrupt related functions.
  8. */
  9. #include <linux/kernel_stat.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/profile.h>
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/ftrace.h>
  17. #include <linux/errno.h>
  18. #include <linux/slab.h>
  19. #include <linux/cpu.h>
  20. #include <asm/irq_regs.h>
  21. #include <asm/cputime.h>
  22. #include <asm/lowcore.h>
  23. #include <asm/irq.h>
  24. #include "entry.h"
  25. struct irq_class {
  26. char *name;
  27. char *desc;
  28. };
  29. static const struct irq_class intrclass_names[] = {
  30. {.name = "EXT" },
  31. {.name = "I/O" },
  32. {.name = "CLK", .desc = "[EXT] Clock Comparator" },
  33. {.name = "IPI", .desc = "[EXT] Signal Processor" },
  34. {.name = "TMR", .desc = "[EXT] CPU Timer" },
  35. {.name = "TAL", .desc = "[EXT] Timing Alert" },
  36. {.name = "PFL", .desc = "[EXT] Pseudo Page Fault" },
  37. {.name = "DSD", .desc = "[EXT] DASD Diag" },
  38. {.name = "VRT", .desc = "[EXT] Virtio" },
  39. {.name = "SCP", .desc = "[EXT] Service Call" },
  40. {.name = "IUC", .desc = "[EXT] IUCV" },
  41. {.name = "CPM", .desc = "[EXT] CPU Measurement" },
  42. {.name = "QAI", .desc = "[I/O] QDIO Adapter Interrupt" },
  43. {.name = "QDI", .desc = "[I/O] QDIO Interrupt" },
  44. {.name = "DAS", .desc = "[I/O] DASD" },
  45. {.name = "C15", .desc = "[I/O] 3215" },
  46. {.name = "C70", .desc = "[I/O] 3270" },
  47. {.name = "TAP", .desc = "[I/O] Tape" },
  48. {.name = "VMR", .desc = "[I/O] Unit Record Devices" },
  49. {.name = "LCS", .desc = "[I/O] LCS" },
  50. {.name = "CLW", .desc = "[I/O] CLAW" },
  51. {.name = "CTC", .desc = "[I/O] CTC" },
  52. {.name = "APB", .desc = "[I/O] AP Bus" },
  53. {.name = "NMI", .desc = "[NMI] Machine Check" },
  54. };
  55. /*
  56. * show_interrupts is needed by /proc/interrupts.
  57. */
  58. int show_interrupts(struct seq_file *p, void *v)
  59. {
  60. int i = *(loff_t *) v, j;
  61. get_online_cpus();
  62. if (i == 0) {
  63. seq_puts(p, " ");
  64. for_each_online_cpu(j)
  65. seq_printf(p, "CPU%d ",j);
  66. seq_putc(p, '\n');
  67. }
  68. if (i < NR_IRQS) {
  69. seq_printf(p, "%s: ", intrclass_names[i].name);
  70. #ifndef CONFIG_SMP
  71. seq_printf(p, "%10u ", kstat_irqs(i));
  72. #else
  73. for_each_online_cpu(j)
  74. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  75. #endif
  76. if (intrclass_names[i].desc)
  77. seq_printf(p, " %s", intrclass_names[i].desc);
  78. seq_putc(p, '\n');
  79. }
  80. put_online_cpus();
  81. return 0;
  82. }
  83. /*
  84. * For compatibilty only. S/390 specific setup of interrupts et al. is done
  85. * much later in init_channel_subsystem().
  86. */
  87. void __init init_IRQ(void)
  88. {
  89. /* nothing... */
  90. }
  91. /*
  92. * Switch to the asynchronous interrupt stack for softirq execution.
  93. */
  94. asmlinkage void do_softirq(void)
  95. {
  96. unsigned long flags, old, new;
  97. if (in_interrupt())
  98. return;
  99. local_irq_save(flags);
  100. if (local_softirq_pending()) {
  101. /* Get current stack pointer. */
  102. asm volatile("la %0,0(15)" : "=a" (old));
  103. /* Check against async. stack address range. */
  104. new = S390_lowcore.async_stack;
  105. if (((new - old) >> (PAGE_SHIFT + THREAD_ORDER)) != 0) {
  106. /* Need to switch to the async. stack. */
  107. new -= STACK_FRAME_OVERHEAD;
  108. ((struct stack_frame *) new)->back_chain = old;
  109. asm volatile(" la 15,0(%0)\n"
  110. " basr 14,%2\n"
  111. " la 15,0(%1)\n"
  112. : : "a" (new), "a" (old),
  113. "a" (__do_softirq)
  114. : "0", "1", "2", "3", "4", "5", "14",
  115. "cc", "memory" );
  116. } else
  117. /* We are already on the async stack. */
  118. __do_softirq();
  119. }
  120. local_irq_restore(flags);
  121. }
  122. #ifdef CONFIG_PROC_FS
  123. void init_irq_proc(void)
  124. {
  125. struct proc_dir_entry *root_irq_dir;
  126. root_irq_dir = proc_mkdir("irq", NULL);
  127. create_prof_cpu_mask(root_irq_dir);
  128. }
  129. #endif
  130. /*
  131. * ext_int_hash[index] is the start of the list for all external interrupts
  132. * that hash to this index. With the current set of external interrupts
  133. * (0x1202 external call, 0x1004 cpu timer, 0x2401 hwc console, 0x4000
  134. * iucv and 0x2603 pfault) this is always the first element.
  135. */
  136. struct ext_int_info {
  137. struct ext_int_info *next;
  138. ext_int_handler_t handler;
  139. u16 code;
  140. };
  141. static struct ext_int_info *ext_int_hash[256];
  142. static inline int ext_hash(u16 code)
  143. {
  144. return (code + (code >> 9)) & 0xff;
  145. }
  146. int register_external_interrupt(u16 code, ext_int_handler_t handler)
  147. {
  148. struct ext_int_info *p;
  149. int index;
  150. p = kmalloc(sizeof(*p), GFP_ATOMIC);
  151. if (!p)
  152. return -ENOMEM;
  153. p->code = code;
  154. p->handler = handler;
  155. index = ext_hash(code);
  156. p->next = ext_int_hash[index];
  157. ext_int_hash[index] = p;
  158. return 0;
  159. }
  160. EXPORT_SYMBOL(register_external_interrupt);
  161. int unregister_external_interrupt(u16 code, ext_int_handler_t handler)
  162. {
  163. struct ext_int_info *p, *q;
  164. int index;
  165. index = ext_hash(code);
  166. q = NULL;
  167. p = ext_int_hash[index];
  168. while (p) {
  169. if (p->code == code && p->handler == handler)
  170. break;
  171. q = p;
  172. p = p->next;
  173. }
  174. if (!p)
  175. return -ENOENT;
  176. if (q)
  177. q->next = p->next;
  178. else
  179. ext_int_hash[index] = p->next;
  180. kfree(p);
  181. return 0;
  182. }
  183. EXPORT_SYMBOL(unregister_external_interrupt);
  184. void __irq_entry do_extint(struct pt_regs *regs, unsigned int ext_int_code,
  185. unsigned int param32, unsigned long param64)
  186. {
  187. struct pt_regs *old_regs;
  188. unsigned short code;
  189. struct ext_int_info *p;
  190. int index;
  191. code = (unsigned short) ext_int_code;
  192. old_regs = set_irq_regs(regs);
  193. s390_idle_check(regs, S390_lowcore.int_clock,
  194. S390_lowcore.async_enter_timer);
  195. irq_enter();
  196. if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
  197. /* Serve timer interrupts first. */
  198. clock_comparator_work();
  199. kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
  200. if (code != 0x1004)
  201. __get_cpu_var(s390_idle).nohz_delay = 1;
  202. index = ext_hash(code);
  203. for (p = ext_int_hash[index]; p; p = p->next) {
  204. if (likely(p->code == code))
  205. p->handler(ext_int_code, param32, param64);
  206. }
  207. irq_exit();
  208. set_irq_regs(old_regs);
  209. }
  210. static DEFINE_SPINLOCK(sc_irq_lock);
  211. static int sc_irq_refcount;
  212. void service_subclass_irq_register(void)
  213. {
  214. spin_lock(&sc_irq_lock);
  215. if (!sc_irq_refcount)
  216. ctl_set_bit(0, 9);
  217. sc_irq_refcount++;
  218. spin_unlock(&sc_irq_lock);
  219. }
  220. EXPORT_SYMBOL(service_subclass_irq_register);
  221. void service_subclass_irq_unregister(void)
  222. {
  223. spin_lock(&sc_irq_lock);
  224. sc_irq_refcount--;
  225. if (!sc_irq_refcount)
  226. ctl_clear_bit(0, 9);
  227. spin_unlock(&sc_irq_lock);
  228. }
  229. EXPORT_SYMBOL(service_subclass_irq_unregister);