1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <linux/module.h>
16#include <linux/seq_file.h>
17#include <linux/interrupt.h>
18#include <linux/irq.h>
19#include <linux/kernel_stat.h>
20#include <linux/uaccess.h>
21#include <hv/drv_pcie_rc_intf.h>
22#include <arch/spr_def.h>
23#include <asm/traps.h>
24#include <linux/perf_event.h>
25
26
27#define IS_HW_CLEARED 1
28
29
30
31
32
33
34
35
36DEFINE_PER_CPU(unsigned long long, interrupts_enabled_mask) =
37 INITIAL_INTERRUPTS_ENABLED;
38EXPORT_PER_CPU_SYMBOL(interrupts_enabled_mask);
39
40
41DEFINE_PER_CPU(irq_cpustat_t, irq_stat) ____cacheline_internodealigned_in_smp;
42EXPORT_PER_CPU_SYMBOL(irq_stat);
43
44
45
46
47
48static DEFINE_PER_CPU(unsigned long, irq_disable_mask)
49 ____cacheline_internodealigned_in_smp;
50
51
52
53
54
55static DEFINE_PER_CPU(int, irq_depth);
56
57#if CHIP_HAS_IPI()
58
59#define mask_irqs(irq_mask) __insn_mtspr(SPR_IPI_MASK_SET_K, irq_mask)
60#define unmask_irqs(irq_mask) __insn_mtspr(SPR_IPI_MASK_RESET_K, irq_mask)
61#define clear_irqs(irq_mask) __insn_mtspr(SPR_IPI_EVENT_RESET_K, irq_mask)
62#else
63
64#define mask_irqs(irq_mask) hv_disable_intr(irq_mask)
65#define unmask_irqs(irq_mask) hv_enable_intr(irq_mask)
66#define clear_irqs(irq_mask) hv_clear_intr(irq_mask)
67#endif
68
69
70
71
72
73
74void tile_dev_intr(struct pt_regs *regs, int intnum)
75{
76 int depth = __this_cpu_inc_return(irq_depth);
77 unsigned long original_irqs;
78 unsigned long remaining_irqs;
79 struct pt_regs *old_regs;
80
81#if CHIP_HAS_IPI()
82
83
84
85
86
87
88 unsigned long masked = __insn_mfspr(SPR_IPI_MASK_K);
89 original_irqs = __insn_mfspr(SPR_IPI_EVENT_K) & ~masked;
90 __insn_mtspr(SPR_IPI_MASK_SET_K, original_irqs);
91#else
92
93
94
95
96
97 original_irqs = __insn_mfspr(SPR_SYSTEM_SAVE_K_3);
98#endif
99 remaining_irqs = original_irqs;
100
101
102 old_regs = set_irq_regs(regs);
103 irq_enter();
104
105#ifdef CONFIG_DEBUG_STACKOVERFLOW
106
107 {
108 long sp = stack_pointer - (long) current_thread_info();
109 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
110 pr_emerg("%s: stack overflow: %ld\n",
111 __func__, sp - sizeof(struct thread_info));
112 dump_stack();
113 }
114 }
115#endif
116 while (remaining_irqs) {
117 unsigned long irq = __ffs(remaining_irqs);
118 remaining_irqs &= ~(1UL << irq);
119
120
121 if (irq != IRQ_RESCHEDULE)
122 __this_cpu_inc(irq_stat.irq_dev_intr_count);
123
124 generic_handle_irq(irq);
125 }
126
127
128
129
130
131
132 if (depth == 1)
133 unmask_irqs(~__this_cpu_read(irq_disable_mask));
134
135 __this_cpu_dec(irq_depth);
136
137
138
139
140
141 irq_exit();
142 set_irq_regs(old_regs);
143}
144
145
146
147
148
149
150static void tile_irq_chip_enable(struct irq_data *d)
151{
152 get_cpu_var(irq_disable_mask) &= ~(1UL << d->irq);
153 if (__this_cpu_read(irq_depth) == 0)
154 unmask_irqs(1UL << d->irq);
155 put_cpu_var(irq_disable_mask);
156}
157
158
159
160
161
162
163
164static void tile_irq_chip_disable(struct irq_data *d)
165{
166 get_cpu_var(irq_disable_mask) |= (1UL << d->irq);
167 mask_irqs(1UL << d->irq);
168 put_cpu_var(irq_disable_mask);
169}
170
171
172static void tile_irq_chip_mask(struct irq_data *d)
173{
174 mask_irqs(1UL << d->irq);
175}
176
177
178static void tile_irq_chip_unmask(struct irq_data *d)
179{
180 unmask_irqs(1UL << d->irq);
181}
182
183
184
185
186
187static void tile_irq_chip_ack(struct irq_data *d)
188{
189 if ((unsigned long)irq_data_get_irq_chip_data(d) != IS_HW_CLEARED)
190 clear_irqs(1UL << d->irq);
191}
192
193
194
195
196
197static void tile_irq_chip_eoi(struct irq_data *d)
198{
199 if (!(__this_cpu_read(irq_disable_mask) & (1UL << d->irq)))
200 unmask_irqs(1UL << d->irq);
201}
202
203static struct irq_chip tile_irq_chip = {
204 .name = "tile_irq_chip",
205 .irq_enable = tile_irq_chip_enable,
206 .irq_disable = tile_irq_chip_disable,
207 .irq_ack = tile_irq_chip_ack,
208 .irq_eoi = tile_irq_chip_eoi,
209 .irq_mask = tile_irq_chip_mask,
210 .irq_unmask = tile_irq_chip_unmask,
211};
212
213void __init init_IRQ(void)
214{
215 ipi_init();
216}
217
218void setup_irq_regs(void)
219{
220
221 unmask_irqs(~0UL);
222#if CHIP_HAS_IPI()
223 arch_local_irq_unmask(INT_IPI_K);
224#endif
225}
226
227void tile_irq_activate(unsigned int irq, int tile_irq_type)
228{
229
230
231
232
233
234
235
236 irq_flow_handler_t handle = handle_level_irq;
237 if (tile_irq_type == TILE_IRQ_PERCPU)
238 handle = handle_percpu_irq;
239 irq_set_chip_and_handler(irq, &tile_irq_chip, handle);
240
241
242
243
244
245 if (tile_irq_type == TILE_IRQ_HW_CLEAR)
246 irq_set_chip_data(irq, (void *)IS_HW_CLEARED);
247}
248EXPORT_SYMBOL(tile_irq_activate);
249
250
251void ack_bad_irq(unsigned int irq)
252{
253 pr_err("unexpected IRQ trap at vector %02x\n", irq);
254}
255
256
257
258
259int arch_show_interrupts(struct seq_file *p, int prec)
260{
261#ifdef CONFIG_PERF_EVENTS
262 int i;
263
264 seq_printf(p, "%*s: ", prec, "PMI");
265
266 for_each_online_cpu(i)
267 seq_printf(p, "%10llu ", per_cpu(perf_irqs, i));
268 seq_puts(p, " perf_events\n");
269#endif
270 return 0;
271}
272
273#if CHIP_HAS_IPI()
274int arch_setup_hwirq(unsigned int irq, int node)
275{
276 return irq >= NR_IRQS ? -EINVAL : 0;
277}
278
279void arch_teardown_hwirq(unsigned int irq) { }
280#endif
281