irq.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. [NMI_NMI] = {.name = "NMI", .desc = "[NMI] Machine Check"},
  80. [CPU_RST] = {.name = "RST", .desc = "[CPU] CPU Restart"},
  81. };
  82. /*
  83. * show_interrupts is needed by /proc/interrupts.
  84. */
  85. int show_interrupts(struct seq_file *p, void *v)
  86. {
  87. int irq = *(loff_t *) v;
  88. int cpu;
  89. get_online_cpus();
  90. if (irq == 0) {
  91. seq_puts(p, " ");
  92. for_each_online_cpu(cpu)
  93. seq_printf(p, "CPU%d ", cpu);
  94. seq_putc(p, '\n');
  95. }
  96. if (irq < NR_IRQS) {
  97. seq_printf(p, "%s: ", irqclass_main_desc[irq].name);
  98. for_each_online_cpu(cpu)
  99. seq_printf(p, "%10u ", kstat_cpu(cpu).irqs[irq]);
  100. seq_putc(p, '\n');
  101. goto skip_arch_irqs;
  102. }
  103. for (irq = 0; irq < NR_ARCH_IRQS; irq++) {
  104. seq_printf(p, "%s: ", irqclass_sub_desc[irq].name);
  105. for_each_online_cpu(cpu)
  106. seq_printf(p, "%10u ", per_cpu(irq_stat, cpu).irqs[irq]);
  107. if (irqclass_sub_desc[irq].desc)
  108. seq_printf(p, " %s", irqclass_sub_desc[irq].desc);
  109. seq_putc(p, '\n');
  110. }
  111. skip_arch_irqs:
  112. put_online_cpus();
  113. return 0;
  114. }
  115. /*
  116. * Switch to the asynchronous interrupt stack for softirq execution.
  117. */
  118. asmlinkage void do_softirq(void)
  119. {
  120. unsigned long flags, old, new;
  121. if (in_interrupt())
  122. return;
  123. local_irq_save(flags);
  124. if (local_softirq_pending()) {
  125. /* Get current stack pointer. */
  126. asm volatile("la %0,0(15)" : "=a" (old));
  127. /* Check against async. stack address range. */
  128. new = S390_lowcore.async_stack;
  129. if (((new - old) >> (PAGE_SHIFT + THREAD_ORDER)) != 0) {
  130. /* Need to switch to the async. stack. */
  131. new -= STACK_FRAME_OVERHEAD;
  132. ((struct stack_frame *) new)->back_chain = old;
  133. asm volatile(" la 15,0(%0)\n"
  134. " basr 14,%2\n"
  135. " la 15,0(%1)\n"
  136. : : "a" (new), "a" (old),
  137. "a" (__do_softirq)
  138. : "0", "1", "2", "3", "4", "5", "14",
  139. "cc", "memory" );
  140. } else {
  141. /* We are already on the async stack. */
  142. __do_softirq();
  143. }
  144. }
  145. local_irq_restore(flags);
  146. }
  147. #ifdef CONFIG_PROC_FS
  148. void init_irq_proc(void)
  149. {
  150. struct proc_dir_entry *root_irq_dir;
  151. root_irq_dir = proc_mkdir("irq", NULL);
  152. create_prof_cpu_mask(root_irq_dir);
  153. }
  154. #endif
  155. /*
  156. * ext_int_hash[index] is the list head for all external interrupts that hash
  157. * to this index.
  158. */
  159. static struct list_head ext_int_hash[256];
  160. struct ext_int_info {
  161. ext_int_handler_t handler;
  162. u16 code;
  163. struct list_head entry;
  164. struct rcu_head rcu;
  165. };
  166. /* ext_int_hash_lock protects the handler lists for external interrupts */
  167. DEFINE_SPINLOCK(ext_int_hash_lock);
  168. static void __init init_external_interrupts(void)
  169. {
  170. int idx;
  171. for (idx = 0; idx < ARRAY_SIZE(ext_int_hash); idx++)
  172. INIT_LIST_HEAD(&ext_int_hash[idx]);
  173. }
  174. static inline int ext_hash(u16 code)
  175. {
  176. return (code + (code >> 9)) & 0xff;
  177. }
  178. int register_external_interrupt(u16 code, ext_int_handler_t handler)
  179. {
  180. struct ext_int_info *p;
  181. unsigned long flags;
  182. int index;
  183. p = kmalloc(sizeof(*p), GFP_ATOMIC);
  184. if (!p)
  185. return -ENOMEM;
  186. p->code = code;
  187. p->handler = handler;
  188. index = ext_hash(code);
  189. spin_lock_irqsave(&ext_int_hash_lock, flags);
  190. list_add_rcu(&p->entry, &ext_int_hash[index]);
  191. spin_unlock_irqrestore(&ext_int_hash_lock, flags);
  192. return 0;
  193. }
  194. EXPORT_SYMBOL(register_external_interrupt);
  195. int unregister_external_interrupt(u16 code, ext_int_handler_t handler)
  196. {
  197. struct ext_int_info *p;
  198. unsigned long flags;
  199. int index = ext_hash(code);
  200. spin_lock_irqsave(&ext_int_hash_lock, flags);
  201. list_for_each_entry_rcu(p, &ext_int_hash[index], entry) {
  202. if (p->code == code && p->handler == handler) {
  203. list_del_rcu(&p->entry);
  204. kfree_rcu(p, rcu);
  205. }
  206. }
  207. spin_unlock_irqrestore(&ext_int_hash_lock, flags);
  208. return 0;
  209. }
  210. EXPORT_SYMBOL(unregister_external_interrupt);
  211. void __irq_entry do_extint(struct pt_regs *regs, struct ext_code ext_code,
  212. unsigned int param32, unsigned long param64)
  213. {
  214. struct pt_regs *old_regs;
  215. struct ext_int_info *p;
  216. int index;
  217. old_regs = set_irq_regs(regs);
  218. irq_enter();
  219. if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) {
  220. /* Serve timer interrupts first. */
  221. clock_comparator_work();
  222. }
  223. kstat_incr_irqs_this_cpu(EXTERNAL_INTERRUPT, NULL);
  224. if (ext_code.code != 0x1004)
  225. __get_cpu_var(s390_idle).nohz_delay = 1;
  226. index = ext_hash(ext_code.code);
  227. rcu_read_lock();
  228. list_for_each_entry_rcu(p, &ext_int_hash[index], entry)
  229. if (likely(p->code == ext_code.code))
  230. p->handler(ext_code, param32, param64);
  231. rcu_read_unlock();
  232. irq_exit();
  233. set_irq_regs(old_regs);
  234. }
  235. void __init init_IRQ(void)
  236. {
  237. init_external_interrupts();
  238. }
  239. static DEFINE_SPINLOCK(sc_irq_lock);
  240. static int sc_irq_refcount;
  241. void service_subclass_irq_register(void)
  242. {
  243. spin_lock(&sc_irq_lock);
  244. if (!sc_irq_refcount)
  245. ctl_set_bit(0, 9);
  246. sc_irq_refcount++;
  247. spin_unlock(&sc_irq_lock);
  248. }
  249. EXPORT_SYMBOL(service_subclass_irq_register);
  250. void service_subclass_irq_unregister(void)
  251. {
  252. spin_lock(&sc_irq_lock);
  253. sc_irq_refcount--;
  254. if (!sc_irq_refcount)
  255. ctl_clear_bit(0, 9);
  256. spin_unlock(&sc_irq_lock);
  257. }
  258. EXPORT_SYMBOL(service_subclass_irq_unregister);
  259. static DEFINE_SPINLOCK(ma_subclass_lock);
  260. static int ma_subclass_refcount;
  261. void measurement_alert_subclass_register(void)
  262. {
  263. spin_lock(&ma_subclass_lock);
  264. if (!ma_subclass_refcount)
  265. ctl_set_bit(0, 5);
  266. ma_subclass_refcount++;
  267. spin_unlock(&ma_subclass_lock);
  268. }
  269. EXPORT_SYMBOL(measurement_alert_subclass_register);
  270. void measurement_alert_subclass_unregister(void)
  271. {
  272. spin_lock(&ma_subclass_lock);
  273. ma_subclass_refcount--;
  274. if (!ma_subclass_refcount)
  275. ctl_clear_bit(0, 5);
  276. spin_unlock(&ma_subclass_lock);
  277. }
  278. EXPORT_SYMBOL(measurement_alert_subclass_unregister);