blob: ca52b587166d950856f36bb4102aba8cb0f466e1 [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
Milton Millerd7cf0ed2007-12-14 15:52:09 +110090static inline unsigned int direct_xirr_info_get(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Milton Millerd7cf0ed2007-12-14 15:52:09 +110092 int cpu = smp_processor_id();
93
94 return in_be32(&xics_per_cpu[cpu]->xirr.word);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Milton Millerd7cf0ed2007-12-14 15:52:09 +110097static inline void direct_xirr_info_set(int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Milton Millerd7cf0ed2007-12-14 15:52:09 +110099 int cpu = smp_processor_id();
100
101 out_be32(&xics_per_cpu[cpu]->xirr.word, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100104static inline void direct_cppr_info(u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100106 int cpu = smp_processor_id();
107
108 out_8(&xics_per_cpu[cpu]->xirr.bytes[0], value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000111static inline void direct_qirr_info(int n_cpu, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 out_8(&xics_per_cpu[n_cpu]->qirr.bytes[0], value);
114}
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000117/* LPAR low level accessors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100120static inline unsigned int lpar_xirr_info_get(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 unsigned long lpar_rc;
David Gibson007e8f52005-10-28 15:35:50 +1000123 unsigned long return_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 lpar_rc = plpar_xirr(&return_value);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200126 if (lpar_rc != H_SUCCESS)
David Gibson007e8f52005-10-28 15:35:50 +1000127 panic(" bad return code xirr - rc = %lx \n", lpar_rc);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000128 return (unsigned int)return_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100131static inline void lpar_xirr_info_set(int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 unsigned long lpar_rc;
134 unsigned long val64 = value & 0xffffffff;
135
136 lpar_rc = plpar_eoi(val64);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200137 if (lpar_rc != H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 panic("bad return code EOI - rc = %ld, value=%lx\n", lpar_rc,
David Gibson007e8f52005-10-28 15:35:50 +1000139 val64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100142static inline void lpar_cppr_info(u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
144 unsigned long lpar_rc;
145
146 lpar_rc = plpar_cppr(value);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200147 if (lpar_rc != H_SUCCESS)
David Gibson007e8f52005-10-28 15:35:50 +1000148 panic("bad return code cppr - rc = %lx\n", lpar_rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000151static inline void lpar_qirr_info(int n_cpu , u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 unsigned long lpar_rc;
154
155 lpar_rc = plpar_ipi(get_hard_smp_processor_id(n_cpu), value);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200156 if (lpar_rc != H_SUCCESS)
David Gibson007e8f52005-10-28 15:35:50 +1000157 panic("bad return code qirr - rc = %lx\n", lpar_rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000161/* High level handlers and init code */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Nathan Fontenotde0723d2008-02-07 07:37:40 +1100163static void xics_update_irq_servers(void)
164{
165 int i, j;
166 struct device_node *np;
167 u32 ilen;
168 const u32 *ireg, *isize;
169 u32 hcpuid;
170
171 /* Find the server numbers for the boot cpu. */
172 np = of_get_cpu_node(boot_cpuid, NULL);
173 BUG_ON(!np);
174
175 ireg = of_get_property(np, "ibm,ppc-interrupt-gserver#s", &ilen);
176 if (!ireg) {
177 of_node_put(np);
178 return;
179 }
180
181 i = ilen / sizeof(int);
182 hcpuid = get_hard_smp_processor_id(boot_cpuid);
183
184 /* Global interrupt distribution server is specified in the last
185 * entry of "ibm,ppc-interrupt-gserver#s" property. Get the last
186 * entry fom this property for current boot cpu id and use it as
187 * default distribution server
188 */
189 for (j = 0; j < i; j += 2) {
190 if (ireg[j] == hcpuid) {
191 default_server = hcpuid;
192 default_distrib_server = ireg[j+1];
193
194 isize = of_get_property(np,
195 "ibm,interrupt-server#-size", NULL);
196 if (isize)
197 interrupt_server_size = *isize;
198 }
199 }
200
201 of_node_put(np);
202}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204#ifdef CONFIG_SMP
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000205static int get_irq_server(unsigned int virq, unsigned int strict_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000207 int server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 /* For the moment only implement delivery to all cpus or one cpu */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000209 cpumask_t cpumask = irq_desc[virq].affinity;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 cpumask_t tmp = CPU_MASK_NONE;
211
Nathan Fontenotde0723d2008-02-07 07:37:40 +1100212 if (! cpu_isset(default_server, cpu_online_map))
213 xics_update_irq_servers();
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 if (!distribute_irqs)
216 return default_server;
217
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000218 if (!cpus_equal(cpumask, CPU_MASK_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 cpus_and(tmp, cpu_online_map, cpumask);
220
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000221 server = first_cpu(tmp);
222
223 if (server < NR_CPUS)
224 return get_hard_smp_processor_id(server);
225
226 if (strict_check)
227 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000230 if (cpus_equal(cpu_online_map, cpu_present_map))
231 return default_distrib_server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000233 return default_server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235#else
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000236static int get_irq_server(unsigned int virq, unsigned int strict_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 return default_server;
239}
240#endif
241
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000242
243static void xics_unmask_irq(unsigned int virq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 unsigned int irq;
246 int call_status;
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000247 int server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000249 pr_debug("xics: unmask virq %d\n", virq);
250
251 irq = (unsigned int)irq_map[virq].hwirq;
252 pr_debug(" -> map to hwirq 0x%x\n", irq);
253 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return;
255
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000256 server = get_irq_server(virq, 0);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server,
259 DEFAULT_PRIORITY);
260 if (call_status != 0) {
Anton Blanchard26370322005-09-12 13:12:11 +1000261 printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_set_xive "
262 "returned %d\n", irq, call_status);
263 printk("set_xive %x, server %x\n", ibm_set_xive, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return;
265 }
266
267 /* Now unmask the interrupt (often a no-op) */
268 call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq);
269 if (call_status != 0) {
Anton Blanchard26370322005-09-12 13:12:11 +1000270 printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_int_on "
271 "returned %d\n", irq, call_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 return;
273 }
274}
275
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000276static void xics_mask_real_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 int call_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 if (irq == XICS_IPI)
281 return;
282
283 call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq);
284 if (call_status != 0) {
Anton Blanchard26370322005-09-12 13:12:11 +1000285 printk(KERN_ERR "xics_disable_real_irq: irq=%u: "
286 "ibm_int_off returned %d\n", irq, call_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 return;
288 }
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 /* Have to set XIVE to 0xff to be able to remove a slot */
Michal Ostrowski673aeb72006-12-20 07:29:40 -0600291 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq,
292 default_server, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (call_status != 0) {
Anton Blanchard26370322005-09-12 13:12:11 +1000294 printk(KERN_ERR "xics_disable_irq: irq=%u: ibm_set_xive(0xff)"
295 " returned %d\n", irq, call_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 return;
297 }
298}
299
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000300static void xics_mask_irq(unsigned int virq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 unsigned int irq;
303
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000304 pr_debug("xics: mask virq %d\n", virq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000306 irq = (unsigned int)irq_map[virq].hwirq;
307 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
308 return;
309 xics_mask_real_irq(irq);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000310}
311
312static unsigned int xics_startup(unsigned int virq)
313{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000314 unsigned int irq;
315
316 /* force a reverse mapping of the interrupt so it gets in the cache */
317 irq = (unsigned int)irq_map[virq].hwirq;
318 irq_radix_revmap(xics_host, irq);
319
320 /* unmask it */
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000321 xics_unmask_irq(virq);
322 return 0;
323}
324
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000325static void xics_eoi_direct(unsigned int virq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000327 unsigned int irq = (unsigned int)irq_map[virq].hwirq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 iosync();
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100330 direct_xirr_info_set((0xff << 24) | irq);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000331}
332
333
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000334static void xics_eoi_lpar(unsigned int virq)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000335{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000336 unsigned int irq = (unsigned int)irq_map[virq].hwirq;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000337
338 iosync();
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100339 lpar_xirr_info_set((0xff << 24) | irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000342static inline unsigned int xics_remap_irq(unsigned int vec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000344 unsigned int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 vec &= 0x00ffffff;
347
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000348 if (vec == XICS_IRQ_SPURIOUS)
349 return NO_IRQ;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000350 irq = irq_radix_revmap(xics_host, vec);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000351 if (likely(irq != NO_IRQ))
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000352 return irq;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000353
354 printk(KERN_ERR "Interrupt %u (real) is invalid,"
355 " disabling it.\n", vec);
356 xics_mask_real_irq(vec);
357 return NO_IRQ;
358}
359
Olaf Hering35a84c22006-10-07 22:08:26 +1000360static unsigned int xics_get_irq_direct(void)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000361{
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100362 return xics_remap_irq(direct_xirr_info_get());
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000363}
364
Olaf Hering35a84c22006-10-07 22:08:26 +1000365static unsigned int xics_get_irq_lpar(void)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000366{
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100367 return xics_remap_irq(lpar_xirr_info_get());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370#ifdef CONFIG_SMP
371
David Howells7d12e782006-10-05 14:55:46 +0100372static irqreturn_t xics_ipi_dispatch(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 WARN_ON(cpu_is_offline(cpu));
375
376 while (xics_ipi_message[cpu].value) {
377 if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION,
378 &xics_ipi_message[cpu].value)) {
379 mb();
David Howells7d12e782006-10-05 14:55:46 +0100380 smp_message_recv(PPC_MSG_CALL_FUNCTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
382 if (test_and_clear_bit(PPC_MSG_RESCHEDULE,
383 &xics_ipi_message[cpu].value)) {
384 mb();
David Howells7d12e782006-10-05 14:55:46 +0100385 smp_message_recv(PPC_MSG_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
387#if 0
388 if (test_and_clear_bit(PPC_MSG_MIGRATE_TASK,
389 &xics_ipi_message[cpu].value)) {
390 mb();
David Howells7d12e782006-10-05 14:55:46 +0100391 smp_message_recv(PPC_MSG_MIGRATE_TASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
393#endif
Michael Ellermancc532912005-12-04 18:39:43 +1100394#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK,
396 &xics_ipi_message[cpu].value)) {
397 mb();
David Howells7d12e782006-10-05 14:55:46 +0100398 smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
400#endif
401 }
402 return IRQ_HANDLED;
403}
404
David Howells7d12e782006-10-05 14:55:46 +0100405static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000406{
407 int cpu = smp_processor_id();
408
409 direct_qirr_info(cpu, 0xff);
410
David Howells7d12e782006-10-05 14:55:46 +0100411 return xics_ipi_dispatch(cpu);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000412}
413
David Howells7d12e782006-10-05 14:55:46 +0100414static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000415{
416 int cpu = smp_processor_id();
417
418 lpar_qirr_info(cpu, 0xff);
419
David Howells7d12e782006-10-05 14:55:46 +0100420 return xics_ipi_dispatch(cpu);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000421}
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423void xics_cause_IPI(int cpu)
424{
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000425 if (firmware_has_feature(FW_FEATURE_LPAR))
426 lpar_qirr_info(cpu, IPI_PRIORITY);
427 else
428 direct_qirr_info(cpu, IPI_PRIORITY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000430
Paul Mackerras6c80a212005-05-06 16:28:56 +1000431#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100433static void xics_set_cpu_priority(unsigned char cppr)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000434{
435 if (firmware_has_feature(FW_FEATURE_LPAR))
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100436 lpar_cppr_info(cppr);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000437 else
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100438 direct_cppr_info(cppr);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000439 iosync();
440}
441
442static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
443{
444 unsigned int irq;
445 int status;
446 int xics_status[2];
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000447 int irq_server;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000448
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000449 irq = (unsigned int)irq_map[virq].hwirq;
450 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000451 return;
452
453 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
454
455 if (status) {
456 printk(KERN_ERR "xics_set_affinity: irq=%u ibm,get-xive "
457 "returns %d\n", irq, status);
458 return;
459 }
460
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000461 /*
462 * For the moment only implement delivery to all cpus or one cpu.
463 * Get current irq_server for the given irq
464 */
Anton Blancharde48395f2007-10-01 07:45:55 +1000465 irq_server = get_irq_server(virq, 1);
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000466 if (irq_server == -1) {
467 char cpulist[128];
468 cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask);
469 printk(KERN_WARNING "xics_set_affinity: No online cpus in "
470 "the mask %s for irq %d\n", cpulist, virq);
471 return;
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000472 }
473
474 status = rtas_call(ibm_set_xive, 3, 1, NULL,
Mohan Kumar M7ccb4a62007-06-13 00:51:57 +1000475 irq, irq_server, xics_status[1]);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000476
477 if (status) {
478 printk(KERN_ERR "xics_set_affinity: irq=%u ibm,set-xive "
479 "returns %d\n", irq, status);
480 return;
481 }
482}
483
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000484void xics_setup_cpu(void)
485{
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100486 xics_set_cpu_priority(0xff);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000487
488 /*
489 * Put the calling processor into the GIQ. This is really only
490 * necessary from a secondary thread as the OF start-cpu interface
491 * performs this function for us on primary threads.
492 *
493 * XXX: undo of teardown on kexec needs this too, as may hotplug
494 */
Haren Myneni81b73dd2006-07-27 14:29:00 -0700495 rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000496 (1UL << interrupt_server_size) - 1 - default_distrib_server, 1);
497}
498
499
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000500static struct irq_chip xics_pic_direct = {
501 .typename = " XICS ",
502 .startup = xics_startup,
503 .mask = xics_mask_irq,
504 .unmask = xics_unmask_irq,
505 .eoi = xics_eoi_direct,
506 .set_affinity = xics_set_affinity
507};
508
509
510static struct irq_chip xics_pic_lpar = {
511 .typename = " XICS ",
512 .startup = xics_startup,
513 .mask = xics_mask_irq,
514 .unmask = xics_unmask_irq,
515 .eoi = xics_eoi_lpar,
516 .set_affinity = xics_set_affinity
517};
518
519
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000520static int xics_host_match(struct irq_host *h, struct device_node *node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000522 /* IBM machines have interrupt parents of various funky types for things
523 * like vdevices, events, etc... The trick we use here is to match
524 * everything here except the legacy 8259 which is compatible "chrp,iic"
Paul Mackerras6c80a212005-05-06 16:28:56 +1000525 */
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000526 return !of_device_is_compatible(node, "chrp,iic");
Paul Mackerras6c80a212005-05-06 16:28:56 +1000527}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000529static int xics_host_map_direct(struct irq_host *h, unsigned int virq,
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700530 irq_hw_number_t hw)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000531{
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700532 pr_debug("xics: map_direct virq %d, hwirq 0x%lx\n", virq, hw);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000533
534 get_irq_desc(virq)->status |= IRQ_LEVEL;
535 set_irq_chip_and_handler(virq, &xics_pic_direct, handle_fasteoi_irq);
536 return 0;
537}
538
539static int xics_host_map_lpar(struct irq_host *h, unsigned int virq,
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700540 irq_hw_number_t hw)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000541{
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700542 pr_debug("xics: map_direct virq %d, hwirq 0x%lx\n", virq, hw);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000543
544 get_irq_desc(virq)->status |= IRQ_LEVEL;
545 set_irq_chip_and_handler(virq, &xics_pic_lpar, handle_fasteoi_irq);
546 return 0;
547}
548
549static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
550 u32 *intspec, unsigned int intsize,
551 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
552
553{
554 /* Current xics implementation translates everything
555 * to level. It is not technically right for MSIs but this
556 * is irrelevant at this point. We might get smarter in the future
557 */
558 *out_hwirq = intspec[0];
559 *out_flags = IRQ_TYPE_LEVEL_LOW;
560
561 return 0;
562}
563
564static struct irq_host_ops xics_host_direct_ops = {
565 .match = xics_host_match,
566 .map = xics_host_map_direct,
567 .xlate = xics_host_xlate,
568};
569
570static struct irq_host_ops xics_host_lpar_ops = {
571 .match = xics_host_match,
572 .map = xics_host_map_lpar,
573 .xlate = xics_host_xlate,
574};
575
576static void __init xics_init_host(void)
577{
578 struct irq_host_ops *ops;
579
580 if (firmware_has_feature(FW_FEATURE_LPAR))
581 ops = &xics_host_lpar_ops;
582 else
583 ops = &xics_host_direct_ops;
Michael Ellerman52964f82007-08-28 18:47:54 +1000584 xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, ops,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000585 XICS_IRQ_SPURIOUS);
586 BUG_ON(xics_host == NULL);
587 irq_set_default_host(xics_host);
588}
589
590static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
591 unsigned long size)
592{
593#ifdef CONFIG_SMP
594 int i;
595
596 /* This may look gross but it's good enough for now, we don't quite
597 * have a hard -> linux processor id matching.
598 */
599 for_each_possible_cpu(i) {
600 if (!cpu_present(i))
601 continue;
602 if (hw_id == get_hard_smp_processor_id(i)) {
603 xics_per_cpu[i] = ioremap(addr, size);
604 return;
605 }
606 }
607#else
608 if (hw_id != 0)
609 return;
610 xics_per_cpu[0] = ioremap(addr, size);
611#endif /* CONFIG_SMP */
612}
613
614static void __init xics_init_one_node(struct device_node *np,
615 unsigned int *indx)
616{
617 unsigned int ilen;
Jeremy Kerr954a46e2006-07-12 15:39:43 +1000618 const u32 *ireg;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000619
620 /* This code does the theorically broken assumption that the interrupt
621 * server numbers are the same as the hard CPU numbers.
622 * This happens to be the case so far but we are playing with fire...
623 * should be fixed one of these days. -BenH.
624 */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000625 ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000626
627 /* Do that ever happen ? we'll know soon enough... but even good'old
628 * f80 does have that property ..
629 */
630 WARN_ON(ireg == NULL);
631 if (ireg) {
632 /*
633 * set node starting index for this node
634 */
635 *indx = *ireg;
636 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000637 ireg = of_get_property(np, "reg", &ilen);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000638 if (!ireg)
639 panic("xics_init_IRQ: can't find interrupt reg property");
640
641 while (ilen >= (4 * sizeof(u32))) {
642 unsigned long addr, size;
643
644 /* XXX Use proper OF parsing code here !!! */
645 addr = (unsigned long)*ireg++ << 32;
646 ilen -= sizeof(u32);
647 addr |= *ireg++;
648 ilen -= sizeof(u32);
649 size = (unsigned long)*ireg++ << 32;
650 ilen -= sizeof(u32);
651 size |= *ireg++;
652 ilen -= sizeof(u32);
653 xics_map_one_cpu(*indx, addr, size);
654 (*indx)++;
655 }
656}
657
658
659static void __init xics_setup_8259_cascade(void)
660{
661 struct device_node *np, *old, *found = NULL;
662 int cascade, naddr;
Jeremy Kerr954a46e2006-07-12 15:39:43 +1000663 const u32 *addrp;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000664 unsigned long intack = 0;
665
666 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000667 if (of_device_is_compatible(np, "chrp,iic")) {
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000668 found = np;
669 break;
670 }
671 if (found == NULL) {
672 printk(KERN_DEBUG "xics: no ISA interrupt controller\n");
673 return;
674 }
675 cascade = irq_of_parse_and_map(found, 0);
676 if (cascade == NO_IRQ) {
677 printk(KERN_ERR "xics: failed to map cascade interrupt");
678 return;
679 }
680 pr_debug("xics: cascade mapped to irq %d\n", cascade);
681
682 for (old = of_node_get(found); old != NULL ; old = np) {
683 np = of_get_parent(old);
684 of_node_put(old);
685 if (np == NULL)
686 break;
687 if (strcmp(np->name, "pci") != 0)
688 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000689 addrp = of_get_property(np, "8259-interrupt-acknowledge", NULL);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000690 if (addrp == NULL)
691 continue;
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000692 naddr = of_n_addr_cells(np);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000693 intack = addrp[naddr-1];
694 if (naddr > 1)
695 intack |= ((unsigned long)addrp[naddr-2]) << 32;
696 }
697 if (intack)
698 printk(KERN_DEBUG "xics: PCI 8259 intack at 0x%016lx\n", intack);
699 i8259_init(found, intack);
700 of_node_put(found);
701 set_irq_chained_handler(cascade, pseries_8259_cascade);
702}
703
704void __init xics_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 struct device_node *np;
Nathan Fontenotde0723d2008-02-07 07:37:40 +1100707 u32 indx = 0;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000708 int found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 ppc64_boot_msg(0x20, "XICS Init");
711
712 ibm_get_xive = rtas_token("ibm,get-xive");
713 ibm_set_xive = rtas_token("ibm,set-xive");
714 ibm_int_on = rtas_token("ibm,int-on");
715 ibm_int_off = rtas_token("ibm,int-off");
716
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000717 for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
718 found = 1;
719 if (firmware_has_feature(FW_FEATURE_LPAR))
720 break;
721 xics_init_one_node(np, &indx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000723 if (found == 0)
724 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000726 xics_init_host();
Nathan Fontenotde0723d2008-02-07 07:37:40 +1100727 xics_update_irq_servers();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000729 if (firmware_has_feature(FW_FEATURE_LPAR))
730 ppc_md.get_irq = xics_get_irq_lpar;
731 else
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000732 ppc_md.get_irq = xics_get_irq_direct;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Paul Mackerras6c80a212005-05-06 16:28:56 +1000734 xics_setup_cpu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000736 xics_setup_8259_cascade();
737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 ppc64_boot_msg(0x21, "XICS Done");
739}
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742#ifdef CONFIG_SMP
743void xics_request_IPIs(void)
744{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000745 unsigned int ipi;
Michael Neuling66b30922007-05-29 17:01:52 +1000746 int rc;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000747
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700748 ipi = irq_create_mapping(xics_host, XICS_IPI);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000749 BUG_ON(ipi == NO_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Thomas Gleixner67144652006-07-01 19:29:22 -0700751 /*
752 * IPIs are marked IRQF_DISABLED as they must run with irqs
753 * disabled
754 */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000755 set_irq_handler(ipi, handle_percpu_irq);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000756 if (firmware_has_feature(FW_FEATURE_LPAR))
Michael Neuling66b30922007-05-29 17:01:52 +1000757 rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED,
758 "IPI", NULL);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000759 else
Michael Neuling66b30922007-05-29 17:01:52 +1000760 rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED,
761 "IPI", NULL);
762 BUG_ON(rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000764#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Nathan Fontenotc3e85062008-02-07 07:37:31 +1100766void xics_teardown_cpu()
R Sharadafce0d572005-06-25 14:58:10 -0700767{
768 int cpu = smp_processor_id();
R Sharadafce0d572005-06-25 14:58:10 -0700769
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100770 xics_set_cpu_priority(0);
Haren Myneni81bbbe92006-04-05 21:10:18 -0600771
772 /*
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700773 * Clear IPI
774 */
775 if (firmware_has_feature(FW_FEATURE_LPAR))
776 lpar_qirr_info(cpu, 0xff);
777 else
778 direct_qirr_info(cpu, 0xff);
Nathan Fontenotc3e85062008-02-07 07:37:31 +1100779}
780
781void xics_kexec_teardown_cpu(int secondary)
782{
783 unsigned int ipi;
784 struct irq_desc *desc;
785
786 xics_teardown_cpu();
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700787
788 /*
Nathan Fontenotc3e85062008-02-07 07:37:31 +1100789 * we need to EOI the IPI
Haren Myneni81bbbe92006-04-05 21:10:18 -0600790 *
791 * probably need to check all the other interrupts too
792 * should we be flagging idle loop instead?
793 * or creating some task to be scheduled?
794 */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000795
796 ipi = irq_find_mapping(xics_host, XICS_IPI);
797 if (ipi == XICS_IRQ_SPURIOUS)
798 return;
799 desc = get_irq_desc(ipi);
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000800 if (desc->chip && desc->chip->eoi)
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700801 desc->chip->eoi(ipi);
Haren Myneni81bbbe92006-04-05 21:10:18 -0600802
R Sharadafce0d572005-06-25 14:58:10 -0700803 /*
Paul Mackerras6d22d852005-08-04 12:53:37 -0700804 * Some machines need to have at least one cpu in the GIQ,
805 * so leave the master cpu in the group.
R Sharadafce0d572005-06-25 14:58:10 -0700806 */
Haren Myneni81bbbe92006-04-05 21:10:18 -0600807 if (secondary)
Haren Myneni81b73dd2006-07-27 14:29:00 -0700808 rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000809 (1UL << interrupt_server_size) - 1 -
810 default_distrib_server, 0);
R Sharadafce0d572005-06-25 14:58:10 -0700811}
812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813#ifdef CONFIG_HOTPLUG_CPU
814
815/* Interrupts are disabled. */
816void xics_migrate_irqs_away(void)
817{
818 int status;
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100819 int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
820 unsigned int irq, virq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 /* Reject any interrupt that was queued to us... */
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100823 xics_set_cpu_priority(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 /* remove ourselves from the global interrupt queue */
Haren Myneni81b73dd2006-07-27 14:29:00 -0700826 status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 (1UL << interrupt_server_size) - 1 - default_distrib_server, 0);
828 WARN_ON(status < 0);
829
830 /* Allow IPIs again... */
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100831 xics_set_cpu_priority(DEFAULT_PRIORITY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 for_each_irq(virq) {
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000834 struct irq_desc *desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 int xics_status[2];
836 unsigned long flags;
837
838 /* We cant set affinity on ISA interrupts */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000839 if (virq < NUM_ISA_INTERRUPTS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 continue;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000841 if (irq_map[virq].host != xics_host)
842 continue;
843 irq = (unsigned int)irq_map[virq].hwirq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 /* We need to get IPIs still. */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000845 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 continue;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000847 desc = get_irq_desc(virq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 /* We only need to migrate enabled IRQS */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700850 if (desc == NULL || desc->chip == NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 || desc->action == NULL
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700852 || desc->chip->set_affinity == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 continue;
854
855 spin_lock_irqsave(&desc->lock, flags);
856
857 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
858 if (status) {
Anton Blanchard26370322005-09-12 13:12:11 +1000859 printk(KERN_ERR "migrate_irqs_away: irq=%u "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 "ibm,get-xive returns %d\n",
861 virq, status);
862 goto unlock;
863 }
864
865 /*
866 * We only support delivery to all cpus or to one cpu.
867 * The irq has to be migrated only in the single cpu
868 * case.
869 */
Milton Millerd7cf0ed2007-12-14 15:52:09 +1100870 if (xics_status[0] != hw_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 goto unlock;
872
Anton Blanchard26370322005-09-12 13:12:11 +1000873 printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 virq, cpu);
875
876 /* Reset affinity to all cpus */
Nathan Fontenota52572d2008-02-07 07:37:26 +1100877 irq_desc[virq].affinity = CPU_MASK_ALL;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700878 desc->chip->set_affinity(virq, CPU_MASK_ALL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879unlock:
880 spin_unlock_irqrestore(&desc->lock, flags);
881 }
882}
883#endif