irq.c 8.9 KB

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