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