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