blob: 5bd90a7eb763327e06300d7dd51aef3eb6ff4123 [file] [log] [blame]
David Gibson007e8f52005-10-28 15:35:50 +10001/*
2 * arch/powerpc/platforms/pseries/xics.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright 2000 IBM Corporation.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100011
12#undef DEBUG
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/threads.h>
16#include <linux/kernel.h>
17#include <linux/irq.h>
18#include <linux/smp.h>
19#include <linux/interrupt.h>
20#include <linux/signal.h>
21#include <linux/init.h>
22#include <linux/gfp.h>
23#include <linux/radix-tree.h>
24#include <linux/cpu.h>
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100025
Michael Ellerman57cfb812006-03-21 20:45:59 +110026#include <asm/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/prom.h>
28#include <asm/io.h>
29#include <asm/pgtable.h>
30#include <asm/smp.h>
31#include <asm/rtas.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/hvcall.h>
33#include <asm/machdep.h>
Paul Mackerras22277182005-10-28 11:47:17 +100034#include <asm/i8259.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
David Gibson007e8f52005-10-28 15:35:50 +100036#include "xics.h"
Anton Blanchardb9377ff2006-07-19 08:01:28 +100037#include "plpar_wrappers.h"
David Gibson007e8f52005-10-28 15:35:50 +100038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define XICS_IPI 2
40#define XICS_IRQ_SPURIOUS 0
41
42/* Want a priority other than 0. Various HW issues require this. */
43#define DEFAULT_PRIORITY 5
44
David Gibson007e8f52005-10-28 15:35:50 +100045/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 * Mark IPIs as higher priority so we can take them inside interrupts that
Thomas Gleixner67144652006-07-01 19:29:22 -070047 * arent marked IRQF_DISABLED
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 */
49#define IPI_PRIORITY 4
50
51struct xics_ipl {
52 union {
53 u32 word;
54 u8 bytes[4];
55 } xirr_poll;
56 union {
57 u32 word;
58 u8 bytes[4];
59 } xirr;
60 u32 dummy;
61 union {
62 u32 word;
63 u8 bytes[4];
64 } qirr;
65};
66
67static struct xics_ipl __iomem *xics_per_cpu[NR_CPUS];
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static unsigned int default_server = 0xFF;
Anton Blanchard26370322005-09-12 13:12:11 +100070static unsigned int default_distrib_server = 0;
71static unsigned int interrupt_server_size = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100073static struct irq_host *xics_host;
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/*
76 * XICS only has a single IPI, so encode the messages per CPU
77 */
78struct xics_ipi_struct xics_ipi_message[NR_CPUS] __cacheline_aligned;
79
80/* RTAS service tokens */
Anton Blanchard26370322005-09-12 13:12:11 +100081static int ibm_get_xive;
82static int ibm_set_xive;
83static int ibm_int_on;
84static int ibm_int_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100086
87/* Direct HW low level accessors */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100090static inline unsigned int direct_xirr_info_get(int n_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 return in_be32(&xics_per_cpu[n_cpu]->xirr.word);
93}
94
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +100095static inline void direct_xirr_info_set(int n_cpu, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 out_be32(&xics_per_cpu[n_cpu]->xirr.word, value);
98}
99
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000100static inline void direct_cppr_info(int n_cpu, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 out_8(&xics_per_cpu[n_cpu]->xirr.bytes[0], value);
103}
104
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000105static inline void direct_qirr_info(int n_cpu, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 out_8(&xics_per_cpu[n_cpu]->qirr.bytes[0], value);
108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000111/* LPAR low level accessors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000114static inline unsigned int lpar_xirr_info_get(int n_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 unsigned long lpar_rc;
David Gibson007e8f52005-10-28 15:35:50 +1000117 unsigned long return_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 lpar_rc = plpar_xirr(&return_value);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200120 if (lpar_rc != H_SUCCESS)
David Gibson007e8f52005-10-28 15:35:50 +1000121 panic(" bad return code xirr - rc = %lx \n", lpar_rc);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000122 return (unsigned int)return_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000125static inline void lpar_xirr_info_set(int n_cpu, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 unsigned long lpar_rc;
128 unsigned long val64 = value & 0xffffffff;
129
130 lpar_rc = plpar_eoi(val64);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200131 if (lpar_rc != H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 panic("bad return code EOI - rc = %ld, value=%lx\n", lpar_rc,
David Gibson007e8f52005-10-28 15:35:50 +1000133 val64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000136static inline void lpar_cppr_info(int n_cpu, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
138 unsigned long lpar_rc;
139
140 lpar_rc = plpar_cppr(value);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200141 if (lpar_rc != H_SUCCESS)
David Gibson007e8f52005-10-28 15:35:50 +1000142 panic("bad return code cppr - rc = %lx\n", lpar_rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000145static inline void lpar_qirr_info(int n_cpu , u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 unsigned long lpar_rc;
148
149 lpar_rc = plpar_ipi(get_hard_smp_processor_id(n_cpu), value);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200150 if (lpar_rc != H_SUCCESS)
David Gibson007e8f52005-10-28 15:35:50 +1000151 panic("bad return code qirr - rc = %lx\n", lpar_rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000155/* High level handlers and init code */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158#ifdef CONFIG_SMP
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000159static int get_irq_server(unsigned int virq, unsigned int strict_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000161 int server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /* For the moment only implement delivery to all cpus or one cpu */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000163 cpumask_t cpumask = irq_desc[virq].affinity;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 cpumask_t tmp = CPU_MASK_NONE;
165
166 if (!distribute_irqs)
167 return default_server;
168
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000169 if (!cpus_equal(cpumask, CPU_MASK_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 cpus_and(tmp, cpu_online_map, cpumask);
171
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000172 server = first_cpu(tmp);
173
174 if (server < NR_CPUS)
175 return get_hard_smp_processor_id(server);
176
177 if (strict_check)
178 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000181 if (cpus_equal(cpu_online_map, cpu_present_map))
182 return default_distrib_server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000184 return default_server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}
186#else
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000187static int get_irq_server(unsigned int virq, unsigned int strict_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 return default_server;
190}
191#endif
192
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000193
194static void xics_unmask_irq(unsigned int virq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
196 unsigned int irq;
197 int call_status;
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000198 int server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000200 pr_debug("xics: unmask virq %d\n", virq);
201
202 irq = (unsigned int)irq_map[virq].hwirq;
203 pr_debug(" -> map to hwirq 0x%x\n", irq);
204 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return;
206
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000207 server = get_irq_server(virq, 0);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server,
210 DEFAULT_PRIORITY);
211 if (call_status != 0) {
Anton Blanchard26370322005-09-12 13:12:11 +1000212 printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_set_xive "
213 "returned %d\n", irq, call_status);
214 printk("set_xive %x, server %x\n", ibm_set_xive, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 return;
216 }
217
218 /* Now unmask the interrupt (often a no-op) */
219 call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq);
220 if (call_status != 0) {
Anton Blanchard26370322005-09-12 13:12:11 +1000221 printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_int_on "
222 "returned %d\n", irq, call_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return;
224 }
225}
226
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000227static void xics_mask_real_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
229 int call_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 if (irq == XICS_IPI)
232 return;
233
234 call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq);
235 if (call_status != 0) {
Anton Blanchard26370322005-09-12 13:12:11 +1000236 printk(KERN_ERR "xics_disable_real_irq: irq=%u: "
237 "ibm_int_off returned %d\n", irq, call_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return;
239 }
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 /* Have to set XIVE to 0xff to be able to remove a slot */
Michal Ostrowski673aeb72006-12-20 07:29:40 -0600242 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq,
243 default_server, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 if (call_status != 0) {
Anton Blanchard26370322005-09-12 13:12:11 +1000245 printk(KERN_ERR "xics_disable_irq: irq=%u: ibm_set_xive(0xff)"
246 " returned %d\n", irq, call_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 return;
248 }
249}
250
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000251static void xics_mask_irq(unsigned int virq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 unsigned int irq;
254
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000255 pr_debug("xics: mask virq %d\n", virq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000257 irq = (unsigned int)irq_map[virq].hwirq;
258 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
259 return;
260 xics_mask_real_irq(irq);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000261}
262
263static unsigned int xics_startup(unsigned int virq)
264{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000265 unsigned int irq;
266
267 /* force a reverse mapping of the interrupt so it gets in the cache */
268 irq = (unsigned int)irq_map[virq].hwirq;
269 irq_radix_revmap(xics_host, irq);
270
271 /* unmask it */
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000272 xics_unmask_irq(virq);
273 return 0;
274}
275
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000276static void xics_eoi_direct(unsigned int virq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 int cpu = smp_processor_id();
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000279 unsigned int irq = (unsigned int)irq_map[virq].hwirq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 iosync();
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000282 direct_xirr_info_set(cpu, (0xff << 24) | irq);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000283}
284
285
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000286static void xics_eoi_lpar(unsigned int virq)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000287{
288 int cpu = smp_processor_id();
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000289 unsigned int irq = (unsigned int)irq_map[virq].hwirq;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000290
291 iosync();
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000292 lpar_xirr_info_set(cpu, (0xff << 24) | irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000295static inline unsigned int xics_remap_irq(unsigned int vec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000297 unsigned int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 vec &= 0x00ffffff;
300
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000301 if (vec == XICS_IRQ_SPURIOUS)
302 return NO_IRQ;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000303 irq = irq_radix_revmap(xics_host, vec);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000304 if (likely(irq != NO_IRQ))
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000305 return irq;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000306
307 printk(KERN_ERR "Interrupt %u (real) is invalid,"
308 " disabling it.\n", vec);
309 xics_mask_real_irq(vec);
310 return NO_IRQ;
311}
312
Olaf Hering35a84c22006-10-07 22:08:26 +1000313static unsigned int xics_get_irq_direct(void)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000314{
315 unsigned int cpu = smp_processor_id();
316
317 return xics_remap_irq(direct_xirr_info_get(cpu));
318}
319
Olaf Hering35a84c22006-10-07 22:08:26 +1000320static unsigned int xics_get_irq_lpar(void)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000321{
322 unsigned int cpu = smp_processor_id();
323
324 return xics_remap_irq(lpar_xirr_info_get(cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
327#ifdef CONFIG_SMP
328
David Howells7d12e782006-10-05 14:55:46 +0100329static irqreturn_t xics_ipi_dispatch(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 WARN_ON(cpu_is_offline(cpu));
332
333 while (xics_ipi_message[cpu].value) {
334 if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION,
335 &xics_ipi_message[cpu].value)) {
336 mb();
David Howells7d12e782006-10-05 14:55:46 +0100337 smp_message_recv(PPC_MSG_CALL_FUNCTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 }
339 if (test_and_clear_bit(PPC_MSG_RESCHEDULE,
340 &xics_ipi_message[cpu].value)) {
341 mb();
David Howells7d12e782006-10-05 14:55:46 +0100342 smp_message_recv(PPC_MSG_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
344#if 0
345 if (test_and_clear_bit(PPC_MSG_MIGRATE_TASK,
346 &xics_ipi_message[cpu].value)) {
347 mb();
David Howells7d12e782006-10-05 14:55:46 +0100348 smp_message_recv(PPC_MSG_MIGRATE_TASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350#endif
Michael Ellermancc532912005-12-04 18:39:43 +1100351#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK,
353 &xics_ipi_message[cpu].value)) {
354 mb();
David Howells7d12e782006-10-05 14:55:46 +0100355 smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357#endif
358 }
359 return IRQ_HANDLED;
360}
361
David Howells7d12e782006-10-05 14:55:46 +0100362static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000363{
364 int cpu = smp_processor_id();
365
366 direct_qirr_info(cpu, 0xff);
367
David Howells7d12e782006-10-05 14:55:46 +0100368 return xics_ipi_dispatch(cpu);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000369}
370
David Howells7d12e782006-10-05 14:55:46 +0100371static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000372{
373 int cpu = smp_processor_id();
374
375 lpar_qirr_info(cpu, 0xff);
376
David Howells7d12e782006-10-05 14:55:46 +0100377 return xics_ipi_dispatch(cpu);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000378}
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380void xics_cause_IPI(int cpu)
381{
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000382 if (firmware_has_feature(FW_FEATURE_LPAR))
383 lpar_qirr_info(cpu, IPI_PRIORITY);
384 else
385 direct_qirr_info(cpu, IPI_PRIORITY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000387
Paul Mackerras6c80a212005-05-06 16:28:56 +1000388#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000390static void xics_set_cpu_priority(int cpu, unsigned char cppr)
391{
392 if (firmware_has_feature(FW_FEATURE_LPAR))
393 lpar_cppr_info(cpu, cppr);
394 else
395 direct_cppr_info(cpu, cppr);
396 iosync();
397}
398
399static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
400{
401 unsigned int irq;
402 int status;
403 int xics_status[2];
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000404 int irq_server;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000405
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000406 irq = (unsigned int)irq_map[virq].hwirq;
407 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000408 return;
409
410 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
411
412 if (status) {
413 printk(KERN_ERR "xics_set_affinity: irq=%u ibm,get-xive "
414 "returns %d\n", irq, status);
415 return;
416 }
417
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000418 /*
419 * For the moment only implement delivery to all cpus or one cpu.
420 * Get current irq_server for the given irq
421 */
422 irq_server = get_irq_server(irq, 1);
423 if (irq_server == -1) {
424 char cpulist[128];
425 cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask);
426 printk(KERN_WARNING "xics_set_affinity: No online cpus in "
427 "the mask %s for irq %d\n", cpulist, virq);
428 return;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000429 }
430
431 status = rtas_call(ibm_set_xive, 3, 1, NULL,
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000432 irq, irq_server, xics_status[1]);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000433
434 if (status) {
435 printk(KERN_ERR "xics_set_affinity: irq=%u ibm,set-xive "
436 "returns %d\n", irq, status);
437 return;
438 }
439}
440
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000441void xics_setup_cpu(void)
442{
443 int cpu = smp_processor_id();
444
445 xics_set_cpu_priority(cpu, 0xff);
446
447 /*
448 * Put the calling processor into the GIQ. This is really only
449 * necessary from a secondary thread as the OF start-cpu interface
450 * performs this function for us on primary threads.
451 *
452 * XXX: undo of teardown on kexec needs this too, as may hotplug
453 */
Haren Myneni81b73dd2006-07-27 14:29:00 -0700454 rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000455 (1UL << interrupt_server_size) - 1 - default_distrib_server, 1);
456}
457
458
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000459static struct irq_chip xics_pic_direct = {
460 .typename = " XICS ",
461 .startup = xics_startup,
462 .mask = xics_mask_irq,
463 .unmask = xics_unmask_irq,
464 .eoi = xics_eoi_direct,
465 .set_affinity = xics_set_affinity
466};
467
468
469static struct irq_chip xics_pic_lpar = {
470 .typename = " XICS ",
471 .startup = xics_startup,
472 .mask = xics_mask_irq,
473 .unmask = xics_unmask_irq,
474 .eoi = xics_eoi_lpar,
475 .set_affinity = xics_set_affinity
476};
477
478
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000479static int xics_host_match(struct irq_host *h, struct device_node *node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000481 /* IBM machines have interrupt parents of various funky types for things
482 * like vdevices, events, etc... The trick we use here is to match
483 * everything here except the legacy 8259 which is compatible "chrp,iic"
Paul Mackerras6c80a212005-05-06 16:28:56 +1000484 */
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000485 return !of_device_is_compatible(node, "chrp,iic");
Paul Mackerras6c80a212005-05-06 16:28:56 +1000486}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000488static int xics_host_map_direct(struct irq_host *h, unsigned int virq,
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700489 irq_hw_number_t hw)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000490{
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700491 pr_debug("xics: map_direct virq %d, hwirq 0x%lx\n", virq, hw);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000492
493 get_irq_desc(virq)->status |= IRQ_LEVEL;
494 set_irq_chip_and_handler(virq, &xics_pic_direct, handle_fasteoi_irq);
495 return 0;
496}
497
498static int xics_host_map_lpar(struct irq_host *h, unsigned int virq,
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700499 irq_hw_number_t hw)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000500{
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700501 pr_debug("xics: map_direct virq %d, hwirq 0x%lx\n", virq, hw);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000502
503 get_irq_desc(virq)->status |= IRQ_LEVEL;
504 set_irq_chip_and_handler(virq, &xics_pic_lpar, handle_fasteoi_irq);
505 return 0;
506}
507
508static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
509 u32 *intspec, unsigned int intsize,
510 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
511
512{
513 /* Current xics implementation translates everything
514 * to level. It is not technically right for MSIs but this
515 * is irrelevant at this point. We might get smarter in the future
516 */
517 *out_hwirq = intspec[0];
518 *out_flags = IRQ_TYPE_LEVEL_LOW;
519
520 return 0;
521}
522
523static struct irq_host_ops xics_host_direct_ops = {
524 .match = xics_host_match,
525 .map = xics_host_map_direct,
526 .xlate = xics_host_xlate,
527};
528
529static struct irq_host_ops xics_host_lpar_ops = {
530 .match = xics_host_match,
531 .map = xics_host_map_lpar,
532 .xlate = xics_host_xlate,
533};
534
535static void __init xics_init_host(void)
536{
537 struct irq_host_ops *ops;
538
539 if (firmware_has_feature(FW_FEATURE_LPAR))
540 ops = &xics_host_lpar_ops;
541 else
542 ops = &xics_host_direct_ops;
543 xics_host = irq_alloc_host(IRQ_HOST_MAP_TREE, 0, ops,
544 XICS_IRQ_SPURIOUS);
545 BUG_ON(xics_host == NULL);
546 irq_set_default_host(xics_host);
547}
548
549static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
550 unsigned long size)
551{
552#ifdef CONFIG_SMP
553 int i;
554
555 /* This may look gross but it's good enough for now, we don't quite
556 * have a hard -> linux processor id matching.
557 */
558 for_each_possible_cpu(i) {
559 if (!cpu_present(i))
560 continue;
561 if (hw_id == get_hard_smp_processor_id(i)) {
562 xics_per_cpu[i] = ioremap(addr, size);
563 return;
564 }
565 }
566#else
567 if (hw_id != 0)
568 return;
569 xics_per_cpu[0] = ioremap(addr, size);
570#endif /* CONFIG_SMP */
571}
572
573static void __init xics_init_one_node(struct device_node *np,
574 unsigned int *indx)
575{
576 unsigned int ilen;
Jeremy Kerr954a46e2006-07-12 15:39:43 +1000577 const u32 *ireg;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000578
579 /* This code does the theorically broken assumption that the interrupt
580 * server numbers are the same as the hard CPU numbers.
581 * This happens to be the case so far but we are playing with fire...
582 * should be fixed one of these days. -BenH.
583 */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000584 ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000585
586 /* Do that ever happen ? we'll know soon enough... but even good'old
587 * f80 does have that property ..
588 */
589 WARN_ON(ireg == NULL);
590 if (ireg) {
591 /*
592 * set node starting index for this node
593 */
594 *indx = *ireg;
595 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000596 ireg = of_get_property(np, "reg", &ilen);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000597 if (!ireg)
598 panic("xics_init_IRQ: can't find interrupt reg property");
599
600 while (ilen >= (4 * sizeof(u32))) {
601 unsigned long addr, size;
602
603 /* XXX Use proper OF parsing code here !!! */
604 addr = (unsigned long)*ireg++ << 32;
605 ilen -= sizeof(u32);
606 addr |= *ireg++;
607 ilen -= sizeof(u32);
608 size = (unsigned long)*ireg++ << 32;
609 ilen -= sizeof(u32);
610 size |= *ireg++;
611 ilen -= sizeof(u32);
612 xics_map_one_cpu(*indx, addr, size);
613 (*indx)++;
614 }
615}
616
617
618static void __init xics_setup_8259_cascade(void)
619{
620 struct device_node *np, *old, *found = NULL;
621 int cascade, naddr;
Jeremy Kerr954a46e2006-07-12 15:39:43 +1000622 const u32 *addrp;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000623 unsigned long intack = 0;
624
625 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000626 if (of_device_is_compatible(np, "chrp,iic")) {
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000627 found = np;
628 break;
629 }
630 if (found == NULL) {
631 printk(KERN_DEBUG "xics: no ISA interrupt controller\n");
632 return;
633 }
634 cascade = irq_of_parse_and_map(found, 0);
635 if (cascade == NO_IRQ) {
636 printk(KERN_ERR "xics: failed to map cascade interrupt");
637 return;
638 }
639 pr_debug("xics: cascade mapped to irq %d\n", cascade);
640
641 for (old = of_node_get(found); old != NULL ; old = np) {
642 np = of_get_parent(old);
643 of_node_put(old);
644 if (np == NULL)
645 break;
646 if (strcmp(np->name, "pci") != 0)
647 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000648 addrp = of_get_property(np, "8259-interrupt-acknowledge", NULL);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000649 if (addrp == NULL)
650 continue;
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000651 naddr = of_n_addr_cells(np);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000652 intack = addrp[naddr-1];
653 if (naddr > 1)
654 intack |= ((unsigned long)addrp[naddr-2]) << 32;
655 }
656 if (intack)
657 printk(KERN_DEBUG "xics: PCI 8259 intack at 0x%016lx\n", intack);
658 i8259_init(found, intack);
659 of_node_put(found);
660 set_irq_chained_handler(cascade, pseries_8259_cascade);
661}
662
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530663static struct device_node *cpuid_to_of_node(int cpu)
664{
665 struct device_node *np;
666 u32 hcpuid = get_hard_smp_processor_id(cpu);
667
668 for_each_node_by_type(np, "cpu") {
669 int i, len;
670 const u32 *intserv;
671
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000672 intserv = of_get_property(np, "ibm,ppc-interrupt-server#s",
673 &len);
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530674
675 if (!intserv)
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000676 intserv = of_get_property(np, "reg", &len);
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530677
678 i = len / sizeof(u32);
679
680 while (i--)
681 if (intserv[i] == hcpuid)
682 return np;
683 }
684
685 return NULL;
686}
687
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000688void __init xics_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530690 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 struct device_node *np;
Jeremy Kerr954a46e2006-07-12 15:39:43 +1000692 u32 ilen, indx = 0;
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530693 const u32 *ireg, *isize;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000694 int found = 0;
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530695 u32 hcpuid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
697 ppc64_boot_msg(0x20, "XICS Init");
698
699 ibm_get_xive = rtas_token("ibm,get-xive");
700 ibm_set_xive = rtas_token("ibm,set-xive");
701 ibm_int_on = rtas_token("ibm,int-on");
702 ibm_int_off = rtas_token("ibm,int-off");
703
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000704 for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
705 found = 1;
706 if (firmware_has_feature(FW_FEATURE_LPAR))
707 break;
708 xics_init_one_node(np, &indx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000710 if (found == 0)
711 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000713 xics_init_host();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 /* Find the server numbers for the boot cpu. */
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530716 np = cpuid_to_of_node(boot_cpuid);
717 BUG_ON(!np);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000718 ireg = of_get_property(np, "ibm,ppc-interrupt-gserver#s", &ilen);
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530719 if (!ireg)
720 goto skip_gserver_check;
721 i = ilen / sizeof(int);
722 hcpuid = get_hard_smp_processor_id(boot_cpuid);
723
724 /* Global interrupt distribution server is specified in the last
725 * entry of "ibm,ppc-interrupt-gserver#s" property. Get the last
726 * entry fom this property for current boot cpu id and use it as
727 * default distribution server
728 */
729 for (j = 0; j < i; j += 2) {
730 if (ireg[j] == hcpuid) {
731 default_server = hcpuid;
732 default_distrib_server = ireg[j+1];
733
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000734 isize = of_get_property(np,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 "ibm,interrupt-server#-size", NULL);
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530736 if (isize)
737 interrupt_server_size = *isize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739 }
Mohan Kumar Ma5715d62006-11-17 17:42:24 +0530740skip_gserver_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 of_node_put(np);
742
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000743 if (firmware_has_feature(FW_FEATURE_LPAR))
744 ppc_md.get_irq = xics_get_irq_lpar;
745 else
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000746 ppc_md.get_irq = xics_get_irq_direct;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Paul Mackerras6c80a212005-05-06 16:28:56 +1000748 xics_setup_cpu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000750 xics_setup_8259_cascade();
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 ppc64_boot_msg(0x21, "XICS Done");
753}
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756#ifdef CONFIG_SMP
757void xics_request_IPIs(void)
758{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000759 unsigned int ipi;
Michael Neuling66b30922007-05-29 17:01:52 +1000760 int rc;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000761
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700762 ipi = irq_create_mapping(xics_host, XICS_IPI);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000763 BUG_ON(ipi == NO_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Thomas Gleixner67144652006-07-01 19:29:22 -0700765 /*
766 * IPIs are marked IRQF_DISABLED as they must run with irqs
767 * disabled
768 */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000769 set_irq_handler(ipi, handle_percpu_irq);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000770 if (firmware_has_feature(FW_FEATURE_LPAR))
Michael Neuling66b30922007-05-29 17:01:52 +1000771 rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED,
772 "IPI", NULL);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000773 else
Michael Neuling66b30922007-05-29 17:01:52 +1000774 rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED,
775 "IPI", NULL);
776 BUG_ON(rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000778#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Paul Mackerras6d22d852005-08-04 12:53:37 -0700780void xics_teardown_cpu(int secondary)
R Sharadafce0d572005-06-25 14:58:10 -0700781{
782 int cpu = smp_processor_id();
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000783 unsigned int ipi;
784 struct irq_desc *desc;
R Sharadafce0d572005-06-25 14:58:10 -0700785
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000786 xics_set_cpu_priority(cpu, 0);
Haren Myneni81bbbe92006-04-05 21:10:18 -0600787
788 /*
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700789 * Clear IPI
790 */
791 if (firmware_has_feature(FW_FEATURE_LPAR))
792 lpar_qirr_info(cpu, 0xff);
793 else
794 direct_qirr_info(cpu, 0xff);
795
796 /*
Haren Myneni81bbbe92006-04-05 21:10:18 -0600797 * we need to EOI the IPI if we got here from kexec down IPI
798 *
799 * probably need to check all the other interrupts too
800 * should we be flagging idle loop instead?
801 * or creating some task to be scheduled?
802 */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000803
804 ipi = irq_find_mapping(xics_host, XICS_IPI);
805 if (ipi == XICS_IRQ_SPURIOUS)
806 return;
807 desc = get_irq_desc(ipi);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000808 if (desc->chip && desc->chip->eoi)
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700809 desc->chip->eoi(ipi);
Haren Myneni81bbbe92006-04-05 21:10:18 -0600810
R Sharadafce0d572005-06-25 14:58:10 -0700811 /*
Paul Mackerras6d22d852005-08-04 12:53:37 -0700812 * Some machines need to have at least one cpu in the GIQ,
813 * so leave the master cpu in the group.
R Sharadafce0d572005-06-25 14:58:10 -0700814 */
Haren Myneni81bbbe92006-04-05 21:10:18 -0600815 if (secondary)
Haren Myneni81b73dd2006-07-27 14:29:00 -0700816 rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000817 (1UL << interrupt_server_size) - 1 -
818 default_distrib_server, 0);
R Sharadafce0d572005-06-25 14:58:10 -0700819}
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821#ifdef CONFIG_HOTPLUG_CPU
822
823/* Interrupts are disabled. */
824void xics_migrate_irqs_away(void)
825{
826 int status;
827 unsigned int irq, virq, cpu = smp_processor_id();
828
829 /* Reject any interrupt that was queued to us... */
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000830 xics_set_cpu_priority(cpu, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 /* remove ourselves from the global interrupt queue */
Haren Myneni81b73dd2006-07-27 14:29:00 -0700833 status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 (1UL << interrupt_server_size) - 1 - default_distrib_server, 0);
835 WARN_ON(status < 0);
836
837 /* Allow IPIs again... */
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000838 xics_set_cpu_priority(cpu, DEFAULT_PRIORITY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 for_each_irq(virq) {
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000841 struct irq_desc *desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 int xics_status[2];
843 unsigned long flags;
844
845 /* We cant set affinity on ISA interrupts */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000846 if (virq < NUM_ISA_INTERRUPTS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 continue;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000848 if (irq_map[virq].host != xics_host)
849 continue;
850 irq = (unsigned int)irq_map[virq].hwirq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 /* We need to get IPIs still. */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000852 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 continue;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000854 desc = get_irq_desc(virq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
856 /* We only need to migrate enabled IRQS */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700857 if (desc == NULL || desc->chip == NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 || desc->action == NULL
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700859 || desc->chip->set_affinity == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 continue;
861
862 spin_lock_irqsave(&desc->lock, flags);
863
864 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
865 if (status) {
Anton Blanchard26370322005-09-12 13:12:11 +1000866 printk(KERN_ERR "migrate_irqs_away: irq=%u "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 "ibm,get-xive returns %d\n",
868 virq, status);
869 goto unlock;
870 }
871
872 /*
873 * We only support delivery to all cpus or to one cpu.
874 * The irq has to be migrated only in the single cpu
875 * case.
876 */
877 if (xics_status[0] != get_hard_smp_processor_id(cpu))
878 goto unlock;
879
Anton Blanchard26370322005-09-12 13:12:11 +1000880 printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 virq, cpu);
882
883 /* Reset affinity to all cpus */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700884 desc->chip->set_affinity(virq, CPU_MASK_ALL);
Ingo Molnara53da522006-06-29 02:24:38 -0700885 irq_desc[irq].affinity = CPU_MASK_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886unlock:
887 spin_unlock_irqrestore(&desc->lock, flags);
888 }
889}
890#endif