blob: 1c7e3a1b81abd622477997fa6b30f5ef861ba1d3 [file] [log] [blame]
Jayachandran C0c965402011-11-11 17:08:29 +05301/*
2 * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
3 * reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the NetLogic
9 * license below:
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <linux/kernel.h>
36#include <linux/init.h>
37#include <linux/linkage.h>
38#include <linux/interrupt.h>
Jayachandran C0c965402011-11-11 17:08:29 +053039#include <linux/mm.h>
40#include <linux/slab.h>
41#include <linux/irq.h>
42
Jayachandran C628f0652013-07-17 10:27:26 +000043#include <linux/irqdomain.h>
44#include <linux/of_address.h>
45#include <linux/of_irq.h>
46
Jayachandran C0c965402011-11-11 17:08:29 +053047#include <asm/errno.h>
48#include <asm/signal.h>
Jayachandran C0c965402011-11-11 17:08:29 +053049#include <asm/ptrace.h>
50#include <asm/mipsregs.h>
51#include <asm/thread_info.h>
52
53#include <asm/netlogic/mips-extns.h>
54#include <asm/netlogic/interrupt.h>
55#include <asm/netlogic/haldefs.h>
56#include <asm/netlogic/common.h>
57
Jayachandran C65040e22011-11-16 00:21:28 +000058#if defined(CONFIG_CPU_XLP)
59#include <asm/netlogic/xlp-hal/iomap.h>
60#include <asm/netlogic/xlp-hal/xlp.h>
61#include <asm/netlogic/xlp-hal/pic.h>
62#elif defined(CONFIG_CPU_XLR)
Jayachandran C0c965402011-11-11 17:08:29 +053063#include <asm/netlogic/xlr/iomap.h>
64#include <asm/netlogic/xlr/pic.h>
Ganesan Ramalingamed21cfe2012-10-31 12:01:42 +000065#include <asm/netlogic/xlr/fmn.h>
Jayachandran C65040e22011-11-16 00:21:28 +000066#else
67#error "Unknown CPU"
68#endif
Jayachandran C0c965402011-11-11 17:08:29 +053069
Jayachandran C38541742012-10-31 12:01:41 +000070#ifdef CONFIG_SMP
71#define SMP_IRQ_MASK ((1ULL << IRQ_IPI_SMP_FUNCTION) | \
72 (1ULL << IRQ_IPI_SMP_RESCHEDULE))
73#else
74#define SMP_IRQ_MASK 0
75#endif
Ralf Baechle70342282013-01-22 12:59:30 +010076#define PERCPU_IRQ_MASK (SMP_IRQ_MASK | (1ull << IRQ_TIMER) | \
Ganesan Ramalingamed21cfe2012-10-31 12:01:42 +000077 (1ull << IRQ_FMN))
Jayachandran C38541742012-10-31 12:01:41 +000078
79struct nlm_pic_irq {
80 void (*extra_ack)(struct irq_data *);
81 struct nlm_soc_info *node;
82 int picirq;
83 int irt;
84 int flags;
85};
86
Jayachandran C0c965402011-11-11 17:08:29 +053087static void xlp_pic_enable(struct irq_data *d)
88{
89 unsigned long flags;
Jayachandran C38541742012-10-31 12:01:41 +000090 struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
Jayachandran C0c965402011-11-11 17:08:29 +053091
Jayachandran C38541742012-10-31 12:01:41 +000092 BUG_ON(!pd);
93 spin_lock_irqsave(&pd->node->piclock, flags);
94 nlm_pic_enable_irt(pd->node->picbase, pd->irt);
95 spin_unlock_irqrestore(&pd->node->piclock, flags);
Jayachandran C0c965402011-11-11 17:08:29 +053096}
97
98static void xlp_pic_disable(struct irq_data *d)
99{
Jayachandran C38541742012-10-31 12:01:41 +0000100 struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
Jayachandran C0c965402011-11-11 17:08:29 +0530101 unsigned long flags;
Jayachandran C0c965402011-11-11 17:08:29 +0530102
Jayachandran C38541742012-10-31 12:01:41 +0000103 BUG_ON(!pd);
104 spin_lock_irqsave(&pd->node->piclock, flags);
105 nlm_pic_disable_irt(pd->node->picbase, pd->irt);
106 spin_unlock_irqrestore(&pd->node->piclock, flags);
Jayachandran C0c965402011-11-11 17:08:29 +0530107}
108
109static void xlp_pic_mask_ack(struct irq_data *d)
110{
Jayachandran C38541742012-10-31 12:01:41 +0000111 struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
Jayachandran C0c965402011-11-11 17:08:29 +0530112
Jayachandran C220d9122013-01-14 15:11:54 +0000113 clear_c0_eimr(pd->picirq);
114 ack_c0_eirr(pd->picirq);
Jayachandran C0c965402011-11-11 17:08:29 +0530115}
116
117static void xlp_pic_unmask(struct irq_data *d)
118{
Jayachandran C38541742012-10-31 12:01:41 +0000119 struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
Jayachandran C0c965402011-11-11 17:08:29 +0530120
Jayachandran C220d9122013-01-14 15:11:54 +0000121 BUG_ON(!pd);
Jayachandran C0c965402011-11-11 17:08:29 +0530122
Jayachandran C38541742012-10-31 12:01:41 +0000123 if (pd->extra_ack)
124 pd->extra_ack(d);
125
Jayachandran C220d9122013-01-14 15:11:54 +0000126 /* re-enable the intr on this cpu */
127 set_c0_eimr(pd->picirq);
128
Jayachandran C0c965402011-11-11 17:08:29 +0530129 /* Ack is a single write, no need to lock */
Jayachandran C38541742012-10-31 12:01:41 +0000130 nlm_pic_ack(pd->node->picbase, pd->irt);
Jayachandran C0c965402011-11-11 17:08:29 +0530131}
132
133static struct irq_chip xlp_pic = {
134 .name = "XLP-PIC",
135 .irq_enable = xlp_pic_enable,
136 .irq_disable = xlp_pic_disable,
137 .irq_mask_ack = xlp_pic_mask_ack,
138 .irq_unmask = xlp_pic_unmask,
139};
140
141static void cpuintr_disable(struct irq_data *d)
142{
Jayachandran C220d9122013-01-14 15:11:54 +0000143 clear_c0_eimr(d->irq);
Jayachandran C0c965402011-11-11 17:08:29 +0530144}
145
146static void cpuintr_enable(struct irq_data *d)
147{
Jayachandran C220d9122013-01-14 15:11:54 +0000148 set_c0_eimr(d->irq);
Jayachandran C0c965402011-11-11 17:08:29 +0530149}
150
151static void cpuintr_ack(struct irq_data *d)
152{
Jayachandran C220d9122013-01-14 15:11:54 +0000153 ack_c0_eirr(d->irq);
Jayachandran C0c965402011-11-11 17:08:29 +0530154}
155
156/*
157 * Chip definition for CPU originated interrupts(timer, msg) and
158 * IPIs
159 */
160struct irq_chip nlm_cpu_intr = {
161 .name = "XLP-CPU-INTR",
162 .irq_enable = cpuintr_enable,
163 .irq_disable = cpuintr_disable,
Jayachandran C220d9122013-01-14 15:11:54 +0000164 .irq_mask = cpuintr_disable,
165 .irq_ack = cpuintr_ack,
166 .irq_eoi = cpuintr_enable,
Jayachandran C0c965402011-11-11 17:08:29 +0530167};
168
Jayachandran C38541742012-10-31 12:01:41 +0000169static void __init nlm_init_percpu_irqs(void)
Jayachandran C0c965402011-11-11 17:08:29 +0530170{
Jayachandran C38541742012-10-31 12:01:41 +0000171 int i;
Jayachandran C0c965402011-11-11 17:08:29 +0530172
173 for (i = 0; i < PIC_IRT_FIRST_IRQ; i++)
174 irq_set_chip_and_handler(i, &nlm_cpu_intr, handle_percpu_irq);
Jayachandran C0c965402011-11-11 17:08:29 +0530175#ifdef CONFIG_SMP
176 irq_set_chip_and_handler(IRQ_IPI_SMP_FUNCTION, &nlm_cpu_intr,
177 nlm_smp_function_ipi_handler);
178 irq_set_chip_and_handler(IRQ_IPI_SMP_RESCHEDULE, &nlm_cpu_intr,
179 nlm_smp_resched_ipi_handler);
Jayachandran C0c965402011-11-11 17:08:29 +0530180#endif
Jayachandran C38541742012-10-31 12:01:41 +0000181}
Jayachandran C0c965402011-11-11 17:08:29 +0530182
Jayachandran C38541742012-10-31 12:01:41 +0000183void nlm_setup_pic_irq(int node, int picirq, int irq, int irt)
184{
185 struct nlm_pic_irq *pic_data;
186 int xirq;
187
188 xirq = nlm_irq_to_xirq(node, irq);
189 pic_data = kzalloc(sizeof(*pic_data), GFP_KERNEL);
190 BUG_ON(pic_data == NULL);
191 pic_data->irt = irt;
192 pic_data->picirq = picirq;
193 pic_data->node = nlm_get_node(node);
194 irq_set_chip_and_handler(xirq, &xlp_pic, handle_level_irq);
195 irq_set_handler_data(xirq, pic_data);
196}
197
198void nlm_set_pic_extra_ack(int node, int irq, void (*xack)(struct irq_data *))
199{
200 struct nlm_pic_irq *pic_data;
201 int xirq;
202
203 xirq = nlm_irq_to_xirq(node, irq);
204 pic_data = irq_get_handler_data(xirq);
205 pic_data->extra_ack = xack;
206}
207
208static void nlm_init_node_irqs(int node)
209{
210 int i, irt;
211 uint64_t irqmask;
212 struct nlm_soc_info *nodep;
213
214 pr_info("Init IRQ for node %d\n", node);
215 nodep = nlm_get_node(node);
216 irqmask = PERCPU_IRQ_MASK;
217 for (i = PIC_IRT_FIRST_IRQ; i <= PIC_IRT_LAST_IRQ; i++) {
218 irt = nlm_irq_to_irt(i);
Jayachandran C0c965402011-11-11 17:08:29 +0530219 if (irt == -1)
220 continue;
Jayachandran C38541742012-10-31 12:01:41 +0000221 nlm_setup_pic_irq(node, i, i, irt);
222 /* set interrupts to first cpu in node */
223 nlm_pic_init_irt(nodep->picbase, irt, i,
Jayachandran C4e45e542013-01-14 15:11:57 +0000224 node * NLM_CPUS_PER_NODE, 0);
Jayachandran C38541742012-10-31 12:01:41 +0000225 irqmask |= (1ull << i);
Jayachandran C0c965402011-11-11 17:08:29 +0530226 }
Jayachandran C77ae7982012-10-31 12:01:39 +0000227 nodep->irqmask = irqmask;
Jayachandran C0c965402011-11-11 17:08:29 +0530228}
229
Jayachandran C38541742012-10-31 12:01:41 +0000230void nlm_smp_irq_init(int hwcpuid)
Jayachandran C0c965402011-11-11 17:08:29 +0530231{
Jayachandran C38541742012-10-31 12:01:41 +0000232 int node, cpu;
233
234 node = hwcpuid / NLM_CPUS_PER_NODE;
235 cpu = hwcpuid % NLM_CPUS_PER_NODE;
236
237 if (cpu == 0 && node != 0)
238 nlm_init_node_irqs(node);
Jayachandran C77ae7982012-10-31 12:01:39 +0000239 write_c0_eimr(nlm_current_node()->irqmask);
Jayachandran C0c965402011-11-11 17:08:29 +0530240}
241
242asmlinkage void plat_irq_dispatch(void)
243{
244 uint64_t eirr;
Jayachandran C77ae7982012-10-31 12:01:39 +0000245 int i, node;
Jayachandran C0c965402011-11-11 17:08:29 +0530246
Jayachandran C77ae7982012-10-31 12:01:39 +0000247 node = nlm_nodeid();
Jayachandran C220d9122013-01-14 15:11:54 +0000248 eirr = read_c0_eirr_and_eimr();
Jayachandran C8ecd0832013-06-10 06:41:10 +0000249 if (eirr == 0)
Jayachandran C0c965402011-11-11 17:08:29 +0530250 return;
251
Jayachandran C8ecd0832013-06-10 06:41:10 +0000252 i = __ffs64(eirr);
Jayachandran C38541742012-10-31 12:01:41 +0000253 /* per-CPU IRQs don't need translation */
Jayachandran C8ecd0832013-06-10 06:41:10 +0000254 if (i < PIC_IRQ_BASE) {
Jayachandran C38541742012-10-31 12:01:41 +0000255 do_IRQ(i);
256 return;
257 }
258
259 /* top level irq handling */
Jayachandran C77ae7982012-10-31 12:01:39 +0000260 do_IRQ(nlm_irq_to_xirq(node, i));
Jayachandran C0c965402011-11-11 17:08:29 +0530261}
Jayachandran C628f0652013-07-17 10:27:26 +0000262
263#ifdef CONFIG_OF
264static struct irq_domain *xlp_pic_domain;
265
266static const struct irq_domain_ops xlp_pic_irq_domain_ops = {
267 .xlate = irq_domain_xlate_onetwocell,
268};
269
270static int __init xlp_of_pic_init(struct device_node *node,
271 struct device_node *parent)
272{
273 const int n_picirqs = PIC_IRT_LAST_IRQ - PIC_IRQ_BASE + 1;
274 struct resource res;
275 int socid, ret;
276
277 /* we need a hack to get the PIC's SoC chip id */
278 ret = of_address_to_resource(node, 0, &res);
279 if (ret < 0) {
280 pr_err("PIC %s: reg property not found!\n", node->name);
281 return -EINVAL;
282 }
283 socid = (res.start >> 18) & 0x3;
284 xlp_pic_domain = irq_domain_add_legacy(node, n_picirqs,
285 nlm_irq_to_xirq(socid, PIC_IRQ_BASE), PIC_IRQ_BASE,
286 &xlp_pic_irq_domain_ops, NULL);
287 if (xlp_pic_domain == NULL) {
288 pr_err("PIC %s: Creating legacy domain failed!\n", node->name);
289 return -EINVAL;
290 }
291 pr_info("Node %d: IRQ domain created for PIC@%pa\n", socid,
292 &res.start);
293 return 0;
294}
295
296static struct of_device_id __initdata xlp_pic_irq_ids[] = {
297 { .compatible = "netlogic,xlp-pic", .data = xlp_of_pic_init },
298 {},
299};
300#endif
301
302void __init arch_init_irq(void)
303{
304 /* Initialize the irq descriptors */
305 nlm_init_percpu_irqs();
306 nlm_init_node_irqs(0);
307 write_c0_eimr(nlm_current_node()->irqmask);
308#if defined(CONFIG_CPU_XLR)
309 nlm_setup_fmn_irq();
310#endif
311#if defined(CONFIG_OF)
312 of_irq_init(xlp_pic_irq_ids);
313#endif
314}