blob: a15f1efc295f936d3de64bb17a62d76c86778a1c [file] [log] [blame]
Arnd Bergmanncebf5892005-06-23 09:43:43 +10001/*
Arnd Bergmannf3f66f52005-10-31 20:08:37 -05002 * Cell Internal Interrupt Controller
Arnd Bergmanncebf5892005-06-23 09:43:43 +10003 *
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +10004 * Copyright (C) 2006 Benjamin Herrenschmidt (benh@kernel.crashing.org)
5 * IBM, Corp.
6 *
Arnd Bergmanncebf5892005-06-23 09:43:43 +10007 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
8 *
9 * Author: Arnd Bergmann <arndb@de.ibm.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100024 *
25 * TODO:
26 * - Fix various assumptions related to HW CPU numbers vs. linux CPU numbers
27 * vs node numbers in the setup code
28 * - Implement proper handling of maxcpus=1/2 (that is, routing of irqs from
29 * a non-active node to the active node)
Arnd Bergmanncebf5892005-06-23 09:43:43 +100030 */
31
Arnd Bergmanncebf5892005-06-23 09:43:43 +100032#include <linux/interrupt.h>
33#include <linux/irq.h>
Paul Gortmaker4b16f8e2011-07-22 18:24:23 -040034#include <linux/export.h>
Arnd Bergmanncebf5892005-06-23 09:43:43 +100035#include <linux/percpu.h>
36#include <linux/types.h>
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100037#include <linux/ioport.h>
Jeremy Kerr5711fe92008-04-04 17:55:28 +110038#include <linux/kernel_stat.h>
Arnd Bergmanncebf5892005-06-23 09:43:43 +100039
40#include <asm/io.h>
41#include <asm/pgtable.h>
42#include <asm/prom.h>
43#include <asm/ptrace.h>
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100044#include <asm/machdep.h>
Benjamin Herrenschmidteef686a02007-10-04 15:40:42 +100045#include <asm/cell-regs.h>
Arnd Bergmanncebf5892005-06-23 09:43:43 +100046
Arnd Bergmannf3f66f52005-10-31 20:08:37 -050047#include "interrupt.h"
Arnd Bergmanncebf5892005-06-23 09:43:43 +100048
49struct iic {
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +020050 struct cbe_iic_thread_regs __iomem *regs;
Arnd Bergmann2fb9d202006-01-05 14:05:29 +000051 u8 target_id;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100052 u8 eoi_stack[16];
53 int eoi_ptr;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100054 struct device_node *node;
Arnd Bergmanncebf5892005-06-23 09:43:43 +100055};
56
Tejun Heo6b7487f2009-10-29 22:34:14 +090057static DEFINE_PER_CPU(struct iic, cpu_iic);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100058#define IIC_NODE_COUNT 2
Grant Likelybae1d8f2012-02-14 14:06:50 -070059static struct irq_domain *iic_host;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100060
61/* Convert between "pending" bits and hw irq number */
62static irq_hw_number_t iic_pending_to_hwnum(struct cbe_iic_pending_bits bits)
63{
64 unsigned char unit = bits.source & 0xf;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100065 unsigned char node = bits.source >> 4;
66 unsigned char class = bits.class & 3;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100067
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100068 /* Decode IPIs */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100069 if (bits.flags & CBE_IIC_IRQ_IPI)
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100070 return IIC_IRQ_TYPE_IPI | (bits.prio >> 4);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100071 else
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100072 return (node << IIC_IRQ_NODE_SHIFT) | (class << 4) | unit;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100073}
Arnd Bergmanncebf5892005-06-23 09:43:43 +100074
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +000075static void iic_mask(struct irq_data *d)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100076{
77}
78
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +000079static void iic_unmask(struct irq_data *d)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100080{
81}
82
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +000083static void iic_eoi(struct irq_data *d)
Arnd Bergmanncebf5892005-06-23 09:43:43 +100084{
Christoph Lameter69111ba2014-10-21 15:23:25 -050085 struct iic *iic = this_cpu_ptr(&cpu_iic);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100086 out_be64(&iic->regs->prio, iic->eoi_stack[--iic->eoi_ptr]);
87 BUG_ON(iic->eoi_ptr < 0);
Arnd Bergmanncebf5892005-06-23 09:43:43 +100088}
89
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100090static struct irq_chip iic_chip = {
Anton Blanchardfc380c02010-01-31 20:33:41 +000091 .name = "CELL-IIC",
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +000092 .irq_mask = iic_mask,
93 .irq_unmask = iic_unmask,
94 .irq_eoi = iic_eoi,
Arnd Bergmanncebf5892005-06-23 09:43:43 +100095};
96
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100097
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +000098static void iic_ioexc_eoi(struct irq_data *d)
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100099{
100}
101
Olaf Hering35a84c22006-10-07 22:08:26 +1000102static void iic_ioexc_cascade(unsigned int irq, struct irq_desc *desc)
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000103{
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100104 struct irq_chip *chip = irq_desc_get_chip(desc);
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +0000105 struct cbe_iic_regs __iomem *node_iic =
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100106 (void __iomem *)irq_desc_get_handler_data(desc);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000107 unsigned int base = (irq & 0xffffff00) | IIC_IRQ_TYPE_IOEXC;
108 unsigned long bits, ack;
109 int cascade;
110
111 for (;;) {
112 bits = in_be64(&node_iic->iic_is);
113 if (bits == 0)
114 break;
115 /* pre-ack edge interrupts */
116 ack = bits & IIC_ISR_EDGE_MASK;
117 if (ack)
118 out_be64(&node_iic->iic_is, ack);
119 /* handle them */
120 for (cascade = 63; cascade >= 0; cascade--)
121 if (bits & (0x8000000000000000UL >> cascade)) {
122 unsigned int cirq =
123 irq_linear_revmap(iic_host,
124 base | cascade);
125 if (cirq != NO_IRQ)
Olof Johansson49f19ce2006-10-05 20:31:10 -0500126 generic_handle_irq(cirq);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000127 }
128 /* post-ack level interrupts */
129 ack = bits & ~IIC_ISR_EDGE_MASK;
130 if (ack)
131 out_be64(&node_iic->iic_is, ack);
132 }
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +0000133 chip->irq_eoi(&desc->irq_data);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000134}
135
136
137static struct irq_chip iic_ioexc_chip = {
Anton Blanchardfc380c02010-01-31 20:33:41 +0000138 .name = "CELL-IOEX",
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +0000139 .irq_mask = iic_mask,
140 .irq_unmask = iic_unmask,
141 .irq_eoi = iic_ioexc_eoi,
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000142};
143
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000144/* Get an IRQ number from the pending state register of the IIC */
Olaf Hering35a84c22006-10-07 22:08:26 +1000145static unsigned int iic_get_irq(void)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000146{
Geoff Levand9e6ee342006-08-09 15:28:13 -0700147 struct cbe_iic_pending_bits pending;
148 struct iic *iic;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000149 unsigned int virq;
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000150
Christoph Lameter69111ba2014-10-21 15:23:25 -0500151 iic = this_cpu_ptr(&cpu_iic);
Geoff Levand9e6ee342006-08-09 15:28:13 -0700152 *(unsigned long *) &pending =
Ingo Molnarb36ac9e2009-01-06 14:03:44 +0000153 in_be64((u64 __iomem *) &iic->regs->pending_destr);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000154 if (!(pending.flags & CBE_IIC_IRQ_VALID))
155 return NO_IRQ;
156 virq = irq_linear_revmap(iic_host, iic_pending_to_hwnum(pending));
157 if (virq == NO_IRQ)
158 return NO_IRQ;
Geoff Levand9e6ee342006-08-09 15:28:13 -0700159 iic->eoi_stack[++iic->eoi_ptr] = pending.prio;
160 BUG_ON(iic->eoi_ptr > 15);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000161 return virq;
Jens Osterkampd0e57c62006-03-23 00:00:06 +0100162}
163
Olof Johansson4bfac362007-10-28 04:28:51 +1100164void iic_setup_cpu(void)
165{
Michael Ellermanb0dd00a2015-04-03 14:11:53 +1100166 out_be64(&this_cpu_ptr(&cpu_iic)->regs->prio, 0xff);
Olof Johansson4bfac362007-10-28 04:28:51 +1100167}
168
169u8 iic_get_target_id(int cpu)
170{
Tejun Heo6b7487f2009-10-29 22:34:14 +0900171 return per_cpu(cpu_iic, cpu).target_id;
Olof Johansson4bfac362007-10-28 04:28:51 +1100172}
173
174EXPORT_SYMBOL_GPL(iic_get_target_id);
175
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000176#ifdef CONFIG_SMP
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200177
178/* Use the highest interrupt priorities for IPI */
Milton Millerd5a1c192011-05-24 20:34:18 +0000179static inline int iic_msg_to_irq(int msg)
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200180{
Milton Millerd5a1c192011-05-24 20:34:18 +0000181 return IIC_IRQ_TYPE_IPI + 0xf - msg;
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200182}
183
Milton Millerd5a1c192011-05-24 20:34:18 +0000184void iic_message_pass(int cpu, int msg)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000185{
Milton Millerd5a1c192011-05-24 20:34:18 +0000186 out_be64(&per_cpu(cpu_iic, cpu).regs->generate, (0xf - msg) << 4);
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000187}
188
Grant Likelybae1d8f2012-02-14 14:06:50 -0700189struct irq_domain *iic_get_irq_host(int node)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000190{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000191 return iic_host;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000192}
193EXPORT_SYMBOL_GPL(iic_get_irq_host);
194
Milton Millerd5a1c192011-05-24 20:34:18 +0000195static void iic_request_ipi(int msg)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000196{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000197 int virq;
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200198
Milton Millerd5a1c192011-05-24 20:34:18 +0000199 virq = irq_create_mapping(iic_host, iic_msg_to_irq(msg));
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000200 if (virq == NO_IRQ) {
201 printk(KERN_ERR
Milton Millerd5a1c192011-05-24 20:34:18 +0000202 "iic: failed to map IPI %s\n", smp_ipi_name[msg]);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000203 return;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000204 }
Milton Miller7ef71d72011-05-24 20:34:18 +0000205
206 /*
207 * If smp_request_message_ipi encounters an error it will notify
208 * the error. If a message is not needed it will return non-zero.
209 */
Milton Millerd5a1c192011-05-24 20:34:18 +0000210 if (smp_request_message_ipi(virq, msg))
Milton Miller7ef71d72011-05-24 20:34:18 +0000211 irq_dispose_mapping(virq);
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000212}
213
214void iic_request_IPIs(void)
215{
Milton Miller7ef71d72011-05-24 20:34:18 +0000216 iic_request_ipi(PPC_MSG_CALL_FUNCTION);
217 iic_request_ipi(PPC_MSG_RESCHEDULE);
Srivatsa S. Bhat1b67bee2014-02-26 05:37:43 +0530218 iic_request_ipi(PPC_MSG_TICK_BROADCAST);
Milton Miller7ef71d72011-05-24 20:34:18 +0000219 iic_request_ipi(PPC_MSG_DEBUGGER_BREAK);
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000220}
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000221
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000222#endif /* CONFIG_SMP */
223
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000224
Marc Zyngierad3aedf2015-07-28 14:46:08 +0100225static int iic_host_match(struct irq_domain *h, struct device_node *node,
226 enum irq_domain_bus_token bus_token)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000227{
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000228 return of_device_is_compatible(node,
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000229 "IBM,CBEA-Internal-Interrupt-Controller");
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000230}
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000231
Grant Likelybae1d8f2012-02-14 14:06:50 -0700232static int iic_host_map(struct irq_domain *h, unsigned int virq,
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700233 irq_hw_number_t hw)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000234{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000235 switch (hw & IIC_IRQ_TYPE_MASK) {
236 case IIC_IRQ_TYPE_IPI:
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100237 irq_set_chip_and_handler(virq, &iic_chip, handle_percpu_irq);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000238 break;
239 case IIC_IRQ_TYPE_IOEXC:
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100240 irq_set_chip_and_handler(virq, &iic_ioexc_chip,
Stephen Rothwelle1229962011-03-30 10:48:28 +1100241 handle_edge_eoi_irq);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000242 break;
243 default:
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100244 irq_set_chip_and_handler(virq, &iic_chip, handle_edge_eoi_irq);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000245 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000246 return 0;
247}
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000248
Grant Likelybae1d8f2012-02-14 14:06:50 -0700249static int iic_host_xlate(struct irq_domain *h, struct device_node *ct,
Roman Fietze40d50cf2009-12-08 02:39:50 +0000250 const u32 *intspec, unsigned int intsize,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000251 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
252
253{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000254 unsigned int node, ext, unit, class;
255 const u32 *val;
256
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000257 if (!of_device_is_compatible(ct,
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000258 "IBM,CBEA-Internal-Interrupt-Controller"))
259 return -ENODEV;
260 if (intsize != 1)
261 return -ENODEV;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000262 val = of_get_property(ct, "#interrupt-cells", NULL);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000263 if (val == NULL || *val != 1)
264 return -ENODEV;
265
266 node = intspec[0] >> 24;
267 ext = (intspec[0] >> 16) & 0xff;
268 class = (intspec[0] >> 8) & 0xff;
269 unit = intspec[0] & 0xff;
270
271 /* Check if node is in supported range */
272 if (node > 1)
273 return -EINVAL;
274
275 /* Build up interrupt number, special case for IO exceptions */
276 *out_hwirq = (node << IIC_IRQ_NODE_SHIFT);
277 if (unit == IIC_UNIT_IIC && class == 1)
278 *out_hwirq |= IIC_IRQ_TYPE_IOEXC | ext;
279 else
280 *out_hwirq |= IIC_IRQ_TYPE_NORMAL |
281 (class << IIC_IRQ_CLASS_SHIFT) | unit;
282
283 /* Dummy flags, ignored by iic code */
284 *out_flags = IRQ_TYPE_EDGE_RISING;
285
286 return 0;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000287}
288
Grant Likely9f70b8e2012-01-26 12:24:34 -0700289static const struct irq_domain_ops iic_host_ops = {
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000290 .match = iic_host_match,
291 .map = iic_host_map,
292 .xlate = iic_host_xlate,
293};
294
295static void __init init_one_iic(unsigned int hw_cpu, unsigned long addr,
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000296 struct device_node *node)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000297{
298 /* XXX FIXME: should locate the linux CPU number from the HW cpu
299 * number properly. We are lucky for now
300 */
Tejun Heo6b7487f2009-10-29 22:34:14 +0900301 struct iic *iic = &per_cpu(cpu_iic, hw_cpu);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000302
303 iic->regs = ioremap(addr, sizeof(struct cbe_iic_thread_regs));
304 BUG_ON(iic->regs == NULL);
305
306 iic->target_id = ((hw_cpu & 2) << 3) | ((hw_cpu & 1) ? 0xf : 0xe);
307 iic->eoi_stack[0] = 0xff;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000308 iic->node = of_node_get(node);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000309 out_be64(&iic->regs->prio, 0);
310
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000311 printk(KERN_INFO "IIC for CPU %d target id 0x%x : %s\n",
312 hw_cpu, iic->target_id, node->full_name);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000313}
314
315static int __init setup_iic(void)
316{
317 struct device_node *dn;
318 struct resource r0, r1;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000319 unsigned int node, cascade, found = 0;
Arnd Bergmann43b4f402006-10-04 17:26:24 +0200320 struct cbe_iic_regs __iomem *node_iic;
Geoff Levand9e6ee342006-08-09 15:28:13 -0700321 const u32 *np;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000322
323 for (dn = NULL;
324 (dn = of_find_node_by_name(dn,"interrupt-controller")) != NULL;) {
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000325 if (!of_device_is_compatible(dn,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000326 "IBM,CBEA-Internal-Interrupt-Controller"))
327 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000328 np = of_get_property(dn, "ibm,interrupt-server-ranges", NULL);
Geoff Levand9e6ee342006-08-09 15:28:13 -0700329 if (np == NULL) {
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000330 printk(KERN_WARNING "IIC: CPU association not found\n");
331 of_node_put(dn);
332 return -ENODEV;
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000333 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000334 if (of_address_to_resource(dn, 0, &r0) ||
335 of_address_to_resource(dn, 1, &r1)) {
336 printk(KERN_WARNING "IIC: Can't resolve addresses\n");
337 of_node_put(dn);
338 return -ENODEV;
339 }
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000340 found++;
341 init_one_iic(np[0], r0.start, dn);
342 init_one_iic(np[1], r1.start, dn);
343
344 /* Setup cascade for IO exceptions. XXX cleanup tricks to get
345 * node vs CPU etc...
346 * Note that we configure the IIC_IRR here with a hard coded
347 * priority of 1. We might want to improve that later.
348 */
349 node = np[0] >> 1;
350 node_iic = cbe_get_cpu_iic_regs(np[0]);
351 cascade = node << IIC_IRQ_NODE_SHIFT;
352 cascade |= 1 << IIC_IRQ_CLASS_SHIFT;
353 cascade |= IIC_UNIT_IIC;
354 cascade = irq_create_mapping(iic_host, cascade);
355 if (cascade == NO_IRQ)
356 continue;
Arnd Bergmann43b4f402006-10-04 17:26:24 +0200357 /*
358 * irq_data is a generic pointer that gets passed back
359 * to us later, so the forced cast is fine.
360 */
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100361 irq_set_handler_data(cascade, (void __force *)node_iic);
362 irq_set_chained_handler(cascade, iic_ioexc_cascade);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000363 out_be64(&node_iic->iic_ir,
364 (1 << 12) /* priority */ |
365 (node << 4) /* dest node */ |
366 IIC_UNIT_THREAD_0 /* route them to thread 0 */);
367 /* Flush pending (make sure it triggers if there is
368 * anything pending
369 */
370 out_be64(&node_iic->iic_is, 0xfffffffffffffffful);
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000371 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000372
373 if (found)
374 return 0;
375 else
376 return -ENODEV;
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000377}
378
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000379void __init iic_init_IRQ(void)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000380{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000381 /* Setup an irq host data structure */
Grant Likelya8db8cf2012-02-14 14:06:54 -0700382 iic_host = irq_domain_add_linear(NULL, IIC_SOURCE_COUNT, &iic_host_ops,
383 NULL);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000384 BUG_ON(iic_host == NULL);
385 irq_set_default_host(iic_host);
386
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000387 /* Discover and initialize iics */
Jens Osterkampd0e57c62006-03-23 00:00:06 +0100388 if (setup_iic() < 0)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000389 panic("IIC: Failed to initialize !\n");
Jens Osterkampd0e57c62006-03-23 00:00:06 +0100390
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000391 /* Set master interrupt handling function */
392 ppc_md.get_irq = iic_get_irq;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000393
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000394 /* Enable on current CPU */
395 iic_setup_cpu();
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000396}
Kevin Corry0443bbd2006-11-20 18:45:15 +0100397
398void iic_set_interrupt_routing(int cpu, int thread, int priority)
399{
400 struct cbe_iic_regs __iomem *iic_regs = cbe_get_cpu_iic_regs(cpu);
401 u64 iic_ir = 0;
402 int node = cpu >> 1;
403
404 /* Set which node and thread will handle the next interrupt */
405 iic_ir |= CBE_IIC_IR_PRIO(priority) |
406 CBE_IIC_IR_DEST_NODE(node);
407 if (thread == 0)
408 iic_ir |= CBE_IIC_IR_DEST_UNIT(CBE_IIC_IR_PT_0);
409 else
410 iic_ir |= CBE_IIC_IR_DEST_UNIT(CBE_IIC_IR_PT_1);
411 out_be64(&iic_regs->iic_ir, iic_ir);
412}