blob: 9df824ea16672aea9e8f6a93ec6c925f7b982a3a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * Copyright IBM Corp. 2004, 2011
Heiko Carstensd7b250e2011-05-26 09:48:24 +02003 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
4 * Holger Smolinski <Holger.Smolinski@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This file contains interrupt related functions.
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel_stat.h>
11#include <linux/interrupt.h>
12#include <linux/seq_file.h>
Heiko Carstens55dff522007-02-05 21:16:44 +010013#include <linux/proc_fs.h>
14#include <linux/profile.h>
Heiko Carstensd7b250e2011-05-26 09:48:24 +020015#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/ftrace.h>
18#include <linux/errno.h>
19#include <linux/slab.h>
20#include <linux/cpu.h>
21#include <asm/irq_regs.h>
22#include <asm/cputime.h>
23#include <asm/lowcore.h>
24#include <asm/irq.h>
25#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Heiko Carstens420f42e2013-01-02 15:18:18 +010027DEFINE_PER_CPU_SHARED_ALIGNED(struct irq_stat, irq_stat);
28EXPORT_PER_CPU_SYMBOL_GPL(irq_stat);
29
Heiko Carstens052ff462011-01-05 12:47:28 +010030struct irq_class {
31 char *name;
32 char *desc;
33};
34
Heiko Carstens420f42e2013-01-02 15:18:18 +010035/*
36 * The list of "main" irq classes on s390. This is the list of interrrupts
37 * that appear both in /proc/stat ("intr" line) and /proc/interrupts.
38 * Historically only external and I/O interrupts have been part of /proc/stat.
39 * We can't add the split external and I/O sub classes since the first field
40 * in the "intr" line in /proc/stat is supposed to be the sum of all other
41 * fields.
42 * Since the external and I/O interrupt fields are already sums we would end
43 * up with having a sum which accounts each interrupt twice.
44 */
45static const struct irq_class irqclass_main_desc[NR_IRQS] = {
Heiko Carstens708c39d2012-09-17 06:05:16 +020046 [EXTERNAL_INTERRUPT] = {.name = "EXT"},
Heiko Carstens420f42e2013-01-02 15:18:18 +010047 [IO_INTERRUPT] = {.name = "I/O"}
48};
49
50/*
51 * The list of split external and I/O interrupts that appear only in
52 * /proc/interrupts.
53 * In addition this list contains non external / I/O events like NMIs.
54 */
55static const struct irq_class irqclass_sub_desc[NR_ARCH_IRQS] = {
56 [IRQEXT_CLK] = {.name = "CLK", .desc = "[EXT] Clock Comparator"},
57 [IRQEXT_EXC] = {.name = "EXC", .desc = "[EXT] External Call"},
58 [IRQEXT_EMS] = {.name = "EMS", .desc = "[EXT] Emergency Signal"},
59 [IRQEXT_TMR] = {.name = "TMR", .desc = "[EXT] CPU Timer"},
60 [IRQEXT_TLA] = {.name = "TAL", .desc = "[EXT] Timing Alert"},
61 [IRQEXT_PFL] = {.name = "PFL", .desc = "[EXT] Pseudo Page Fault"},
62 [IRQEXT_DSD] = {.name = "DSD", .desc = "[EXT] DASD Diag"},
63 [IRQEXT_VRT] = {.name = "VRT", .desc = "[EXT] Virtio"},
64 [IRQEXT_SCP] = {.name = "SCP", .desc = "[EXT] Service Call"},
65 [IRQEXT_IUC] = {.name = "IUC", .desc = "[EXT] IUCV"},
66 [IRQEXT_CMS] = {.name = "CMS", .desc = "[EXT] CPU-Measurement: Sampling"},
67 [IRQEXT_CMC] = {.name = "CMC", .desc = "[EXT] CPU-Measurement: Counter"},
68 [IRQEXT_CMR] = {.name = "CMR", .desc = "[EXT] CPU-Measurement: RI"},
69 [IRQIO_CIO] = {.name = "CIO", .desc = "[I/O] Common I/O Layer Interrupt"},
70 [IRQIO_QAI] = {.name = "QAI", .desc = "[I/O] QDIO Adapter Interrupt"},
71 [IRQIO_DAS] = {.name = "DAS", .desc = "[I/O] DASD"},
72 [IRQIO_C15] = {.name = "C15", .desc = "[I/O] 3215"},
73 [IRQIO_C70] = {.name = "C70", .desc = "[I/O] 3270"},
74 [IRQIO_TAP] = {.name = "TAP", .desc = "[I/O] Tape"},
75 [IRQIO_VMR] = {.name = "VMR", .desc = "[I/O] Unit Record Devices"},
76 [IRQIO_LCS] = {.name = "LCS", .desc = "[I/O] LCS"},
77 [IRQIO_CLW] = {.name = "CLW", .desc = "[I/O] CLAW"},
78 [IRQIO_CTC] = {.name = "CTC", .desc = "[I/O] CTC"},
79 [IRQIO_APB] = {.name = "APB", .desc = "[I/O] AP Bus"},
80 [IRQIO_ADM] = {.name = "ADM", .desc = "[I/O] EADM Subchannel"},
81 [IRQIO_CSC] = {.name = "CSC", .desc = "[I/O] CHSC Subchannel"},
82 [IRQIO_PCI] = {.name = "PCI", .desc = "[I/O] PCI Interrupt" },
83 [IRQIO_MSI] = {.name = "MSI", .desc = "[I/O] MSI Interrupt" },
Heiko Carstens708c39d2012-09-17 06:05:16 +020084 [NMI_NMI] = {.name = "NMI", .desc = "[NMI] Machine Check"},
Heiko Carstens93f3b2e2013-01-02 16:54:12 +010085 [CPU_RST] = {.name = "RST", .desc = "[CPU] CPU Restart"},
Heiko Carstens052ff462011-01-05 12:47:28 +010086};
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088/*
89 * show_interrupts is needed by /proc/interrupts.
90 */
91int show_interrupts(struct seq_file *p, void *v)
92{
Heiko Carstens420f42e2013-01-02 15:18:18 +010093 int irq = *(loff_t *) v;
94 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Heiko Carstens8dd79cb2008-05-15 16:52:39 +020096 get_online_cpus();
Heiko Carstens420f42e2013-01-02 15:18:18 +010097 if (irq == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 seq_puts(p, " ");
Heiko Carstens420f42e2013-01-02 15:18:18 +010099 for_each_online_cpu(cpu)
100 seq_printf(p, "CPU%d ", cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 seq_putc(p, '\n');
102 }
Heiko Carstens420f42e2013-01-02 15:18:18 +0100103 if (irq < NR_IRQS) {
104 seq_printf(p, "%s: ", irqclass_main_desc[irq].name);
105 for_each_online_cpu(cpu)
106 seq_printf(p, "%10u ", kstat_cpu(cpu).irqs[irq]);
107 seq_putc(p, '\n');
108 goto skip_arch_irqs;
109 }
110 for (irq = 0; irq < NR_ARCH_IRQS; irq++) {
111 seq_printf(p, "%s: ", irqclass_sub_desc[irq].name);
112 for_each_online_cpu(cpu)
113 seq_printf(p, "%10u ", per_cpu(irq_stat, cpu).irqs[irq]);
114 if (irqclass_sub_desc[irq].desc)
115 seq_printf(p, " %s", irqclass_sub_desc[irq].desc);
116 seq_putc(p, '\n');
117 }
118skip_arch_irqs:
Heiko Carstens8dd79cb2008-05-15 16:52:39 +0200119 put_online_cpus();
Heiko Carstens420f42e2013-01-02 15:18:18 +0100120 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
123/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 * Switch to the asynchronous interrupt stack for softirq execution.
125 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126asmlinkage void do_softirq(void)
127{
128 unsigned long flags, old, new;
129
130 if (in_interrupt())
131 return;
132
133 local_irq_save(flags);
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 if (local_softirq_pending()) {
136 /* Get current stack pointer. */
137 asm volatile("la %0,0(15)" : "=a" (old));
138 /* Check against async. stack address range. */
139 new = S390_lowcore.async_stack;
140 if (((new - old) >> (PAGE_SHIFT + THREAD_ORDER)) != 0) {
141 /* Need to switch to the async. stack. */
142 new -= STACK_FRAME_OVERHEAD;
143 ((struct stack_frame *) new)->back_chain = old;
144
145 asm volatile(" la 15,0(%0)\n"
146 " basr 14,%2\n"
147 " la 15,0(%1)\n"
148 : : "a" (new), "a" (old),
149 "a" (__do_softirq)
150 : "0", "1", "2", "3", "4", "5", "14",
151 "cc", "memory" );
Heiko Carstens7968ca82012-04-11 14:28:09 +0200152 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 /* We are already on the async stack. */
154 __do_softirq();
Heiko Carstens7968ca82012-04-11 14:28:09 +0200155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 local_irq_restore(flags);
159}
Heiko Carstens55dff522007-02-05 21:16:44 +0100160
Sachin Sant0addff82009-02-11 10:37:29 +0100161#ifdef CONFIG_PROC_FS
Heiko Carstens55dff522007-02-05 21:16:44 +0100162void init_irq_proc(void)
163{
164 struct proc_dir_entry *root_irq_dir;
165
166 root_irq_dir = proc_mkdir("irq", NULL);
167 create_prof_cpu_mask(root_irq_dir);
168}
Sachin Sant0addff82009-02-11 10:37:29 +0100169#endif
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200170
171/*
Jan Glauber89c9b662011-07-24 10:48:27 +0200172 * ext_int_hash[index] is the list head for all external interrupts that hash
173 * to this index.
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200174 */
Jan Glauber89c9b662011-07-24 10:48:27 +0200175static struct list_head ext_int_hash[256];
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200176
177struct ext_int_info {
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200178 ext_int_handler_t handler;
179 u16 code;
Jan Glauber89c9b662011-07-24 10:48:27 +0200180 struct list_head entry;
181 struct rcu_head rcu;
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200182};
183
Jan Glauber89c9b662011-07-24 10:48:27 +0200184/* ext_int_hash_lock protects the handler lists for external interrupts */
185DEFINE_SPINLOCK(ext_int_hash_lock);
186
187static void __init init_external_interrupts(void)
188{
189 int idx;
190
191 for (idx = 0; idx < ARRAY_SIZE(ext_int_hash); idx++)
192 INIT_LIST_HEAD(&ext_int_hash[idx]);
193}
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200194
195static inline int ext_hash(u16 code)
196{
197 return (code + (code >> 9)) & 0xff;
198}
199
200int register_external_interrupt(u16 code, ext_int_handler_t handler)
201{
202 struct ext_int_info *p;
Jan Glauber89c9b662011-07-24 10:48:27 +0200203 unsigned long flags;
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200204 int index;
205
206 p = kmalloc(sizeof(*p), GFP_ATOMIC);
207 if (!p)
208 return -ENOMEM;
209 p->code = code;
210 p->handler = handler;
211 index = ext_hash(code);
Jan Glauber89c9b662011-07-24 10:48:27 +0200212
213 spin_lock_irqsave(&ext_int_hash_lock, flags);
214 list_add_rcu(&p->entry, &ext_int_hash[index]);
215 spin_unlock_irqrestore(&ext_int_hash_lock, flags);
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200216 return 0;
217}
218EXPORT_SYMBOL(register_external_interrupt);
219
220int unregister_external_interrupt(u16 code, ext_int_handler_t handler)
221{
Jan Glauber89c9b662011-07-24 10:48:27 +0200222 struct ext_int_info *p;
223 unsigned long flags;
224 int index = ext_hash(code);
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200225
Jan Glauber89c9b662011-07-24 10:48:27 +0200226 spin_lock_irqsave(&ext_int_hash_lock, flags);
Heiko Carstens7968ca82012-04-11 14:28:09 +0200227 list_for_each_entry_rcu(p, &ext_int_hash[index], entry) {
Jan Glauber89c9b662011-07-24 10:48:27 +0200228 if (p->code == code && p->handler == handler) {
229 list_del_rcu(&p->entry);
Paul E. McKenneybc399d62012-01-06 16:59:51 -0800230 kfree_rcu(p, rcu);
Jan Glauber89c9b662011-07-24 10:48:27 +0200231 }
Heiko Carstens7968ca82012-04-11 14:28:09 +0200232 }
Jan Glauber89c9b662011-07-24 10:48:27 +0200233 spin_unlock_irqrestore(&ext_int_hash_lock, flags);
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200234 return 0;
235}
236EXPORT_SYMBOL(unregister_external_interrupt);
237
Heiko Carstensfde15c32012-03-11 11:59:31 -0400238void __irq_entry do_extint(struct pt_regs *regs, struct ext_code ext_code,
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200239 unsigned int param32, unsigned long param64)
240{
241 struct pt_regs *old_regs;
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200242 struct ext_int_info *p;
243 int index;
244
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200245 old_regs = set_irq_regs(regs);
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200246 irq_enter();
Heiko Carstens7968ca82012-04-11 14:28:09 +0200247 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) {
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200248 /* Serve timer interrupts first. */
249 clock_comparator_work();
Heiko Carstens7968ca82012-04-11 14:28:09 +0200250 }
Heiko Carstensadd9bde2013-01-02 14:01:23 +0100251 kstat_incr_irqs_this_cpu(EXTERNAL_INTERRUPT, NULL);
Heiko Carstensfde15c32012-03-11 11:59:31 -0400252 if (ext_code.code != 0x1004)
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200253 __get_cpu_var(s390_idle).nohz_delay = 1;
Jan Glauber89c9b662011-07-24 10:48:27 +0200254
Heiko Carstensfde15c32012-03-11 11:59:31 -0400255 index = ext_hash(ext_code.code);
Jan Glauber89c9b662011-07-24 10:48:27 +0200256 rcu_read_lock();
257 list_for_each_entry_rcu(p, &ext_int_hash[index], entry)
Heiko Carstensfde15c32012-03-11 11:59:31 -0400258 if (likely(p->code == ext_code.code))
259 p->handler(ext_code, param32, param64);
Jan Glauber89c9b662011-07-24 10:48:27 +0200260 rcu_read_unlock();
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200261 irq_exit();
262 set_irq_regs(old_regs);
263}
264
Jan Glauber89c9b662011-07-24 10:48:27 +0200265void __init init_IRQ(void)
266{
267 init_external_interrupts();
268}
269
Heiko Carstensd7b250e2011-05-26 09:48:24 +0200270static DEFINE_SPINLOCK(sc_irq_lock);
271static int sc_irq_refcount;
272
273void service_subclass_irq_register(void)
274{
275 spin_lock(&sc_irq_lock);
276 if (!sc_irq_refcount)
277 ctl_set_bit(0, 9);
278 sc_irq_refcount++;
279 spin_unlock(&sc_irq_lock);
280}
281EXPORT_SYMBOL(service_subclass_irq_register);
282
283void service_subclass_irq_unregister(void)
284{
285 spin_lock(&sc_irq_lock);
286 sc_irq_refcount--;
287 if (!sc_irq_refcount)
288 ctl_clear_bit(0, 9);
289 spin_unlock(&sc_irq_lock);
290}
291EXPORT_SYMBOL(service_subclass_irq_unregister);
Jan Glauberb03d5412012-03-23 11:13:05 +0100292
293static DEFINE_SPINLOCK(ma_subclass_lock);
294static int ma_subclass_refcount;
295
296void measurement_alert_subclass_register(void)
297{
298 spin_lock(&ma_subclass_lock);
299 if (!ma_subclass_refcount)
300 ctl_set_bit(0, 5);
301 ma_subclass_refcount++;
302 spin_unlock(&ma_subclass_lock);
303}
304EXPORT_SYMBOL(measurement_alert_subclass_register);
305
306void measurement_alert_subclass_unregister(void)
307{
308 spin_lock(&ma_subclass_lock);
309 ma_subclass_refcount--;
310 if (!ma_subclass_refcount)
311 ctl_clear_bit(0, 5);
312 spin_unlock(&ma_subclass_lock);
313}
314EXPORT_SYMBOL(measurement_alert_subclass_unregister);