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