2 * Copyright 2016 IBM Corporation.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/irq.h>
12 #include <linux/smp.h>
13 #include <linux/interrupt.h>
14 #include <linux/cpu.h>
19 #include <asm/errno.h>
24 static void icp_opal_teardown_cpu(void)
26 int cpu = smp_processor_id();
28 /* Clear any pending IPI */
29 opal_int_set_mfrr(cpu, 0xff);
32 static void icp_opal_flush_ipi(void)
35 * We take the ipi irq but and never return so we need to EOI the IPI,
36 * but want to leave our priority 0.
38 * Should we check all the other interrupts too?
39 * Should we be flagging idle loop instead?
40 * Or creating some task to be scheduled?
42 opal_int_eoi((0x00 << 24) | XICS_IPI);
45 static unsigned int icp_opal_get_irq(void)
52 rc = opal_int_get_xirr(&xirr, false);
55 xirr = be32_to_cpu(xirr);
56 vec = xirr & 0x00ffffff;
57 if (vec == XICS_IRQ_SPURIOUS)
60 irq = irq_find_mapping(xics_host, vec);
61 if (likely(irq != NO_IRQ)) {
66 /* We don't have a linux mapping, so have rtas mask it. */
67 xics_mask_unknown_vec(vec);
69 /* We might learn about it later, so EOI it */
75 static void icp_opal_set_cpu_priority(unsigned char cppr)
77 xics_set_base_cppr(cppr);
78 opal_int_set_cppr(cppr);
82 static void icp_opal_eoi(struct irq_data *d)
84 unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
88 rc = opal_int_eoi((xics_pop_cppr() << 24) | hw_irq);
91 * EOI tells us whether there are more interrupts to fetch.
93 * Some HW implementations might not be able to send us another
94 * external interrupt in that case, so we force a replay.
97 force_external_irq_replay();
102 static void icp_opal_cause_ipi(int cpu, unsigned long data)
104 opal_int_set_mfrr(cpu, IPI_PRIORITY);
107 static irqreturn_t icp_opal_ipi_action(int irq, void *dev_id)
109 int cpu = smp_processor_id();
111 opal_int_set_mfrr(cpu, 0xff);
113 return smp_ipi_demux();
116 #endif /* CONFIG_SMP */
118 static const struct icp_ops icp_opal_ops = {
119 .get_irq = icp_opal_get_irq,
121 .set_priority = icp_opal_set_cpu_priority,
122 .teardown_cpu = icp_opal_teardown_cpu,
123 .flush_ipi = icp_opal_flush_ipi,
125 .ipi_action = icp_opal_ipi_action,
126 .cause_ipi = icp_opal_cause_ipi,
130 int icp_opal_init(void)
132 struct device_node *np;
134 np = of_find_compatible_node(NULL, NULL, "ibm,opal-intc");
138 icp_ops = &icp_opal_ops;
140 printk("XICS: Using OPAL ICP fallbacks\n");