Merge branch 'devel'
[pandora-kernel.git] / arch / powerpc / platforms / pseries / xics.c
1 /*
2  * arch/powerpc/platforms/pseries/xics.c
3  *
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  */
11
12 #undef DEBUG
13
14 #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>
25
26 #include <asm/firmware.h>
27 #include <asm/prom.h>
28 #include <asm/io.h>
29 #include <asm/pgtable.h>
30 #include <asm/smp.h>
31 #include <asm/rtas.h>
32 #include <asm/hvcall.h>
33 #include <asm/machdep.h>
34 #include <asm/i8259.h>
35
36 #include "xics.h"
37 #include "plpar_wrappers.h"
38
39 #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
45 /*
46  * Mark IPIs as higher priority so we can take them inside interrupts that
47  * arent marked IRQF_DISABLED
48  */
49 #define IPI_PRIORITY            4
50
51 struct 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
67 static struct xics_ipl __iomem *xics_per_cpu[NR_CPUS];
68
69 static unsigned int default_server = 0xFF;
70 static unsigned int default_distrib_server = 0;
71 static unsigned int interrupt_server_size = 8;
72
73 static struct irq_host *xics_host;
74
75 /*
76  * XICS only has a single IPI, so encode the messages per CPU
77  */
78 struct xics_ipi_struct xics_ipi_message[NR_CPUS] __cacheline_aligned;
79
80 /* RTAS service tokens */
81 static int ibm_get_xive;
82 static int ibm_set_xive;
83 static int ibm_int_on;
84 static int ibm_int_off;
85
86
87 /* Direct HW low level accessors */
88
89
90 static inline unsigned int direct_xirr_info_get(void)
91 {
92         int cpu = smp_processor_id();
93
94         return in_be32(&xics_per_cpu[cpu]->xirr.word);
95 }
96
97 static inline void direct_xirr_info_set(int value)
98 {
99         int cpu = smp_processor_id();
100
101         out_be32(&xics_per_cpu[cpu]->xirr.word, value);
102 }
103
104 static inline void direct_cppr_info(u8 value)
105 {
106         int cpu = smp_processor_id();
107
108         out_8(&xics_per_cpu[cpu]->xirr.bytes[0], value);
109 }
110
111 static inline void direct_qirr_info(int n_cpu, u8 value)
112 {
113         out_8(&xics_per_cpu[n_cpu]->qirr.bytes[0], value);
114 }
115
116
117 /* LPAR low level accessors */
118
119
120 static inline unsigned int lpar_xirr_info_get(void)
121 {
122         unsigned long lpar_rc;
123         unsigned long return_value;
124
125         lpar_rc = plpar_xirr(&return_value);
126         if (lpar_rc != H_SUCCESS)
127                 panic(" bad return code xirr - rc = %lx \n", lpar_rc);
128         return (unsigned int)return_value;
129 }
130
131 static inline void lpar_xirr_info_set(int value)
132 {
133         unsigned long lpar_rc;
134         unsigned long val64 = value & 0xffffffff;
135
136         lpar_rc = plpar_eoi(val64);
137         if (lpar_rc != H_SUCCESS)
138                 panic("bad return code EOI - rc = %ld, value=%lx\n", lpar_rc,
139                       val64);
140 }
141
142 static inline void lpar_cppr_info(u8 value)
143 {
144         unsigned long lpar_rc;
145
146         lpar_rc = plpar_cppr(value);
147         if (lpar_rc != H_SUCCESS)
148                 panic("bad return code cppr - rc = %lx\n", lpar_rc);
149 }
150
151 static inline void lpar_qirr_info(int n_cpu , u8 value)
152 {
153         unsigned long lpar_rc;
154
155         lpar_rc = plpar_ipi(get_hard_smp_processor_id(n_cpu), value);
156         if (lpar_rc != H_SUCCESS)
157                 panic("bad return code qirr - rc = %lx\n", lpar_rc);
158 }
159
160
161 /* High level handlers and init code */
162
163 static 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 }
203
204 #ifdef CONFIG_SMP
205 static int get_irq_server(unsigned int virq, unsigned int strict_check)
206 {
207         int server;
208         /* For the moment only implement delivery to all cpus or one cpu */
209         cpumask_t cpumask = irq_desc[virq].affinity;
210         cpumask_t tmp = CPU_MASK_NONE;
211
212         if (! cpu_isset(default_server, cpu_online_map))
213                 xics_update_irq_servers();
214
215         if (!distribute_irqs)
216                 return default_server;
217
218         if (!cpus_equal(cpumask, CPU_MASK_ALL)) {
219                 cpus_and(tmp, cpu_online_map, cpumask);
220
221                 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;
228         }
229
230         if (cpus_equal(cpu_online_map, cpu_present_map))
231                 return default_distrib_server;
232
233         return default_server;
234 }
235 #else
236 static int get_irq_server(unsigned int virq, unsigned int strict_check)
237 {
238         return default_server;
239 }
240 #endif
241
242
243 static void xics_unmask_irq(unsigned int virq)
244 {
245         unsigned int irq;
246         int call_status;
247         int server;
248
249         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)
254                 return;
255
256         server = get_irq_server(virq, 0);
257
258         call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server,
259                                 DEFAULT_PRIORITY);
260         if (call_status != 0) {
261                 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);
264                 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) {
270                 printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_int_on "
271                        "returned %d\n", irq, call_status);
272                 return;
273         }
274 }
275
276 static void xics_mask_real_irq(unsigned int irq)
277 {
278         int call_status;
279
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) {
285                 printk(KERN_ERR "xics_disable_real_irq: irq=%u: "
286                        "ibm_int_off returned %d\n", irq, call_status);
287                 return;
288         }
289
290         /* Have to set XIVE to 0xff to be able to remove a slot */
291         call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq,
292                                 default_server, 0xff);
293         if (call_status != 0) {
294                 printk(KERN_ERR "xics_disable_irq: irq=%u: ibm_set_xive(0xff)"
295                        " returned %d\n", irq, call_status);
296                 return;
297         }
298 }
299
300 static void xics_mask_irq(unsigned int virq)
301 {
302         unsigned int irq;
303
304         pr_debug("xics: mask virq %d\n", virq);
305
306         irq = (unsigned int)irq_map[virq].hwirq;
307         if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
308                 return;
309         xics_mask_real_irq(irq);
310 }
311
312 static unsigned int xics_startup(unsigned int virq)
313 {
314         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 */
321         xics_unmask_irq(virq);
322         return 0;
323 }
324
325 static void xics_eoi_direct(unsigned int virq)
326 {
327         unsigned int irq = (unsigned int)irq_map[virq].hwirq;
328
329         iosync();
330         direct_xirr_info_set((0xff << 24) | irq);
331 }
332
333
334 static void xics_eoi_lpar(unsigned int virq)
335 {
336         unsigned int irq = (unsigned int)irq_map[virq].hwirq;
337
338         iosync();
339         lpar_xirr_info_set((0xff << 24) | irq);
340 }
341
342 static inline unsigned int xics_remap_irq(unsigned int vec)
343 {
344         unsigned int irq;
345
346         vec &= 0x00ffffff;
347
348         if (vec == XICS_IRQ_SPURIOUS)
349                 return NO_IRQ;
350         irq = irq_radix_revmap(xics_host, vec);
351         if (likely(irq != NO_IRQ))
352                 return irq;
353
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
360 static unsigned int xics_get_irq_direct(void)
361 {
362         return xics_remap_irq(direct_xirr_info_get());
363 }
364
365 static unsigned int xics_get_irq_lpar(void)
366 {
367         return xics_remap_irq(lpar_xirr_info_get());
368 }
369
370 #ifdef CONFIG_SMP
371
372 static irqreturn_t xics_ipi_dispatch(int cpu)
373 {
374         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();
380                         smp_message_recv(PPC_MSG_CALL_FUNCTION);
381                 }
382                 if (test_and_clear_bit(PPC_MSG_RESCHEDULE,
383                                        &xics_ipi_message[cpu].value)) {
384                         mb();
385                         smp_message_recv(PPC_MSG_RESCHEDULE);
386                 }
387 #if 0
388                 if (test_and_clear_bit(PPC_MSG_MIGRATE_TASK,
389                                        &xics_ipi_message[cpu].value)) {
390                         mb();
391                         smp_message_recv(PPC_MSG_MIGRATE_TASK);
392                 }
393 #endif
394 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
395                 if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK,
396                                        &xics_ipi_message[cpu].value)) {
397                         mb();
398                         smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
399                 }
400 #endif
401         }
402         return IRQ_HANDLED;
403 }
404
405 static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
406 {
407         int cpu = smp_processor_id();
408
409         direct_qirr_info(cpu, 0xff);
410
411         return xics_ipi_dispatch(cpu);
412 }
413
414 static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
415 {
416         int cpu = smp_processor_id();
417
418         lpar_qirr_info(cpu, 0xff);
419
420         return xics_ipi_dispatch(cpu);
421 }
422
423 void xics_cause_IPI(int cpu)
424 {
425         if (firmware_has_feature(FW_FEATURE_LPAR))
426                 lpar_qirr_info(cpu, IPI_PRIORITY);
427         else
428                 direct_qirr_info(cpu, IPI_PRIORITY);
429 }
430
431 #endif /* CONFIG_SMP */
432
433 static void xics_set_cpu_priority(unsigned char cppr)
434 {
435         if (firmware_has_feature(FW_FEATURE_LPAR))
436                 lpar_cppr_info(cppr);
437         else
438                 direct_cppr_info(cppr);
439         iosync();
440 }
441
442 static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
443 {
444         unsigned int irq;
445         int status;
446         int xics_status[2];
447         int irq_server;
448
449         irq = (unsigned int)irq_map[virq].hwirq;
450         if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
451                 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
461         /*
462          * For the moment only implement delivery to all cpus or one cpu.
463          * Get current irq_server for the given irq
464          */
465         irq_server = get_irq_server(virq, 1);
466         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;
472         }
473
474         status = rtas_call(ibm_set_xive, 3, 1, NULL,
475                                 irq, irq_server, xics_status[1]);
476
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
484 void xics_setup_cpu(void)
485 {
486         xics_set_cpu_priority(0xff);
487
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          */
495         rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
496                 (1UL << interrupt_server_size) - 1 - default_distrib_server, 1);
497 }
498
499
500 static 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
510 static 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 /* Points to the irq_chip we're actually using */
520 static struct irq_chip *xics_irq_chip;
521
522 static int xics_host_match(struct irq_host *h, struct device_node *node)
523 {
524         /* IBM machines have interrupt parents of various funky types for things
525          * like vdevices, events, etc... The trick we use here is to match
526          * everything here except the legacy 8259 which is compatible "chrp,iic"
527          */
528         return !of_device_is_compatible(node, "chrp,iic");
529 }
530
531 static int xics_host_map(struct irq_host *h, unsigned int virq,
532                          irq_hw_number_t hw)
533 {
534         pr_debug("xics: map virq %d, hwirq 0x%lx\n", virq, hw);
535
536         get_irq_desc(virq)->status |= IRQ_LEVEL;
537         set_irq_chip_and_handler(virq, xics_irq_chip, handle_fasteoi_irq);
538         return 0;
539 }
540
541 static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
542                            u32 *intspec, unsigned int intsize,
543                            irq_hw_number_t *out_hwirq, unsigned int *out_flags)
544
545 {
546         /* Current xics implementation translates everything
547          * to level. It is not technically right for MSIs but this
548          * is irrelevant at this point. We might get smarter in the future
549          */
550         *out_hwirq = intspec[0];
551         *out_flags = IRQ_TYPE_LEVEL_LOW;
552
553         return 0;
554 }
555
556 static struct irq_host_ops xics_host_ops = {
557         .match = xics_host_match,
558         .map = xics_host_map,
559         .xlate = xics_host_xlate,
560 };
561
562 static void __init xics_init_host(void)
563 {
564         if (firmware_has_feature(FW_FEATURE_LPAR))
565                 xics_irq_chip = &xics_pic_lpar;
566         else
567                 xics_irq_chip = &xics_pic_direct;
568
569         xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, &xics_host_ops,
570                                    XICS_IRQ_SPURIOUS);
571         BUG_ON(xics_host == NULL);
572         irq_set_default_host(xics_host);
573 }
574
575 static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
576                                      unsigned long size)
577 {
578 #ifdef CONFIG_SMP
579         int i;
580
581         /* This may look gross but it's good enough for now, we don't quite
582          * have a hard -> linux processor id matching.
583          */
584         for_each_possible_cpu(i) {
585                 if (!cpu_present(i))
586                         continue;
587                 if (hw_id == get_hard_smp_processor_id(i)) {
588                         xics_per_cpu[i] = ioremap(addr, size);
589                         return;
590                 }
591         }
592 #else
593         if (hw_id != 0)
594                 return;
595         xics_per_cpu[0] = ioremap(addr, size);
596 #endif /* CONFIG_SMP */
597 }
598
599 static void __init xics_init_one_node(struct device_node *np,
600                                       unsigned int *indx)
601 {
602         unsigned int ilen;
603         const u32 *ireg;
604
605         /* This code does the theorically broken assumption that the interrupt
606          * server numbers are the same as the hard CPU numbers.
607          * This happens to be the case so far but we are playing with fire...
608          * should be fixed one of these days. -BenH.
609          */
610         ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
611
612         /* Do that ever happen ? we'll know soon enough... but even good'old
613          * f80 does have that property ..
614          */
615         WARN_ON(ireg == NULL);
616         if (ireg) {
617                 /*
618                  * set node starting index for this node
619                  */
620                 *indx = *ireg;
621         }
622         ireg = of_get_property(np, "reg", &ilen);
623         if (!ireg)
624                 panic("xics_init_IRQ: can't find interrupt reg property");
625
626         while (ilen >= (4 * sizeof(u32))) {
627                 unsigned long addr, size;
628
629                 /* XXX Use proper OF parsing code here !!! */
630                 addr = (unsigned long)*ireg++ << 32;
631                 ilen -= sizeof(u32);
632                 addr |= *ireg++;
633                 ilen -= sizeof(u32);
634                 size = (unsigned long)*ireg++ << 32;
635                 ilen -= sizeof(u32);
636                 size |= *ireg++;
637                 ilen -= sizeof(u32);
638                 xics_map_one_cpu(*indx, addr, size);
639                 (*indx)++;
640         }
641 }
642
643 void __init xics_init_IRQ(void)
644 {
645         struct device_node *np;
646         u32 indx = 0;
647         int found = 0;
648
649         ppc64_boot_msg(0x20, "XICS Init");
650
651         ibm_get_xive = rtas_token("ibm,get-xive");
652         ibm_set_xive = rtas_token("ibm,set-xive");
653         ibm_int_on  = rtas_token("ibm,int-on");
654         ibm_int_off = rtas_token("ibm,int-off");
655
656         for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
657                 found = 1;
658                 if (firmware_has_feature(FW_FEATURE_LPAR))
659                         break;
660                 xics_init_one_node(np, &indx);
661         }
662         if (found == 0)
663                 return;
664
665         xics_init_host();
666         xics_update_irq_servers();
667
668         if (firmware_has_feature(FW_FEATURE_LPAR))
669                 ppc_md.get_irq = xics_get_irq_lpar;
670         else
671                 ppc_md.get_irq = xics_get_irq_direct;
672
673         xics_setup_cpu();
674
675         ppc64_boot_msg(0x21, "XICS Done");
676 }
677
678
679 #ifdef CONFIG_SMP
680 void xics_request_IPIs(void)
681 {
682         unsigned int ipi;
683         int rc;
684
685         ipi = irq_create_mapping(xics_host, XICS_IPI);
686         BUG_ON(ipi == NO_IRQ);
687
688         /*
689          * IPIs are marked IRQF_DISABLED as they must run with irqs
690          * disabled
691          */
692         set_irq_handler(ipi, handle_percpu_irq);
693         if (firmware_has_feature(FW_FEATURE_LPAR))
694                 rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED,
695                                 "IPI", NULL);
696         else
697                 rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED,
698                                 "IPI", NULL);
699         BUG_ON(rc);
700 }
701 #endif /* CONFIG_SMP */
702
703 void xics_teardown_cpu(void)
704 {
705         int cpu = smp_processor_id();
706
707         xics_set_cpu_priority(0);
708
709         /*
710          * Clear IPI
711          */
712         if (firmware_has_feature(FW_FEATURE_LPAR))
713                 lpar_qirr_info(cpu, 0xff);
714         else
715                 direct_qirr_info(cpu, 0xff);
716 }
717
718 void xics_kexec_teardown_cpu(int secondary)
719 {
720         unsigned int ipi;
721         struct irq_desc *desc;
722
723         xics_teardown_cpu();
724
725         /*
726          * we need to EOI the IPI
727          *
728          * probably need to check all the other interrupts too
729          * should we be flagging idle loop instead?
730          * or creating some task to be scheduled?
731          */
732
733         ipi = irq_find_mapping(xics_host, XICS_IPI);
734         if (ipi == XICS_IRQ_SPURIOUS)
735                 return;
736         desc = get_irq_desc(ipi);
737         if (desc->chip && desc->chip->eoi)
738                 desc->chip->eoi(ipi);
739
740         /*
741          * Some machines need to have at least one cpu in the GIQ,
742          * so leave the master cpu in the group.
743          */
744         if (secondary)
745                 rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
746                                    (1UL << interrupt_server_size) - 1 -
747                                    default_distrib_server, 0);
748 }
749
750 #ifdef CONFIG_HOTPLUG_CPU
751
752 /* Interrupts are disabled. */
753 void xics_migrate_irqs_away(void)
754 {
755         int status;
756         int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
757         unsigned int irq, virq;
758
759         /* Reject any interrupt that was queued to us... */
760         xics_set_cpu_priority(0);
761
762         /* remove ourselves from the global interrupt queue */
763         status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
764                 (1UL << interrupt_server_size) - 1 - default_distrib_server, 0);
765         WARN_ON(status < 0);
766
767         /* Allow IPIs again... */
768         xics_set_cpu_priority(DEFAULT_PRIORITY);
769
770         for_each_irq(virq) {
771                 struct irq_desc *desc;
772                 int xics_status[2];
773                 unsigned long flags;
774
775                 /* We cant set affinity on ISA interrupts */
776                 if (virq < NUM_ISA_INTERRUPTS)
777                         continue;
778                 if (irq_map[virq].host != xics_host)
779                         continue;
780                 irq = (unsigned int)irq_map[virq].hwirq;
781                 /* We need to get IPIs still. */
782                 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
783                         continue;
784                 desc = get_irq_desc(virq);
785
786                 /* We only need to migrate enabled IRQS */
787                 if (desc == NULL || desc->chip == NULL
788                     || desc->action == NULL
789                     || desc->chip->set_affinity == NULL)
790                         continue;
791
792                 spin_lock_irqsave(&desc->lock, flags);
793
794                 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
795                 if (status) {
796                         printk(KERN_ERR "migrate_irqs_away: irq=%u "
797                                         "ibm,get-xive returns %d\n",
798                                         virq, status);
799                         goto unlock;
800                 }
801
802                 /*
803                  * We only support delivery to all cpus or to one cpu.
804                  * The irq has to be migrated only in the single cpu
805                  * case.
806                  */
807                 if (xics_status[0] != hw_cpu)
808                         goto unlock;
809
810                 printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
811                        virq, cpu);
812
813                 /* Reset affinity to all cpus */
814                 irq_desc[virq].affinity = CPU_MASK_ALL;
815                 desc->chip->set_affinity(virq, CPU_MASK_ALL);
816 unlock:
817                 spin_unlock_irqrestore(&desc->lock, flags);
818         }
819 }
820 #endif