irq.c 9.3 KB

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