irq.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. DEFINE_PER_CPU_SHARED_ALIGNED(struct irq_stat, irq_stat);
  26. EXPORT_PER_CPU_SYMBOL_GPL(irq_stat);
  27. struct irq_class {
  28. char *name;
  29. char *desc;
  30. };
  31. /*
  32. * The list of "main" irq classes on s390. This is the list of interrrupts
  33. * that appear both in /proc/stat ("intr" line) and /proc/interrupts.
  34. * Historically only external and I/O interrupts have been part of /proc/stat.
  35. * We can't add the split external and I/O sub classes since the first field
  36. * in the "intr" line in /proc/stat is supposed to be the sum of all other
  37. * fields.
  38. * Since the external and I/O interrupt fields are already sums we would end
  39. * up with having a sum which accounts each interrupt twice.
  40. */
  41. static const struct irq_class irqclass_main_desc[NR_IRQS] = {
  42. [EXTERNAL_INTERRUPT] = {.name = "EXT"},
  43. [IO_INTERRUPT] = {.name = "I/O"}
  44. };
  45. /*
  46. * The list of split external and I/O interrupts that appear only in
  47. * /proc/interrupts.
  48. * In addition this list contains non external / I/O events like NMIs.
  49. */
  50. static const struct irq_class irqclass_sub_desc[NR_ARCH_IRQS] = {
  51. [IRQEXT_CLK] = {.name = "CLK", .desc = "[EXT] Clock Comparator"},
  52. [IRQEXT_EXC] = {.name = "EXC", .desc = "[EXT] External Call"},
  53. [IRQEXT_EMS] = {.name = "EMS", .desc = "[EXT] Emergency Signal"},
  54. [IRQEXT_TMR] = {.name = "TMR", .desc = "[EXT] CPU Timer"},
  55. [IRQEXT_TLA] = {.name = "TAL", .desc = "[EXT] Timing Alert"},
  56. [IRQEXT_PFL] = {.name = "PFL", .desc = "[EXT] Pseudo Page Fault"},
  57. [IRQEXT_DSD] = {.name = "DSD", .desc = "[EXT] DASD Diag"},
  58. [IRQEXT_VRT] = {.name = "VRT", .desc = "[EXT] Virtio"},
  59. [IRQEXT_SCP] = {.name = "SCP", .desc = "[EXT] Service Call"},
  60. [IRQEXT_IUC] = {.name = "IUC", .desc = "[EXT] IUCV"},
  61. [IRQEXT_CMS] = {.name = "CMS", .desc = "[EXT] CPU-Measurement: Sampling"},
  62. [IRQEXT_CMC] = {.name = "CMC", .desc = "[EXT] CPU-Measurement: Counter"},
  63. [IRQEXT_CMR] = {.name = "CMR", .desc = "[EXT] CPU-Measurement: RI"},
  64. [IRQIO_CIO] = {.name = "CIO", .desc = "[I/O] Common I/O Layer Interrupt"},
  65. [IRQIO_QAI] = {.name = "QAI", .desc = "[I/O] QDIO Adapter Interrupt"},
  66. [IRQIO_DAS] = {.name = "DAS", .desc = "[I/O] DASD"},
  67. [IRQIO_C15] = {.name = "C15", .desc = "[I/O] 3215"},
  68. [IRQIO_C70] = {.name = "C70", .desc = "[I/O] 3270"},
  69. [IRQIO_TAP] = {.name = "TAP", .desc = "[I/O] Tape"},
  70. [IRQIO_VMR] = {.name = "VMR", .desc = "[I/O] Unit Record Devices"},
  71. [IRQIO_LCS] = {.name = "LCS", .desc = "[I/O] LCS"},
  72. [IRQIO_CLW] = {.name = "CLW", .desc = "[I/O] CLAW"},
  73. [IRQIO_CTC] = {.name = "CTC", .desc = "[I/O] CTC"},
  74. [IRQIO_APB] = {.name = "APB", .desc = "[I/O] AP Bus"},
  75. [IRQIO_ADM] = {.name = "ADM", .desc = "[I/O] EADM Subchannel"},
  76. [IRQIO_CSC] = {.name = "CSC", .desc = "[I/O] CHSC Subchannel"},
  77. [IRQIO_PCI] = {.name = "PCI", .desc = "[I/O] PCI Interrupt" },
  78. [IRQIO_MSI] = {.name = "MSI", .desc = "[I/O] MSI Interrupt" },
  79. [IRQIO_VIR] = {.name = "VIR", .desc = "[I/O] Virtual I/O Devices"},
  80. [NMI_NMI] = {.name = "NMI", .desc = "[NMI] Machine Check"},
  81. [CPU_RST] = {.name = "RST", .desc = "[CPU] CPU Restart"},
  82. };
  83. /*
  84. * show_interrupts is needed by /proc/interrupts.
  85. */
  86. int show_interrupts(struct seq_file *p, void *v)
  87. {
  88. int irq = *(loff_t *) v;
  89. int cpu;
  90. get_online_cpus();
  91. if (irq == 0) {
  92. seq_puts(p, " ");
  93. for_each_online_cpu(cpu)
  94. seq_printf(p, "CPU%d ", cpu);
  95. seq_putc(p, '\n');
  96. }
  97. if (irq < NR_IRQS) {
  98. seq_printf(p, "%s: ", irqclass_main_desc[irq].name);
  99. for_each_online_cpu(cpu)
  100. seq_printf(p, "%10u ", kstat_cpu(cpu).irqs[irq]);
  101. seq_putc(p, '\n');
  102. goto skip_arch_irqs;
  103. }
  104. for (irq = 0; irq < NR_ARCH_IRQS; irq++) {
  105. seq_printf(p, "%s: ", irqclass_sub_desc[irq].name);
  106. for_each_online_cpu(cpu)
  107. seq_printf(p, "%10u ", per_cpu(irq_stat, cpu).irqs[irq]);
  108. if (irqclass_sub_desc[irq].desc)
  109. seq_printf(p, " %s", irqclass_sub_desc[irq].desc);
  110. seq_putc(p, '\n');
  111. }
  112. skip_arch_irqs:
  113. put_online_cpus();
  114. return 0;
  115. }
  116. /*
  117. * Switch to the asynchronous interrupt stack for softirq execution.
  118. */
  119. asmlinkage void do_softirq(void)
  120. {
  121. unsigned long flags, old, new;
  122. if (in_interrupt())
  123. return;
  124. local_irq_save(flags);
  125. if (local_softirq_pending()) {
  126. /* Get current stack pointer. */
  127. asm volatile("la %0,0(15)" : "=a" (old));
  128. /* Check against async. stack address range. */
  129. new = S390_lowcore.async_stack;
  130. if (((new - old) >> (PAGE_SHIFT + THREAD_ORDER)) != 0) {
  131. /* Need to switch to the async. stack. */
  132. new -= STACK_FRAME_OVERHEAD;
  133. ((struct stack_frame *) new)->back_chain = old;
  134. asm volatile(" la 15,0(%0)\n"
  135. " basr 14,%2\n"
  136. " la 15,0(%1)\n"
  137. : : "a" (new), "a" (old),
  138. "a" (__do_softirq)
  139. : "0", "1", "2", "3", "4", "5", "14",
  140. "cc", "memory" );
  141. } else {
  142. /* We are already on the async stack. */
  143. __do_softirq();
  144. }
  145. }
  146. local_irq_restore(flags);
  147. }
  148. #ifdef CONFIG_PROC_FS
  149. void init_irq_proc(void)
  150. {
  151. struct proc_dir_entry *root_irq_dir;
  152. root_irq_dir = proc_mkdir("irq", NULL);
  153. create_prof_cpu_mask(root_irq_dir);
  154. }
  155. #endif
  156. /*
  157. * ext_int_hash[index] is the list head for all external interrupts that hash
  158. * to this index.
  159. */
  160. static struct list_head ext_int_hash[256];
  161. struct ext_int_info {
  162. ext_int_handler_t handler;
  163. u16 code;
  164. struct list_head entry;
  165. struct rcu_head rcu;
  166. };
  167. /* ext_int_hash_lock protects the handler lists for external interrupts */
  168. DEFINE_SPINLOCK(ext_int_hash_lock);
  169. static void __init init_external_interrupts(void)
  170. {
  171. int idx;
  172. for (idx = 0; idx < ARRAY_SIZE(ext_int_hash); idx++)
  173. INIT_LIST_HEAD(&ext_int_hash[idx]);
  174. }
  175. static inline int ext_hash(u16 code)
  176. {
  177. return (code + (code >> 9)) & 0xff;
  178. }
  179. int register_external_interrupt(u16 code, ext_int_handler_t handler)
  180. {
  181. struct ext_int_info *p;
  182. unsigned long flags;
  183. int index;
  184. p = kmalloc(sizeof(*p), GFP_ATOMIC);
  185. if (!p)
  186. return -ENOMEM;
  187. p->code = code;
  188. p->handler = handler;
  189. index = ext_hash(code);
  190. spin_lock_irqsave(&ext_int_hash_lock, flags);
  191. list_add_rcu(&p->entry, &ext_int_hash[index]);
  192. spin_unlock_irqrestore(&ext_int_hash_lock, flags);
  193. return 0;
  194. }
  195. EXPORT_SYMBOL(register_external_interrupt);
  196. int unregister_external_interrupt(u16 code, ext_int_handler_t handler)
  197. {
  198. struct ext_int_info *p;
  199. unsigned long flags;
  200. int index = ext_hash(code);
  201. spin_lock_irqsave(&ext_int_hash_lock, flags);
  202. list_for_each_entry_rcu(p, &ext_int_hash[index], entry) {
  203. if (p->code == code && p->handler == handler) {
  204. list_del_rcu(&p->entry);
  205. kfree_rcu(p, rcu);
  206. }
  207. }
  208. spin_unlock_irqrestore(&ext_int_hash_lock, flags);
  209. return 0;
  210. }
  211. EXPORT_SYMBOL(unregister_external_interrupt);
  212. void __irq_entry do_extint(struct pt_regs *regs, struct ext_code ext_code,
  213. unsigned int param32, unsigned long param64)
  214. {
  215. struct pt_regs *old_regs;
  216. struct ext_int_info *p;
  217. int index;
  218. old_regs = set_irq_regs(regs);
  219. irq_enter();
  220. if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) {
  221. /* Serve timer interrupts first. */
  222. clock_comparator_work();
  223. }
  224. kstat_incr_irqs_this_cpu(EXTERNAL_INTERRUPT, NULL);
  225. if (ext_code.code != 0x1004)
  226. __get_cpu_var(s390_idle).nohz_delay = 1;
  227. index = ext_hash(ext_code.code);
  228. rcu_read_lock();
  229. list_for_each_entry_rcu(p, &ext_int_hash[index], entry)
  230. if (likely(p->code == ext_code.code))
  231. p->handler(ext_code, param32, param64);
  232. rcu_read_unlock();
  233. irq_exit();
  234. set_irq_regs(old_regs);
  235. }
  236. void __init init_IRQ(void)
  237. {
  238. init_external_interrupts();
  239. }
  240. static DEFINE_SPINLOCK(sc_irq_lock);
  241. static int sc_irq_refcount;
  242. void service_subclass_irq_register(void)
  243. {
  244. spin_lock(&sc_irq_lock);
  245. if (!sc_irq_refcount)
  246. ctl_set_bit(0, 9);
  247. sc_irq_refcount++;
  248. spin_unlock(&sc_irq_lock);
  249. }
  250. EXPORT_SYMBOL(service_subclass_irq_register);
  251. void service_subclass_irq_unregister(void)
  252. {
  253. spin_lock(&sc_irq_lock);
  254. sc_irq_refcount--;
  255. if (!sc_irq_refcount)
  256. ctl_clear_bit(0, 9);
  257. spin_unlock(&sc_irq_lock);
  258. }
  259. EXPORT_SYMBOL(service_subclass_irq_unregister);
  260. static DEFINE_SPINLOCK(ma_subclass_lock);
  261. static int ma_subclass_refcount;
  262. void measurement_alert_subclass_register(void)
  263. {
  264. spin_lock(&ma_subclass_lock);
  265. if (!ma_subclass_refcount)
  266. ctl_set_bit(0, 5);
  267. ma_subclass_refcount++;
  268. spin_unlock(&ma_subclass_lock);
  269. }
  270. EXPORT_SYMBOL(measurement_alert_subclass_register);
  271. void measurement_alert_subclass_unregister(void)
  272. {
  273. spin_lock(&ma_subclass_lock);
  274. ma_subclass_refcount--;
  275. if (!ma_subclass_refcount)
  276. ctl_clear_bit(0, 5);
  277. spin_unlock(&ma_subclass_lock);
  278. }
  279. EXPORT_SYMBOL(measurement_alert_subclass_unregister);