blob: 10eb1a443626b2b4411e0c488ad6386e3f2e8976 [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>
Arnd Bergmann2fb9d202006-01-05 14:05:29 +000034#include <linux/module.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
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100059static struct irq_host *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
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100075static void iic_mask(unsigned int irq)
76{
77}
78
79static void iic_unmask(unsigned int irq)
80{
81}
82
83static void iic_eoi(unsigned int irq)
Arnd Bergmanncebf5892005-06-23 09:43:43 +100084{
Tejun Heo6b7487f2009-10-29 22:34:14 +090085 struct iic *iic = &__get_cpu_var(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",
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100092 .mask = iic_mask,
93 .unmask = iic_unmask,
94 .eoi = iic_eoi,
Arnd Bergmanncebf5892005-06-23 09:43:43 +100095};
96
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +100097
98static void iic_ioexc_eoi(unsigned int irq)
99{
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{
Arnd Bergmann43b4f402006-10-04 17:26:24 +0200104 struct cbe_iic_regs __iomem *node_iic = (void __iomem *)desc->handler_data;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000105 unsigned int base = (irq & 0xffffff00) | IIC_IRQ_TYPE_IOEXC;
106 unsigned long bits, ack;
107 int cascade;
108
109 for (;;) {
110 bits = in_be64(&node_iic->iic_is);
111 if (bits == 0)
112 break;
113 /* pre-ack edge interrupts */
114 ack = bits & IIC_ISR_EDGE_MASK;
115 if (ack)
116 out_be64(&node_iic->iic_is, ack);
117 /* handle them */
118 for (cascade = 63; cascade >= 0; cascade--)
119 if (bits & (0x8000000000000000UL >> cascade)) {
120 unsigned int cirq =
121 irq_linear_revmap(iic_host,
122 base | cascade);
123 if (cirq != NO_IRQ)
Olof Johansson49f19ce2006-10-05 20:31:10 -0500124 generic_handle_irq(cirq);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000125 }
126 /* post-ack level interrupts */
127 ack = bits & ~IIC_ISR_EDGE_MASK;
128 if (ack)
129 out_be64(&node_iic->iic_is, ack);
130 }
131 desc->chip->eoi(irq);
132}
133
134
135static struct irq_chip iic_ioexc_chip = {
Anton Blanchardfc380c02010-01-31 20:33:41 +0000136 .name = "CELL-IOEX",
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000137 .mask = iic_mask,
138 .unmask = iic_unmask,
139 .eoi = iic_ioexc_eoi,
140};
141
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000142/* Get an IRQ number from the pending state register of the IIC */
Olaf Hering35a84c22006-10-07 22:08:26 +1000143static unsigned int iic_get_irq(void)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000144{
Geoff Levand9e6ee342006-08-09 15:28:13 -0700145 struct cbe_iic_pending_bits pending;
146 struct iic *iic;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000147 unsigned int virq;
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000148
Tejun Heo6b7487f2009-10-29 22:34:14 +0900149 iic = &__get_cpu_var(cpu_iic);
Geoff Levand9e6ee342006-08-09 15:28:13 -0700150 *(unsigned long *) &pending =
Ingo Molnarb36ac9e2009-01-06 14:03:44 +0000151 in_be64((u64 __iomem *) &iic->regs->pending_destr);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000152 if (!(pending.flags & CBE_IIC_IRQ_VALID))
153 return NO_IRQ;
154 virq = irq_linear_revmap(iic_host, iic_pending_to_hwnum(pending));
155 if (virq == NO_IRQ)
156 return NO_IRQ;
Geoff Levand9e6ee342006-08-09 15:28:13 -0700157 iic->eoi_stack[++iic->eoi_ptr] = pending.prio;
158 BUG_ON(iic->eoi_ptr > 15);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000159 return virq;
Jens Osterkampd0e57c62006-03-23 00:00:06 +0100160}
161
Olof Johansson4bfac362007-10-28 04:28:51 +1100162void iic_setup_cpu(void)
163{
Tejun Heo6b7487f2009-10-29 22:34:14 +0900164 out_be64(&__get_cpu_var(cpu_iic).regs->prio, 0xff);
Olof Johansson4bfac362007-10-28 04:28:51 +1100165}
166
167u8 iic_get_target_id(int cpu)
168{
Tejun Heo6b7487f2009-10-29 22:34:14 +0900169 return per_cpu(cpu_iic, cpu).target_id;
Olof Johansson4bfac362007-10-28 04:28:51 +1100170}
171
172EXPORT_SYMBOL_GPL(iic_get_target_id);
173
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000174#ifdef CONFIG_SMP
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200175
176/* Use the highest interrupt priorities for IPI */
177static inline int iic_ipi_to_irq(int ipi)
178{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000179 return IIC_IRQ_TYPE_IPI + 0xf - ipi;
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200180}
181
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000182void iic_cause_IPI(int cpu, int mesg)
183{
Tejun Heo6b7487f2009-10-29 22:34:14 +0900184 out_be64(&per_cpu(cpu_iic, cpu).regs->generate, (0xf - mesg) << 4);
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000185}
186
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000187struct irq_host *iic_get_irq_host(int node)
188{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000189 return iic_host;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000190}
191EXPORT_SYMBOL_GPL(iic_get_irq_host);
192
David Howells7d12e782006-10-05 14:55:46 +0100193static irqreturn_t iic_ipi_action(int irq, void *dev_id)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000194{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000195 int ipi = (int)(long)dev_id;
196
David Howells7d12e782006-10-05 14:55:46 +0100197 smp_message_recv(ipi);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000198
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000199 return IRQ_HANDLED;
200}
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200201static void iic_request_ipi(int ipi, const char *name)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000202{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000203 int virq;
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200204
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000205 virq = irq_create_mapping(iic_host, iic_ipi_to_irq(ipi));
206 if (virq == NO_IRQ) {
207 printk(KERN_ERR
208 "iic: failed to map IPI %s\n", name);
209 return;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000210 }
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000211 if (request_irq(virq, iic_ipi_action, IRQF_DISABLED, name,
212 (void *)(long)ipi))
213 printk(KERN_ERR
214 "iic: failed to request IPI %s\n", name);
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000215}
216
217void iic_request_IPIs(void)
218{
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200219 iic_request_ipi(PPC_MSG_CALL_FUNCTION, "IPI-call");
220 iic_request_ipi(PPC_MSG_RESCHEDULE, "IPI-resched");
Jens Axboeb7d7a242008-06-26 11:22:13 +0200221 iic_request_ipi(PPC_MSG_CALL_FUNC_SINGLE, "IPI-call-single");
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000222#ifdef CONFIG_DEBUGGER
Arnd Bergmanna84195f2005-08-18 19:35:21 +0200223 iic_request_ipi(PPC_MSG_DEBUGGER_BREAK, "IPI-debug");
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000224#endif /* CONFIG_DEBUGGER */
225}
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000226
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000227#endif /* CONFIG_SMP */
228
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000229
230static int iic_host_match(struct irq_host *h, struct device_node *node)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000231{
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000232 return of_device_is_compatible(node,
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000233 "IBM,CBEA-Internal-Interrupt-Controller");
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000234}
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000235
Jeremy Kerr5711fe92008-04-04 17:55:28 +1100236extern int noirqdebug;
237
238static void handle_iic_irq(unsigned int irq, struct irq_desc *desc)
239{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100240 raw_spin_lock(&desc->lock);
Jeremy Kerr5711fe92008-04-04 17:55:28 +1100241
242 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
243
244 /*
245 * If we're currently running this IRQ, or its disabled,
246 * we shouldn't process the IRQ. Mark it pending, handle
247 * the necessary masking and go out
248 */
249 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
250 !desc->action)) {
251 desc->status |= IRQ_PENDING;
252 goto out_eoi;
253 }
254
Yinghai Ludee41022009-01-11 00:29:15 -0800255 kstat_incr_irqs_this_cpu(irq, desc);
Jeremy Kerr5711fe92008-04-04 17:55:28 +1100256
257 /* Mark the IRQ currently in progress.*/
258 desc->status |= IRQ_INPROGRESS;
259
260 do {
261 struct irqaction *action = desc->action;
262 irqreturn_t action_ret;
263
264 if (unlikely(!action))
265 goto out_eoi;
266
267 desc->status &= ~IRQ_PENDING;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100268 raw_spin_unlock(&desc->lock);
Jeremy Kerr5711fe92008-04-04 17:55:28 +1100269 action_ret = handle_IRQ_event(irq, action);
270 if (!noirqdebug)
271 note_interrupt(irq, desc, action_ret);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100272 raw_spin_lock(&desc->lock);
Jeremy Kerr5711fe92008-04-04 17:55:28 +1100273
274 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
275
276 desc->status &= ~IRQ_INPROGRESS;
277out_eoi:
278 desc->chip->eoi(irq);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100279 raw_spin_unlock(&desc->lock);
Jeremy Kerr5711fe92008-04-04 17:55:28 +1100280}
281
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000282static int iic_host_map(struct irq_host *h, unsigned int virq,
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700283 irq_hw_number_t hw)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000284{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000285 switch (hw & IIC_IRQ_TYPE_MASK) {
286 case IIC_IRQ_TYPE_IPI:
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000287 set_irq_chip_and_handler(virq, &iic_chip, handle_percpu_irq);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000288 break;
289 case IIC_IRQ_TYPE_IOEXC:
290 set_irq_chip_and_handler(virq, &iic_ioexc_chip,
Jeremy Kerr5711fe92008-04-04 17:55:28 +1100291 handle_iic_irq);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000292 break;
293 default:
Jeremy Kerr5711fe92008-04-04 17:55:28 +1100294 set_irq_chip_and_handler(virq, &iic_chip, handle_iic_irq);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000295 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000296 return 0;
297}
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000298
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000299static int iic_host_xlate(struct irq_host *h, struct device_node *ct,
Roman Fietze40d50cf2009-12-08 02:39:50 +0000300 const u32 *intspec, unsigned int intsize,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000301 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
302
303{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000304 unsigned int node, ext, unit, class;
305 const u32 *val;
306
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000307 if (!of_device_is_compatible(ct,
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000308 "IBM,CBEA-Internal-Interrupt-Controller"))
309 return -ENODEV;
310 if (intsize != 1)
311 return -ENODEV;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000312 val = of_get_property(ct, "#interrupt-cells", NULL);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000313 if (val == NULL || *val != 1)
314 return -ENODEV;
315
316 node = intspec[0] >> 24;
317 ext = (intspec[0] >> 16) & 0xff;
318 class = (intspec[0] >> 8) & 0xff;
319 unit = intspec[0] & 0xff;
320
321 /* Check if node is in supported range */
322 if (node > 1)
323 return -EINVAL;
324
325 /* Build up interrupt number, special case for IO exceptions */
326 *out_hwirq = (node << IIC_IRQ_NODE_SHIFT);
327 if (unit == IIC_UNIT_IIC && class == 1)
328 *out_hwirq |= IIC_IRQ_TYPE_IOEXC | ext;
329 else
330 *out_hwirq |= IIC_IRQ_TYPE_NORMAL |
331 (class << IIC_IRQ_CLASS_SHIFT) | unit;
332
333 /* Dummy flags, ignored by iic code */
334 *out_flags = IRQ_TYPE_EDGE_RISING;
335
336 return 0;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000337}
338
339static struct irq_host_ops iic_host_ops = {
340 .match = iic_host_match,
341 .map = iic_host_map,
342 .xlate = iic_host_xlate,
343};
344
345static void __init init_one_iic(unsigned int hw_cpu, unsigned long addr,
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000346 struct device_node *node)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000347{
348 /* XXX FIXME: should locate the linux CPU number from the HW cpu
349 * number properly. We are lucky for now
350 */
Tejun Heo6b7487f2009-10-29 22:34:14 +0900351 struct iic *iic = &per_cpu(cpu_iic, hw_cpu);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000352
353 iic->regs = ioremap(addr, sizeof(struct cbe_iic_thread_regs));
354 BUG_ON(iic->regs == NULL);
355
356 iic->target_id = ((hw_cpu & 2) << 3) | ((hw_cpu & 1) ? 0xf : 0xe);
357 iic->eoi_stack[0] = 0xff;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000358 iic->node = of_node_get(node);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000359 out_be64(&iic->regs->prio, 0);
360
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000361 printk(KERN_INFO "IIC for CPU %d target id 0x%x : %s\n",
362 hw_cpu, iic->target_id, node->full_name);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000363}
364
365static int __init setup_iic(void)
366{
367 struct device_node *dn;
368 struct resource r0, r1;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000369 unsigned int node, cascade, found = 0;
Arnd Bergmann43b4f402006-10-04 17:26:24 +0200370 struct cbe_iic_regs __iomem *node_iic;
Geoff Levand9e6ee342006-08-09 15:28:13 -0700371 const u32 *np;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000372
373 for (dn = NULL;
374 (dn = of_find_node_by_name(dn,"interrupt-controller")) != NULL;) {
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000375 if (!of_device_is_compatible(dn,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000376 "IBM,CBEA-Internal-Interrupt-Controller"))
377 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000378 np = of_get_property(dn, "ibm,interrupt-server-ranges", NULL);
Geoff Levand9e6ee342006-08-09 15:28:13 -0700379 if (np == NULL) {
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000380 printk(KERN_WARNING "IIC: CPU association not found\n");
381 of_node_put(dn);
382 return -ENODEV;
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000383 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000384 if (of_address_to_resource(dn, 0, &r0) ||
385 of_address_to_resource(dn, 1, &r1)) {
386 printk(KERN_WARNING "IIC: Can't resolve addresses\n");
387 of_node_put(dn);
388 return -ENODEV;
389 }
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000390 found++;
391 init_one_iic(np[0], r0.start, dn);
392 init_one_iic(np[1], r1.start, dn);
393
394 /* Setup cascade for IO exceptions. XXX cleanup tricks to get
395 * node vs CPU etc...
396 * Note that we configure the IIC_IRR here with a hard coded
397 * priority of 1. We might want to improve that later.
398 */
399 node = np[0] >> 1;
400 node_iic = cbe_get_cpu_iic_regs(np[0]);
401 cascade = node << IIC_IRQ_NODE_SHIFT;
402 cascade |= 1 << IIC_IRQ_CLASS_SHIFT;
403 cascade |= IIC_UNIT_IIC;
404 cascade = irq_create_mapping(iic_host, cascade);
405 if (cascade == NO_IRQ)
406 continue;
Arnd Bergmann43b4f402006-10-04 17:26:24 +0200407 /*
408 * irq_data is a generic pointer that gets passed back
409 * to us later, so the forced cast is fine.
410 */
411 set_irq_data(cascade, (void __force *)node_iic);
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000412 set_irq_chained_handler(cascade , iic_ioexc_cascade);
413 out_be64(&node_iic->iic_ir,
414 (1 << 12) /* priority */ |
415 (node << 4) /* dest node */ |
416 IIC_UNIT_THREAD_0 /* route them to thread 0 */);
417 /* Flush pending (make sure it triggers if there is
418 * anything pending
419 */
420 out_be64(&node_iic->iic_is, 0xfffffffffffffffful);
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000421 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000422
423 if (found)
424 return 0;
425 else
426 return -ENODEV;
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000427}
428
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000429void __init iic_init_IRQ(void)
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000430{
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000431 /* Setup an irq host data structure */
Michael Ellerman52964f82007-08-28 18:47:54 +1000432 iic_host = irq_alloc_host(NULL, IRQ_HOST_MAP_LINEAR, IIC_SOURCE_COUNT,
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000433 &iic_host_ops, IIC_IRQ_INVALID);
434 BUG_ON(iic_host == NULL);
435 irq_set_default_host(iic_host);
436
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000437 /* Discover and initialize iics */
Jens Osterkampd0e57c62006-03-23 00:00:06 +0100438 if (setup_iic() < 0)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000439 panic("IIC: Failed to initialize !\n");
Jens Osterkampd0e57c62006-03-23 00:00:06 +0100440
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000441 /* Set master interrupt handling function */
442 ppc_md.get_irq = iic_get_irq;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000443
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000444 /* Enable on current CPU */
445 iic_setup_cpu();
Arnd Bergmanncebf5892005-06-23 09:43:43 +1000446}
Kevin Corry0443bbd2006-11-20 18:45:15 +0100447
448void iic_set_interrupt_routing(int cpu, int thread, int priority)
449{
450 struct cbe_iic_regs __iomem *iic_regs = cbe_get_cpu_iic_regs(cpu);
451 u64 iic_ir = 0;
452 int node = cpu >> 1;
453
454 /* Set which node and thread will handle the next interrupt */
455 iic_ir |= CBE_IIC_IR_PRIO(priority) |
456 CBE_IIC_IR_DEST_NODE(node);
457 if (thread == 0)
458 iic_ir |= CBE_IIC_IR_DEST_UNIT(CBE_IIC_IR_PT_0);
459 else
460 iic_ir |= CBE_IIC_IR_DEST_UNIT(CBE_IIC_IR_PT_1);
461 out_be64(&iic_regs->iic_ir, iic_ir);
462}