Initial commit
[wrt350n-kernel.git] / arch / powerpc / platforms / celleb / interrupt.c
blobc7c68ca70c82a321b3eaba1175ab0cb22a12eb8d
1 /*
2 * Celleb/Beat Interrupt controller
4 * (C) Copyright 2006-2007 TOSHIBA CORPORATION
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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>
27 #include <asm/machdep.h>
29 #include "interrupt.h"
30 #include "beat_wrapper.h"
32 #define MAX_IRQS NR_IRQS
33 static DEFINE_SPINLOCK(beatic_irq_mask_lock);
34 static uint64_t beatic_irq_mask_enable[(MAX_IRQS+255)/64];
35 static uint64_t beatic_irq_mask_ack[(MAX_IRQS+255)/64];
37 static struct irq_host *beatic_host = NULL;
40 * In this implementation, "virq" == "IRQ plug number",
41 * "(irq_hw_number_t)hwirq" == "IRQ outlet number".
44 /* assumption: locked */
45 static inline void beatic_update_irq_mask(unsigned int irq_plug)
47 int off;
48 unsigned long masks[4];
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!");
64 static void beatic_mask_irq(unsigned int irq_plug)
66 unsigned long flags;
68 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 spin_unlock_irqrestore(&beatic_irq_mask_lock, flags);
74 static void beatic_unmask_irq(unsigned int irq_plug)
76 unsigned long flags;
78 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 spin_unlock_irqrestore(&beatic_irq_mask_lock, flags);
84 static void beatic_ack_irq(unsigned int irq_plug)
86 unsigned long flags;
88 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 spin_unlock_irqrestore(&beatic_irq_mask_lock, flags);
94 static void beatic_end_irq(unsigned int irq_plug)
96 s64 err;
97 unsigned long flags;
99 if ((err = beat_downcount_of_interrupt(irq_plug)) != 0) {
100 if ((err & 0xFFFFFFFF) != 0xFFFFFFF5) /* -11: wrong state */
101 panic("Failed to downcount IRQ! Error = %16lx", err);
103 printk(KERN_ERR "IRQ over-downcounted, plug %d\n", irq_plug);
105 spin_lock_irqsave(&beatic_irq_mask_lock, flags);
106 beatic_irq_mask_ack[irq_plug/64] |= 1UL << (63 - (irq_plug%64));
107 beatic_update_irq_mask(irq_plug);
108 spin_unlock_irqrestore(&beatic_irq_mask_lock, flags);
111 static struct irq_chip beatic_pic = {
112 .typename = " CELL-BEAT ",
113 .unmask = beatic_unmask_irq,
114 .mask = beatic_mask_irq,
115 .eoi = beatic_end_irq,
119 * Dispose binding hardware IRQ number (hw) and Virtuql IRQ number (virq),
120 * update flags.
122 * Note that the number (virq) is already assigned at upper layer.
124 static void beatic_pic_host_unmap(struct irq_host *h, unsigned int virq)
126 beat_destruct_irq_plug(virq);
130 * Create or update binding hardware IRQ number (hw) and Virtuql
131 * IRQ number (virq). This is called only once for a given mapping.
133 * Note that the number (virq) is already assigned at upper layer.
135 static int beatic_pic_host_map(struct irq_host *h, unsigned int virq,
136 irq_hw_number_t hw)
138 struct irq_desc *desc = get_irq_desc(virq);
139 int64_t err;
141 if ((err = beat_construct_and_connect_irq_plug(virq, hw)) < 0)
142 return -EIO;
144 desc->status |= IRQ_LEVEL;
145 set_irq_chip_and_handler(virq, &beatic_pic, handle_fasteoi_irq);
146 return 0;
150 * Update binding hardware IRQ number (hw) and Virtuql
151 * IRQ number (virq). This is called only once for a given mapping.
153 static void beatic_pic_host_remap(struct irq_host *h, unsigned int virq,
154 irq_hw_number_t hw)
156 beat_construct_and_connect_irq_plug(virq, hw);
160 * Translate device-tree interrupt spec to irq_hw_number_t style (ulong),
161 * to pass away to irq_create_mapping().
163 * Called from irq_create_of_mapping() only.
164 * Note: We have only 1 entry to translate.
166 static int beatic_pic_host_xlate(struct irq_host *h, struct device_node *ct,
167 u32 *intspec, unsigned int intsize,
168 irq_hw_number_t *out_hwirq,
169 unsigned int *out_flags)
171 u64 *intspec2 = (u64 *)intspec;
173 *out_hwirq = *intspec2;
174 *out_flags |= IRQ_TYPE_LEVEL_LOW;
175 return 0;
178 static int beatic_pic_host_match(struct irq_host *h, struct device_node *np)
180 /* Match all */
181 return 1;
184 static struct irq_host_ops beatic_pic_host_ops = {
185 .map = beatic_pic_host_map,
186 .remap = beatic_pic_host_remap,
187 .unmap = beatic_pic_host_unmap,
188 .xlate = beatic_pic_host_xlate,
189 .match = beatic_pic_host_match,
193 * Get an IRQ number
194 * Note: returns VIRQ
196 static inline unsigned int beatic_get_irq_plug(void)
198 int i;
199 uint64_t pending[4], ub;
201 for (i = 0; i < MAX_IRQS; i += 256) {
202 beat_detect_pending_interrupts(i, pending);
203 __asm__ ("cntlzd %0,%1":"=r"(ub):
204 "r"(pending[0] & beatic_irq_mask_enable[i/64+0]
205 & beatic_irq_mask_ack[i/64+0]));
206 if (ub != 64)
207 return i + ub + 0;
208 __asm__ ("cntlzd %0,%1":"=r"(ub):
209 "r"(pending[1] & beatic_irq_mask_enable[i/64+1]
210 & beatic_irq_mask_ack[i/64+1]));
211 if (ub != 64)
212 return i + ub + 64;
213 __asm__ ("cntlzd %0,%1":"=r"(ub):
214 "r"(pending[2] & beatic_irq_mask_enable[i/64+2]
215 & beatic_irq_mask_ack[i/64+2]));
216 if (ub != 64)
217 return i + ub + 128;
218 __asm__ ("cntlzd %0,%1":"=r"(ub):
219 "r"(pending[3] & beatic_irq_mask_enable[i/64+3]
220 & beatic_irq_mask_ack[i/64+3]));
221 if (ub != 64)
222 return i + ub + 192;
225 return NO_IRQ;
227 unsigned int beatic_get_irq(void)
229 unsigned int ret;
231 ret = beatic_get_irq_plug();
232 if (ret != NO_IRQ)
233 beatic_ack_irq(ret);
234 return ret;
239 void __init beatic_init_IRQ(void)
241 int i;
243 memset(beatic_irq_mask_enable, 0, sizeof(beatic_irq_mask_enable));
244 memset(beatic_irq_mask_ack, 255, sizeof(beatic_irq_mask_ack));
245 for (i = 0; i < MAX_IRQS; i += 256)
246 beat_set_interrupt_mask(i, 0L, 0L, 0L, 0L);
248 /* Set out get_irq function */
249 ppc_md.get_irq = beatic_get_irq;
251 /* Allocate an irq host */
252 beatic_host = irq_alloc_host(NULL, IRQ_HOST_MAP_NOMAP, 0,
253 &beatic_pic_host_ops,
255 BUG_ON(beatic_host == NULL);
256 irq_set_default_host(beatic_host);
259 #ifdef CONFIG_SMP
261 /* Nullified to compile with SMP mode */
262 void beatic_setup_cpu(int cpu)
266 void beatic_cause_IPI(int cpu, int mesg)
270 void beatic_request_IPIs(void)
273 #endif /* CONFIG_SMP */
275 void beatic_deinit_IRQ(void)
277 int i;
279 for (i = 1; i < NR_IRQS; i++)
280 beat_destruct_irq_plug(i);