irq.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 = "EXC", .desc = "[EXT] External Call" },
  34. {.name = "EMS", .desc = "[EXT] Emergency Signal" },
  35. {.name = "TMR", .desc = "[EXT] CPU Timer" },
  36. {.name = "TAL", .desc = "[EXT] Timing Alert" },
  37. {.name = "PFL", .desc = "[EXT] Pseudo Page Fault" },
  38. {.name = "DSD", .desc = "[EXT] DASD Diag" },
  39. {.name = "VRT", .desc = "[EXT] Virtio" },
  40. {.name = "SCP", .desc = "[EXT] Service Call" },
  41. {.name = "IUC", .desc = "[EXT] IUCV" },
  42. {.name = "CPM", .desc = "[EXT] CPU Measurement" },
  43. {.name = "CIO", .desc = "[I/O] Common I/O Layer Interrupt" },
  44. {.name = "QAI", .desc = "[I/O] QDIO Adapter Interrupt" },
  45. {.name = "DAS", .desc = "[I/O] DASD" },
  46. {.name = "C15", .desc = "[I/O] 3215" },
  47. {.name = "C70", .desc = "[I/O] 3270" },
  48. {.name = "TAP", .desc = "[I/O] Tape" },
  49. {.name = "VMR", .desc = "[I/O] Unit Record Devices" },
  50. {.name = "LCS", .desc = "[I/O] LCS" },
  51. {.name = "CLW", .desc = "[I/O] CLAW" },
  52. {.name = "CTC", .desc = "[I/O] CTC" },
  53. {.name = "APB", .desc = "[I/O] AP Bus" },
  54. {.name = "CSC", .desc = "[I/O] CHSC Subchannel" },
  55. {.name = "NMI", .desc = "[NMI] Machine Check" },
  56. };
  57. /*
  58. * show_interrupts is needed by /proc/interrupts.
  59. */
  60. int show_interrupts(struct seq_file *p, void *v)
  61. {
  62. int i = *(loff_t *) v, j;
  63. get_online_cpus();
  64. if (i == 0) {
  65. seq_puts(p, " ");
  66. for_each_online_cpu(j)
  67. seq_printf(p, "CPU%d ",j);
  68. seq_putc(p, '\n');
  69. }
  70. if (i < NR_IRQS) {
  71. seq_printf(p, "%s: ", intrclass_names[i].name);
  72. #ifndef CONFIG_SMP
  73. seq_printf(p, "%10u ", kstat_irqs(i));
  74. #else
  75. for_each_online_cpu(j)
  76. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  77. #endif
  78. if (intrclass_names[i].desc)
  79. seq_printf(p, " %s", intrclass_names[i].desc);
  80. seq_putc(p, '\n');
  81. }
  82. put_online_cpus();
  83. return 0;
  84. }
  85. /*
  86. * Switch to the asynchronous interrupt stack for softirq execution.
  87. */
  88. asmlinkage void do_softirq(void)
  89. {
  90. unsigned long flags, old, new;
  91. if (in_interrupt())
  92. return;
  93. local_irq_save(flags);
  94. if (local_softirq_pending()) {
  95. /* Get current stack pointer. */
  96. asm volatile("la %0,0(15)" : "=a" (old));
  97. /* Check against async. stack address range. */
  98. new = S390_lowcore.async_stack;
  99. if (((new - old) >> (PAGE_SHIFT + THREAD_ORDER)) != 0) {
  100. /* Need to switch to the async. stack. */
  101. new -= STACK_FRAME_OVERHEAD;
  102. ((struct stack_frame *) new)->back_chain = old;
  103. asm volatile(" la 15,0(%0)\n"
  104. " basr 14,%2\n"
  105. " la 15,0(%1)\n"
  106. : : "a" (new), "a" (old),
  107. "a" (__do_softirq)
  108. : "0", "1", "2", "3", "4", "5", "14",
  109. "cc", "memory" );
  110. } else {
  111. /* We are already on the async stack. */
  112. __do_softirq();
  113. }
  114. }
  115. local_irq_restore(flags);
  116. }
  117. #ifdef CONFIG_PROC_FS
  118. void init_irq_proc(void)
  119. {
  120. struct proc_dir_entry *root_irq_dir;
  121. root_irq_dir = proc_mkdir("irq", NULL);
  122. create_prof_cpu_mask(root_irq_dir);
  123. }
  124. #endif
  125. /*
  126. * ext_int_hash[index] is the list head for all external interrupts that hash
  127. * to this index.
  128. */
  129. static struct list_head ext_int_hash[256];
  130. struct ext_int_info {
  131. ext_int_handler_t handler;
  132. u16 code;
  133. struct list_head entry;
  134. struct rcu_head rcu;
  135. };
  136. /* ext_int_hash_lock protects the handler lists for external interrupts */
  137. DEFINE_SPINLOCK(ext_int_hash_lock);
  138. static void __init init_external_interrupts(void)
  139. {
  140. int idx;
  141. for (idx = 0; idx < ARRAY_SIZE(ext_int_hash); idx++)
  142. INIT_LIST_HEAD(&ext_int_hash[idx]);
  143. }
  144. static inline int ext_hash(u16 code)
  145. {
  146. return (code + (code >> 9)) & 0xff;
  147. }
  148. int register_external_interrupt(u16 code, ext_int_handler_t handler)
  149. {
  150. struct ext_int_info *p;
  151. unsigned long flags;
  152. int index;
  153. p = kmalloc(sizeof(*p), GFP_ATOMIC);
  154. if (!p)
  155. return -ENOMEM;
  156. p->code = code;
  157. p->handler = handler;
  158. index = ext_hash(code);
  159. spin_lock_irqsave(&ext_int_hash_lock, flags);
  160. list_add_rcu(&p->entry, &ext_int_hash[index]);
  161. spin_unlock_irqrestore(&ext_int_hash_lock, flags);
  162. return 0;
  163. }
  164. EXPORT_SYMBOL(register_external_interrupt);
  165. int unregister_external_interrupt(u16 code, ext_int_handler_t handler)
  166. {
  167. struct ext_int_info *p;
  168. unsigned long flags;
  169. int index = ext_hash(code);
  170. spin_lock_irqsave(&ext_int_hash_lock, flags);
  171. list_for_each_entry_rcu(p, &ext_int_hash[index], entry) {
  172. if (p->code == code && p->handler == handler) {
  173. list_del_rcu(&p->entry);
  174. kfree_rcu(p, rcu);
  175. }
  176. }
  177. spin_unlock_irqrestore(&ext_int_hash_lock, flags);
  178. return 0;
  179. }
  180. EXPORT_SYMBOL(unregister_external_interrupt);
  181. void __irq_entry do_extint(struct pt_regs *regs, struct ext_code ext_code,
  182. unsigned int param32, unsigned long param64)
  183. {
  184. struct pt_regs *old_regs;
  185. struct ext_int_info *p;
  186. int index;
  187. old_regs = set_irq_regs(regs);
  188. irq_enter();
  189. if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) {
  190. /* Serve timer interrupts first. */
  191. clock_comparator_work();
  192. }
  193. kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
  194. if (ext_code.code != 0x1004)
  195. __get_cpu_var(s390_idle).nohz_delay = 1;
  196. index = ext_hash(ext_code.code);
  197. rcu_read_lock();
  198. list_for_each_entry_rcu(p, &ext_int_hash[index], entry)
  199. if (likely(p->code == ext_code.code))
  200. p->handler(ext_code, param32, param64);
  201. rcu_read_unlock();
  202. irq_exit();
  203. set_irq_regs(old_regs);
  204. }
  205. void __init init_IRQ(void)
  206. {
  207. init_external_interrupts();
  208. }
  209. static DEFINE_SPINLOCK(sc_irq_lock);
  210. static int sc_irq_refcount;
  211. void service_subclass_irq_register(void)
  212. {
  213. spin_lock(&sc_irq_lock);
  214. if (!sc_irq_refcount)
  215. ctl_set_bit(0, 9);
  216. sc_irq_refcount++;
  217. spin_unlock(&sc_irq_lock);
  218. }
  219. EXPORT_SYMBOL(service_subclass_irq_register);
  220. void service_subclass_irq_unregister(void)
  221. {
  222. spin_lock(&sc_irq_lock);
  223. sc_irq_refcount--;
  224. if (!sc_irq_refcount)
  225. ctl_clear_bit(0, 9);
  226. spin_unlock(&sc_irq_lock);
  227. }
  228. EXPORT_SYMBOL(service_subclass_irq_unregister);
  229. static DEFINE_SPINLOCK(ma_subclass_lock);
  230. static int ma_subclass_refcount;
  231. void measurement_alert_subclass_register(void)
  232. {
  233. spin_lock(&ma_subclass_lock);
  234. if (!ma_subclass_refcount)
  235. ctl_set_bit(0, 5);
  236. ma_subclass_refcount++;
  237. spin_unlock(&ma_subclass_lock);
  238. }
  239. EXPORT_SYMBOL(measurement_alert_subclass_register);
  240. void measurement_alert_subclass_unregister(void)
  241. {
  242. spin_lock(&ma_subclass_lock);
  243. ma_subclass_refcount--;
  244. if (!ma_subclass_refcount)
  245. ctl_clear_bit(0, 5);
  246. spin_unlock(&ma_subclass_lock);
  247. }
  248. EXPORT_SYMBOL(measurement_alert_subclass_unregister);