1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/irq.h>
24#include <linux/percpu.h>
25#include <linux/types.h>
26
27#include <asm/machdep.h>
28
29#include "beat_interrupt.h"
30#include "beat_wrapper.h"
31
32#define MAX_IRQS NR_IRQS
33static DEFINE_RAW_SPINLOCK(beatic_irq_mask_lock);
34static uint64_t beatic_irq_mask_enable[(MAX_IRQS+255)/64];
35static uint64_t beatic_irq_mask_ack[(MAX_IRQS+255)/64];
36
37static struct irq_host *beatic_host;
38
39
40
41
42
43
44
45static inline void beatic_update_irq_mask(unsigned int irq_plug)
46{
47 int off;
48 unsigned long masks[4];
49
50 off = (irq_plug / 256) * 4;
51 masks[0] = beatic_irq_mask_enable[off + 0]
52 & beatic_irq_mask_ack[off + 0];
53 masks[1] = beatic_irq_mask_enable[off + 1]
54 & beatic_irq_mask_ack[off + 1];
55 masks[2] = beatic_irq_mask_enable[off + 2]
56 & beatic_irq_mask_ack[off + 2];
57 masks[3] = beatic_irq_mask_enable[off + 3]
58 & beatic_irq_mask_ack[off + 3];
59 if (beat_set_interrupt_mask(irq_plug&~255UL,
60 masks[0], masks[1], masks[2], masks[3]) != 0)
61 panic("Failed to set mask IRQ!");
62}
63
64static void beatic_mask_irq(unsigned int irq_plug)
65{
66 unsigned long flags;
67
68 raw_spin_lock_irqsave(&beatic_irq_mask_lock, flags);
69 beatic_irq_mask_enable[irq_plug/64] &= ~(1UL << (63 - (irq_plug%64)));
70 beatic_update_irq_mask(irq_plug);
71 raw_spin_unlock_irqrestore(&beatic_irq_mask_lock, flags);
72}
73
74static void beatic_unmask_irq(unsigned int irq_plug)
75{
76 unsigned long flags;
77
78 raw_spin_lock_irqsave(&beatic_irq_mask_lock, flags);
79 beatic_irq_mask_enable[irq_plug/64] |= 1UL << (63 - (irq_plug%64));
80 beatic_update_irq_mask(irq_plug);
81 raw_spin_unlock_irqrestore(&beatic_irq_mask_lock, flags);
82}
83
84static void beatic_ack_irq(unsigned int irq_plug)
85{
86 unsigned long flags;
87
88 raw_spin_lock_irqsave(&beatic_irq_mask_lock, flags);
89 beatic_irq_mask_ack[irq_plug/64] &= ~(1UL << (63 - (irq_plug%64)));
90 beatic_update_irq_mask(irq_plug);
91 raw_spin_unlock_irqrestore(&beatic_irq_mask_lock, flags);
92}
93
94static void beatic_end_irq(unsigned int irq_plug)
95{
96 s64 err;
97 unsigned long flags;
98
99 err = beat_downcount_of_interrupt(irq_plug);
100 if (err != 0) {
101 if ((err & 0xFFFFFFFF) != 0xFFFFFFF5)
102 panic("Failed to downcount IRQ! Error = %16llx", err);
103
104 printk(KERN_ERR "IRQ over-downcounted, plug %d\n", irq_plug);
105 }
106 raw_spin_lock_irqsave(&beatic_irq_mask_lock, flags);
107 beatic_irq_mask_ack[irq_plug/64] |= 1UL << (63 - (irq_plug%64));
108 beatic_update_irq_mask(irq_plug);
109 raw_spin_unlock_irqrestore(&beatic_irq_mask_lock, flags);
110}
111
112static struct irq_chip beatic_pic = {
113 .name = "CELL-BEAT",
114 .unmask = beatic_unmask_irq,
115 .mask = beatic_mask_irq,
116 .eoi = beatic_end_irq,
117};
118
119
120
121
122
123
124
125static void beatic_pic_host_unmap(struct irq_host *h, unsigned int virq)
126{
127 beat_destruct_irq_plug(virq);
128}
129
130
131
132
133
134
135
136static int beatic_pic_host_map(struct irq_host *h, unsigned int virq,
137 irq_hw_number_t hw)
138{
139 struct irq_desc *desc = irq_to_desc(virq);
140 int64_t err;
141
142 err = beat_construct_and_connect_irq_plug(virq, hw);
143 if (err < 0)
144 return -EIO;
145
146 desc->status |= IRQ_LEVEL;
147 set_irq_chip_and_handler(virq, &beatic_pic, handle_fasteoi_irq);
148 return 0;
149}
150
151
152
153
154
155static void beatic_pic_host_remap(struct irq_host *h, unsigned int virq,
156 irq_hw_number_t hw)
157{
158 beat_construct_and_connect_irq_plug(virq, hw);
159}
160
161
162
163
164
165
166
167
168static int beatic_pic_host_xlate(struct irq_host *h, struct device_node *ct,
169 const u32 *intspec, unsigned int intsize,
170 irq_hw_number_t *out_hwirq,
171 unsigned int *out_flags)
172{
173 const u64 *intspec2 = (const u64 *)intspec;
174
175 *out_hwirq = *intspec2;
176 *out_flags |= IRQ_TYPE_LEVEL_LOW;
177 return 0;
178}
179
180static int beatic_pic_host_match(struct irq_host *h, struct device_node *np)
181{
182
183 return 1;
184}
185
186static struct irq_host_ops beatic_pic_host_ops = {
187 .map = beatic_pic_host_map,
188 .remap = beatic_pic_host_remap,
189 .unmap = beatic_pic_host_unmap,
190 .xlate = beatic_pic_host_xlate,
191 .match = beatic_pic_host_match,
192};
193
194
195
196
197
198static inline unsigned int beatic_get_irq_plug(void)
199{
200 int i;
201 uint64_t pending[4], ub;
202
203 for (i = 0; i < MAX_IRQS; i += 256) {
204 beat_detect_pending_interrupts(i, pending);
205 __asm__ ("cntlzd %0,%1":"=r"(ub):
206 "r"(pending[0] & beatic_irq_mask_enable[i/64+0]
207 & beatic_irq_mask_ack[i/64+0]));
208 if (ub != 64)
209 return i + ub + 0;
210 __asm__ ("cntlzd %0,%1":"=r"(ub):
211 "r"(pending[1] & beatic_irq_mask_enable[i/64+1]
212 & beatic_irq_mask_ack[i/64+1]));
213 if (ub != 64)
214 return i + ub + 64;
215 __asm__ ("cntlzd %0,%1":"=r"(ub):
216 "r"(pending[2] & beatic_irq_mask_enable[i/64+2]
217 & beatic_irq_mask_ack[i/64+2]));
218 if (ub != 64)
219 return i + ub + 128;
220 __asm__ ("cntlzd %0,%1":"=r"(ub):
221 "r"(pending[3] & beatic_irq_mask_enable[i/64+3]
222 & beatic_irq_mask_ack[i/64+3]));
223 if (ub != 64)
224 return i + ub + 192;
225 }
226
227 return NO_IRQ;
228}
229unsigned int beatic_get_irq(void)
230{
231 unsigned int ret;
232
233 ret = beatic_get_irq_plug();
234 if (ret != NO_IRQ)
235 beatic_ack_irq(ret);
236 return ret;
237}
238
239
240
241void __init beatic_init_IRQ(void)
242{
243 int i;
244
245 memset(beatic_irq_mask_enable, 0, sizeof(beatic_irq_mask_enable));
246 memset(beatic_irq_mask_ack, 255, sizeof(beatic_irq_mask_ack));
247 for (i = 0; i < MAX_IRQS; i += 256)
248 beat_set_interrupt_mask(i, 0L, 0L, 0L, 0L);
249
250
251 ppc_md.get_irq = beatic_get_irq;
252
253
254 beatic_host = irq_alloc_host(NULL, IRQ_HOST_MAP_NOMAP, 0,
255 &beatic_pic_host_ops,
256 0);
257 BUG_ON(beatic_host == NULL);
258 irq_set_default_host(beatic_host);
259}
260
261#ifdef CONFIG_SMP
262
263
264void beatic_setup_cpu(int cpu)
265{
266}
267
268void beatic_cause_IPI(int cpu, int mesg)
269{
270}
271
272void beatic_request_IPIs(void)
273{
274}
275#endif
276
277void beatic_deinit_IRQ(void)
278{
279 int i;
280
281 for (i = 1; i < NR_IRQS; i++)
282 beat_destruct_irq_plug(i);
283}
284