GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / powerpc / platforms / pseries / xics.c
blob7705fa4e40d11d5757b0deee19f90e81591ea59d
1 /*
2 * arch/powerpc/platforms/pseries/xics.c
4 * Copyright 2000 IBM Corporation.
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.
12 #include <linux/types.h>
13 #include <linux/threads.h>
14 #include <linux/kernel.h>
15 #include <linux/irq.h>
16 #include <linux/smp.h>
17 #include <linux/interrupt.h>
18 #include <linux/init.h>
19 #include <linux/radix-tree.h>
20 #include <linux/cpu.h>
21 #include <linux/msi.h>
22 #include <linux/of.h>
23 #include <linux/percpu.h>
25 #include <asm/firmware.h>
26 #include <asm/io.h>
27 #include <asm/pgtable.h>
28 #include <asm/smp.h>
29 #include <asm/rtas.h>
30 #include <asm/hvcall.h>
31 #include <asm/machdep.h>
33 #include "xics.h"
34 #include "plpar_wrappers.h"
36 static struct irq_host *xics_host;
38 #define XICS_IPI 2
39 #define XICS_IRQ_SPURIOUS 0
41 /* Want a priority other than 0. Various HW issues require this. */
42 #define DEFAULT_PRIORITY 5
45 * Mark IPIs as higher priority so we can take them inside interrupts that
46 * arent marked IRQF_DISABLED
48 #define IPI_PRIORITY 4
50 /* The least favored priority */
51 #define LOWEST_PRIORITY 0xFF
53 /* The number of priorities defined above */
54 #define MAX_NUM_PRIORITIES 3
56 static unsigned int default_server = 0xFF;
57 static unsigned int default_distrib_server = 0;
58 static unsigned int interrupt_server_size = 8;
60 /* RTAS service tokens */
61 static int ibm_get_xive;
62 static int ibm_set_xive;
63 static int ibm_int_on;
64 static int ibm_int_off;
66 struct xics_cppr {
67 unsigned char stack[MAX_NUM_PRIORITIES];
68 int index;
71 static DEFINE_PER_CPU(struct xics_cppr, xics_cppr);
73 /* Direct hardware low level accessors */
75 /* The part of the interrupt presentation layer that we care about */
76 struct xics_ipl {
77 union {
78 u32 word;
79 u8 bytes[4];
80 } xirr_poll;
81 union {
82 u32 word;
83 u8 bytes[4];
84 } xirr;
85 u32 dummy;
86 union {
87 u32 word;
88 u8 bytes[4];
89 } qirr;
92 static struct xics_ipl __iomem *xics_per_cpu[NR_CPUS];
94 static inline unsigned int direct_xirr_info_get(void)
96 int cpu = smp_processor_id();
98 return in_be32(&xics_per_cpu[cpu]->xirr.word);
101 static inline void direct_xirr_info_set(unsigned int value)
103 int cpu = smp_processor_id();
105 out_be32(&xics_per_cpu[cpu]->xirr.word, value);
108 static inline void direct_cppr_info(u8 value)
110 int cpu = smp_processor_id();
112 out_8(&xics_per_cpu[cpu]->xirr.bytes[0], value);
115 static inline void direct_qirr_info(int n_cpu, u8 value)
117 out_8(&xics_per_cpu[n_cpu]->qirr.bytes[0], value);
121 /* LPAR low level accessors */
123 static inline unsigned int lpar_xirr_info_get(unsigned char cppr)
125 unsigned long lpar_rc;
126 unsigned long return_value;
128 lpar_rc = plpar_xirr(&return_value, cppr);
129 if (lpar_rc != H_SUCCESS)
130 panic(" bad return code xirr - rc = %lx\n", lpar_rc);
131 return (unsigned int)return_value;
134 static inline void lpar_xirr_info_set(unsigned int value)
136 unsigned long lpar_rc;
138 lpar_rc = plpar_eoi(value);
139 if (lpar_rc != H_SUCCESS)
140 panic("bad return code EOI - rc = %ld, value=%x\n", lpar_rc,
141 value);
144 static inline void lpar_cppr_info(u8 value)
146 unsigned long lpar_rc;
148 lpar_rc = plpar_cppr(value);
149 if (lpar_rc != H_SUCCESS)
150 panic("bad return code cppr - rc = %lx\n", lpar_rc);
153 static inline void lpar_qirr_info(int n_cpu , u8 value)
155 unsigned long lpar_rc;
157 lpar_rc = plpar_ipi(get_hard_smp_processor_id(n_cpu), value);
158 if (lpar_rc != H_SUCCESS)
159 panic("bad return code qirr - rc = %lx\n", lpar_rc);
163 /* Interface to generic irq subsystem */
165 #ifdef CONFIG_SMP
167 * For the moment we only implement delivery to all cpus or one cpu.
169 * If the requested affinity is cpu_all_mask, we set global affinity.
170 * If not we set it to the first cpu in the mask, even if multiple cpus
171 * are set. This is so things like irqbalance (which set core and package
172 * wide affinities) do the right thing.
174 static int get_irq_server(unsigned int virq, const struct cpumask *cpumask,
175 unsigned int strict_check)
178 if (!distribute_irqs)
179 return default_server;
181 if (!cpumask_equal(cpumask, cpu_all_mask)) {
182 int server = cpumask_first_and(cpu_online_mask, cpumask);
184 if (server < nr_cpu_ids)
185 return get_hard_smp_processor_id(server);
187 if (strict_check)
188 return -1;
191 if (cpumask_equal(cpu_online_mask, cpu_present_mask))
192 return default_distrib_server;
194 return default_server;
196 #else
197 #define get_irq_server(virq, cpumask, strict_check) (default_server)
198 #endif
200 static void xics_unmask_irq(unsigned int virq)
202 unsigned int irq;
203 int call_status;
204 int server;
206 pr_devel("xics: unmask virq %d\n", virq);
208 irq = (unsigned int)irq_map[virq].hwirq;
209 pr_devel(" -> map to hwirq 0x%x\n", irq);
210 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
211 return;
213 server = get_irq_server(virq, irq_to_desc(virq)->affinity, 0);
215 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server,
216 DEFAULT_PRIORITY);
217 if (call_status != 0) {
218 printk(KERN_ERR
219 "%s: ibm_set_xive irq %u server %x returned %d\n",
220 __func__, irq, server, call_status);
221 return;
224 /* Now unmask the interrupt (often a no-op) */
225 call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq);
226 if (call_status != 0) {
227 printk(KERN_ERR "%s: ibm_int_on irq=%u returned %d\n",
228 __func__, irq, call_status);
229 return;
233 static unsigned int xics_startup(unsigned int virq)
236 * The generic MSI code returns with the interrupt disabled on the
237 * card, using the MSI mask bits. Firmware doesn't appear to unmask
238 * at that level, so we do it here by hand.
240 if (irq_to_desc(virq)->msi_desc)
241 unmask_msi_irq(virq);
243 /* unmask it */
244 xics_unmask_irq(virq);
245 return 0;
248 static void xics_mask_real_irq(unsigned int irq)
250 int call_status;
252 if (irq == XICS_IPI)
253 return;
255 call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq);
256 if (call_status != 0) {
257 printk(KERN_ERR "%s: ibm_int_off irq=%u returned %d\n",
258 __func__, irq, call_status);
259 return;
262 /* Have to set XIVE to 0xff to be able to remove a slot */
263 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq,
264 default_server, 0xff);
265 if (call_status != 0) {
266 printk(KERN_ERR "%s: ibm_set_xive(0xff) irq=%u returned %d\n",
267 __func__, irq, call_status);
268 return;
272 static void xics_mask_irq(unsigned int virq)
274 unsigned int irq;
276 pr_devel("xics: mask virq %d\n", virq);
278 irq = (unsigned int)irq_map[virq].hwirq;
279 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
280 return;
281 xics_mask_real_irq(irq);
284 static void xics_mask_unknown_vec(unsigned int vec)
286 printk(KERN_ERR "Interrupt %u (real) is invalid, disabling it.\n", vec);
287 xics_mask_real_irq(vec);
290 static inline unsigned int xics_xirr_vector(unsigned int xirr)
293 * The top byte is the old cppr, to be restored on EOI.
294 * The remaining 24 bits are the vector.
296 return xirr & 0x00ffffff;
299 static void push_cppr(unsigned int vec)
301 struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
303 if (WARN_ON(os_cppr->index >= MAX_NUM_PRIORITIES - 1))
304 return;
306 if (vec == XICS_IPI)
307 os_cppr->stack[++os_cppr->index] = IPI_PRIORITY;
308 else
309 os_cppr->stack[++os_cppr->index] = DEFAULT_PRIORITY;
312 static unsigned int xics_get_irq_direct(void)
314 unsigned int xirr = direct_xirr_info_get();
315 unsigned int vec = xics_xirr_vector(xirr);
316 unsigned int irq;
318 if (vec == XICS_IRQ_SPURIOUS)
319 return NO_IRQ;
321 irq = irq_radix_revmap_lookup(xics_host, vec);
322 if (likely(irq != NO_IRQ)) {
323 push_cppr(vec);
324 return irq;
327 /* We don't have a linux mapping, so have rtas mask it. */
328 xics_mask_unknown_vec(vec);
330 /* We might learn about it later, so EOI it */
331 direct_xirr_info_set(xirr);
332 return NO_IRQ;
335 static unsigned int xics_get_irq_lpar(void)
337 struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
338 unsigned int xirr = lpar_xirr_info_get(os_cppr->stack[os_cppr->index]);
339 unsigned int vec = xics_xirr_vector(xirr);
340 unsigned int irq;
342 if (vec == XICS_IRQ_SPURIOUS)
343 return NO_IRQ;
345 irq = irq_radix_revmap_lookup(xics_host, vec);
346 if (likely(irq != NO_IRQ)) {
347 push_cppr(vec);
348 return irq;
351 /* We don't have a linux mapping, so have RTAS mask it. */
352 xics_mask_unknown_vec(vec);
354 /* We might learn about it later, so EOI it */
355 lpar_xirr_info_set(xirr);
356 return NO_IRQ;
359 static unsigned char pop_cppr(void)
361 struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
363 if (WARN_ON(os_cppr->index < 1))
364 return LOWEST_PRIORITY;
366 return os_cppr->stack[--os_cppr->index];
369 static void xics_eoi_direct(unsigned int virq)
371 unsigned int irq = (unsigned int)irq_map[virq].hwirq;
373 iosync();
374 direct_xirr_info_set((pop_cppr() << 24) | irq);
377 static void xics_eoi_lpar(unsigned int virq)
379 unsigned int irq = (unsigned int)irq_map[virq].hwirq;
381 iosync();
382 lpar_xirr_info_set((pop_cppr() << 24) | irq);
385 static int xics_set_affinity(unsigned int virq, const struct cpumask *cpumask)
387 unsigned int irq;
388 int status;
389 int xics_status[2];
390 int irq_server;
392 irq = (unsigned int)irq_map[virq].hwirq;
393 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
394 return -1;
396 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
398 if (status) {
399 printk(KERN_ERR "%s: ibm,get-xive irq=%u returns %d\n",
400 __func__, irq, status);
401 return -1;
404 irq_server = get_irq_server(virq, cpumask, 1);
405 if (irq_server == -1) {
406 char cpulist[128];
407 cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask);
408 printk(KERN_WARNING
409 "%s: No online cpus in the mask %s for irq %d\n",
410 __func__, cpulist, virq);
411 return -1;
414 status = rtas_call(ibm_set_xive, 3, 1, NULL,
415 irq, irq_server, xics_status[1]);
417 if (status) {
418 printk(KERN_ERR "%s: ibm,set-xive irq=%u returns %d\n",
419 __func__, irq, status);
420 return -1;
423 return 0;
426 static struct irq_chip xics_pic_direct = {
427 .name = "XICS",
428 .startup = xics_startup,
429 .mask = xics_mask_irq,
430 .unmask = xics_unmask_irq,
431 .eoi = xics_eoi_direct,
432 .set_affinity = xics_set_affinity
435 static struct irq_chip xics_pic_lpar = {
436 .name = "XICS",
437 .startup = xics_startup,
438 .mask = xics_mask_irq,
439 .unmask = xics_unmask_irq,
440 .eoi = xics_eoi_lpar,
441 .set_affinity = xics_set_affinity
445 /* Interface to arch irq controller subsystem layer */
447 /* Points to the irq_chip we're actually using */
448 static struct irq_chip *xics_irq_chip;
450 static int xics_host_match(struct irq_host *h, struct device_node *node)
452 /* IBM machines have interrupt parents of various funky types for things
453 * like vdevices, events, etc... The trick we use here is to match
454 * everything here except the legacy 8259 which is compatible "chrp,iic"
456 return !of_device_is_compatible(node, "chrp,iic");
459 static int xics_host_map(struct irq_host *h, unsigned int virq,
460 irq_hw_number_t hw)
462 pr_devel("xics: map virq %d, hwirq 0x%lx\n", virq, hw);
464 /* Insert the interrupt mapping into the radix tree for fast lookup */
465 irq_radix_revmap_insert(xics_host, virq, hw);
467 irq_to_desc(virq)->status |= IRQ_LEVEL;
468 set_irq_chip_and_handler(virq, xics_irq_chip, handle_fasteoi_irq);
469 return 0;
472 static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
473 const u32 *intspec, unsigned int intsize,
474 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
477 /* Current xics implementation translates everything
478 * to level. It is not technically right for MSIs but this
479 * is irrelevant at this point. We might get smarter in the future
481 *out_hwirq = intspec[0];
482 *out_flags = IRQ_TYPE_LEVEL_LOW;
484 return 0;
487 static struct irq_host_ops xics_host_ops = {
488 .match = xics_host_match,
489 .map = xics_host_map,
490 .xlate = xics_host_xlate,
493 static void __init xics_init_host(void)
495 if (firmware_has_feature(FW_FEATURE_LPAR))
496 xics_irq_chip = &xics_pic_lpar;
497 else
498 xics_irq_chip = &xics_pic_direct;
500 xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, &xics_host_ops,
501 XICS_IRQ_SPURIOUS);
502 BUG_ON(xics_host == NULL);
503 irq_set_default_host(xics_host);
507 /* Inter-processor interrupt support */
509 #ifdef CONFIG_SMP
511 * XICS only has a single IPI, so encode the messages per CPU
513 static DEFINE_PER_CPU_SHARED_ALIGNED(unsigned long, xics_ipi_message);
515 static inline void smp_xics_do_message(int cpu, int msg)
517 unsigned long *tgt = &per_cpu(xics_ipi_message, cpu);
519 set_bit(msg, tgt);
520 mb();
521 if (firmware_has_feature(FW_FEATURE_LPAR))
522 lpar_qirr_info(cpu, IPI_PRIORITY);
523 else
524 direct_qirr_info(cpu, IPI_PRIORITY);
527 void smp_xics_message_pass(int target, int msg)
529 unsigned int i;
531 if (target < NR_CPUS) {
532 smp_xics_do_message(target, msg);
533 } else {
534 for_each_online_cpu(i) {
535 if (target == MSG_ALL_BUT_SELF
536 && i == smp_processor_id())
537 continue;
538 smp_xics_do_message(i, msg);
543 static irqreturn_t xics_ipi_dispatch(int cpu)
545 unsigned long *tgt = &per_cpu(xics_ipi_message, cpu);
547 mb(); /* order mmio clearing qirr */
548 while (*tgt) {
549 if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION, tgt)) {
550 smp_message_recv(PPC_MSG_CALL_FUNCTION);
552 if (test_and_clear_bit(PPC_MSG_RESCHEDULE, tgt)) {
553 smp_message_recv(PPC_MSG_RESCHEDULE);
555 if (test_and_clear_bit(PPC_MSG_CALL_FUNC_SINGLE, tgt)) {
556 smp_message_recv(PPC_MSG_CALL_FUNC_SINGLE);
558 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
559 if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK, tgt)) {
560 smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
562 #endif
564 return IRQ_HANDLED;
567 static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
569 int cpu = smp_processor_id();
571 direct_qirr_info(cpu, 0xff);
573 return xics_ipi_dispatch(cpu);
576 static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
578 int cpu = smp_processor_id();
580 lpar_qirr_info(cpu, 0xff);
582 return xics_ipi_dispatch(cpu);
585 static void xics_request_ipi(void)
587 unsigned int ipi;
588 int rc;
590 ipi = irq_create_mapping(xics_host, XICS_IPI);
591 BUG_ON(ipi == NO_IRQ);
594 * IPIs are marked IRQF_DISABLED as they must run with irqs
595 * disabled
597 set_irq_handler(ipi, handle_percpu_irq);
598 if (firmware_has_feature(FW_FEATURE_LPAR))
599 rc = request_irq(ipi, xics_ipi_action_lpar,
600 IRQF_DISABLED|IRQF_PERCPU, "IPI", NULL);
601 else
602 rc = request_irq(ipi, xics_ipi_action_direct,
603 IRQF_DISABLED|IRQF_PERCPU, "IPI", NULL);
604 BUG_ON(rc);
607 int __init smp_xics_probe(void)
609 xics_request_ipi();
611 return cpumask_weight(cpu_possible_mask);
614 #endif /* CONFIG_SMP */
617 /* Initialization */
619 static void xics_update_irq_servers(void)
621 int i, j;
622 struct device_node *np;
623 u32 ilen;
624 const u32 *ireg;
625 u32 hcpuid;
627 /* Find the server numbers for the boot cpu. */
628 np = of_get_cpu_node(boot_cpuid, NULL);
629 BUG_ON(!np);
631 ireg = of_get_property(np, "ibm,ppc-interrupt-gserver#s", &ilen);
632 if (!ireg) {
633 of_node_put(np);
634 return;
637 i = ilen / sizeof(int);
638 hcpuid = get_hard_smp_processor_id(boot_cpuid);
640 /* Global interrupt distribution server is specified in the last
641 * entry of "ibm,ppc-interrupt-gserver#s" property. Get the last
642 * entry fom this property for current boot cpu id and use it as
643 * default distribution server
645 for (j = 0; j < i; j += 2) {
646 if (ireg[j] == hcpuid) {
647 default_server = hcpuid;
648 default_distrib_server = ireg[j+1];
652 of_node_put(np);
655 static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
656 unsigned long size)
658 int i;
660 /* This may look gross but it's good enough for now, we don't quite
661 * have a hard -> linux processor id matching.
663 for_each_possible_cpu(i) {
664 if (!cpu_present(i))
665 continue;
666 if (hw_id == get_hard_smp_processor_id(i)) {
667 xics_per_cpu[i] = ioremap(addr, size);
668 return;
673 static void __init xics_init_one_node(struct device_node *np,
674 unsigned int *indx)
676 unsigned int ilen;
677 const u32 *ireg;
679 /* This code does the theorically broken assumption that the interrupt
680 * server numbers are the same as the hard CPU numbers.
681 * This happens to be the case so far but we are playing with fire...
682 * should be fixed one of these days. -BenH.
684 ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
686 /* Do that ever happen ? we'll know soon enough... but even good'old
687 * f80 does have that property ..
689 WARN_ON(ireg == NULL);
690 if (ireg) {
692 * set node starting index for this node
694 *indx = *ireg;
696 ireg = of_get_property(np, "reg", &ilen);
697 if (!ireg)
698 panic("xics_init_IRQ: can't find interrupt reg property");
700 while (ilen >= (4 * sizeof(u32))) {
701 unsigned long addr, size;
703 addr = (unsigned long)*ireg++ << 32;
704 ilen -= sizeof(u32);
705 addr |= *ireg++;
706 ilen -= sizeof(u32);
707 size = (unsigned long)*ireg++ << 32;
708 ilen -= sizeof(u32);
709 size |= *ireg++;
710 ilen -= sizeof(u32);
711 xics_map_one_cpu(*indx, addr, size);
712 (*indx)++;
716 void __init xics_init_IRQ(void)
718 struct device_node *np;
719 u32 indx = 0;
720 int found = 0;
721 const u32 *isize;
723 ppc64_boot_msg(0x20, "XICS Init");
725 ibm_get_xive = rtas_token("ibm,get-xive");
726 ibm_set_xive = rtas_token("ibm,set-xive");
727 ibm_int_on = rtas_token("ibm,int-on");
728 ibm_int_off = rtas_token("ibm,int-off");
730 for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
731 found = 1;
732 if (firmware_has_feature(FW_FEATURE_LPAR)) {
733 of_node_put(np);
734 break;
736 xics_init_one_node(np, &indx);
738 if (found == 0)
739 return;
741 /* get the bit size of server numbers */
742 found = 0;
744 for_each_compatible_node(np, NULL, "ibm,ppc-xics") {
745 isize = of_get_property(np, "ibm,interrupt-server#-size", NULL);
747 if (!isize)
748 continue;
750 if (!found) {
751 interrupt_server_size = *isize;
752 found = 1;
753 } else if (*isize != interrupt_server_size) {
754 printk(KERN_WARNING "XICS: "
755 "mismatched ibm,interrupt-server#-size\n");
756 interrupt_server_size = max(*isize,
757 interrupt_server_size);
761 xics_update_irq_servers();
762 xics_init_host();
764 if (firmware_has_feature(FW_FEATURE_LPAR))
765 ppc_md.get_irq = xics_get_irq_lpar;
766 else
767 ppc_md.get_irq = xics_get_irq_direct;
769 xics_setup_cpu();
771 ppc64_boot_msg(0x21, "XICS Done");
774 /* Cpu startup, shutdown, and hotplug */
776 static void xics_set_cpu_priority(unsigned char cppr)
778 struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
781 * we only really want to set the priority when there's
782 * just one cppr value on the stack
784 WARN_ON(os_cppr->index != 0);
786 os_cppr->stack[0] = cppr;
788 if (firmware_has_feature(FW_FEATURE_LPAR))
789 lpar_cppr_info(cppr);
790 else
791 direct_cppr_info(cppr);
792 iosync();
795 /* Have the calling processor join or leave the specified global queue */
796 static void xics_set_cpu_giq(unsigned int gserver, unsigned int join)
798 int index;
799 int status;
801 if (!rtas_indicator_present(GLOBAL_INTERRUPT_QUEUE, NULL))
802 return;
804 index = (1UL << interrupt_server_size) - 1 - gserver;
806 status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE, index, join);
808 WARN(status < 0, "set-indicator(%d, %d, %u) returned %d\n",
809 GLOBAL_INTERRUPT_QUEUE, index, join, status);
812 void xics_setup_cpu(void)
814 xics_set_cpu_priority(LOWEST_PRIORITY);
816 xics_set_cpu_giq(default_distrib_server, 1);
819 void xics_teardown_cpu(void)
821 struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
822 int cpu = smp_processor_id();
825 * we have to reset the cppr index to 0 because we're
826 * not going to return from the IPI
828 os_cppr->index = 0;
829 xics_set_cpu_priority(0);
831 /* Clear any pending IPI request */
832 if (firmware_has_feature(FW_FEATURE_LPAR))
833 lpar_qirr_info(cpu, 0xff);
834 else
835 direct_qirr_info(cpu, 0xff);
838 void xics_kexec_teardown_cpu(int secondary)
840 xics_teardown_cpu();
843 * we take the ipi irq but and never return so we
844 * need to EOI the IPI, but want to leave our priority 0
846 * should we check all the other interrupts too?
847 * should we be flagging idle loop instead?
848 * or creating some task to be scheduled?
851 if (firmware_has_feature(FW_FEATURE_LPAR))
852 lpar_xirr_info_set((0x00 << 24) | XICS_IPI);
853 else
854 direct_xirr_info_set((0x00 << 24) | XICS_IPI);
857 * Some machines need to have at least one cpu in the GIQ,
858 * so leave the master cpu in the group.
860 if (secondary)
861 xics_set_cpu_giq(default_distrib_server, 0);
864 #ifdef CONFIG_HOTPLUG_CPU
866 /* Interrupts are disabled. */
867 void xics_migrate_irqs_away(void)
869 int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
870 unsigned int irq, virq;
872 /* If we used to be the default server, move to the new "boot_cpuid" */
873 if (hw_cpu == default_server)
874 xics_update_irq_servers();
876 /* Reject any interrupt that was queued to us... */
877 xics_set_cpu_priority(0);
879 /* Remove ourselves from the global interrupt queue */
880 xics_set_cpu_giq(default_distrib_server, 0);
882 /* Allow IPIs again... */
883 xics_set_cpu_priority(DEFAULT_PRIORITY);
885 for_each_irq(virq) {
886 struct irq_desc *desc;
887 int xics_status[2];
888 int status;
889 unsigned long flags;
891 /* We cant set affinity on ISA interrupts */
892 if (virq < NUM_ISA_INTERRUPTS)
893 continue;
894 if (irq_map[virq].host != xics_host)
895 continue;
896 irq = (unsigned int)irq_map[virq].hwirq;
897 /* We need to get IPIs still. */
898 if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
899 continue;
900 desc = irq_to_desc(virq);
902 /* We only need to migrate enabled IRQS */
903 if (desc == NULL || desc->chip == NULL
904 || desc->action == NULL
905 || desc->chip->set_affinity == NULL)
906 continue;
908 raw_spin_lock_irqsave(&desc->lock, flags);
910 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
911 if (status) {
912 printk(KERN_ERR "%s: ibm,get-xive irq=%u returns %d\n",
913 __func__, irq, status);
914 goto unlock;
918 * We only support delivery to all cpus or to one cpu.
919 * The irq has to be migrated only in the single cpu
920 * case.
922 if (xics_status[0] != hw_cpu)
923 goto unlock;
925 /* This is expected during cpu offline. */
926 if (cpu_online(cpu))
927 printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
928 virq, cpu);
930 /* Reset affinity to all cpus */
931 cpumask_setall(irq_to_desc(virq)->affinity);
932 desc->chip->set_affinity(virq, cpu_all_mask);
933 unlock:
934 raw_spin_unlock_irqrestore(&desc->lock, flags);
937 #endif