1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
282fea5a1SVineet Gupta /*
382fea5a1SVineet Gupta * ARC ARConnect (MultiCore IP) support (formerly known as MCIP)
482fea5a1SVineet Gupta *
582fea5a1SVineet Gupta * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
682fea5a1SVineet Gupta */
782fea5a1SVineet Gupta
882fea5a1SVineet Gupta #include <linux/smp.h>
982fea5a1SVineet Gupta #include <linux/irq.h>
10e51d5d02SYuriy Kolerov #include <linux/irqchip/chained_irq.h>
1182fea5a1SVineet Gupta #include <linux/spinlock.h>
122d7f5c48SVineet Gupta #include <soc/arc/mcip.h>
13bb143f81SVineet Gupta #include <asm/irqflags-arcv2.h>
14964cf28fSVineet Gupta #include <asm/setup.h>
1582fea5a1SVineet Gupta
1682fea5a1SVineet Gupta static DEFINE_RAW_SPINLOCK(mcip_lock);
1782fea5a1SVineet Gupta
183ce0fefcSVineet Gupta #ifdef CONFIG_SMP
193ce0fefcSVineet Gupta
203ce0fefcSVineet Gupta static char smp_cpuinfo_buf[128];
213ce0fefcSVineet Gupta
2207423d00SEugeniy Paltsev /*
2307423d00SEugeniy Paltsev * Set mask to halt GFRC if any online core in SMP cluster is halted.
2407423d00SEugeniy Paltsev * Only works for ARC HS v3.0+, on earlier versions has no effect.
2507423d00SEugeniy Paltsev */
mcip_update_gfrc_halt_mask(int cpu)2607423d00SEugeniy Paltsev static void mcip_update_gfrc_halt_mask(int cpu)
2707423d00SEugeniy Paltsev {
2807423d00SEugeniy Paltsev struct bcr_generic gfrc;
2907423d00SEugeniy Paltsev unsigned long flags;
3007423d00SEugeniy Paltsev u32 gfrc_halt_mask;
3107423d00SEugeniy Paltsev
3207423d00SEugeniy Paltsev READ_BCR(ARC_REG_GFRC_BUILD, gfrc);
3307423d00SEugeniy Paltsev
3407423d00SEugeniy Paltsev /*
3507423d00SEugeniy Paltsev * CMD_GFRC_SET_CORE and CMD_GFRC_READ_CORE commands were added in
3607423d00SEugeniy Paltsev * GFRC 0x3 version.
3707423d00SEugeniy Paltsev */
3807423d00SEugeniy Paltsev if (gfrc.ver < 0x3)
3907423d00SEugeniy Paltsev return;
4007423d00SEugeniy Paltsev
4107423d00SEugeniy Paltsev raw_spin_lock_irqsave(&mcip_lock, flags);
4207423d00SEugeniy Paltsev
4307423d00SEugeniy Paltsev __mcip_cmd(CMD_GFRC_READ_CORE, 0);
4407423d00SEugeniy Paltsev gfrc_halt_mask = read_aux_reg(ARC_REG_MCIP_READBACK);
4507423d00SEugeniy Paltsev gfrc_halt_mask |= BIT(cpu);
4607423d00SEugeniy Paltsev __mcip_cmd_data(CMD_GFRC_SET_CORE, 0, gfrc_halt_mask);
4707423d00SEugeniy Paltsev
4807423d00SEugeniy Paltsev raw_spin_unlock_irqrestore(&mcip_lock, flags);
4907423d00SEugeniy Paltsev }
5007423d00SEugeniy Paltsev
mcip_update_debug_halt_mask(int cpu)51f3205de9SEugeniy Paltsev static void mcip_update_debug_halt_mask(int cpu)
52f3205de9SEugeniy Paltsev {
53f3205de9SEugeniy Paltsev u32 mcip_mask = 0;
54f3205de9SEugeniy Paltsev unsigned long flags;
55f3205de9SEugeniy Paltsev
56f3205de9SEugeniy Paltsev raw_spin_lock_irqsave(&mcip_lock, flags);
57f3205de9SEugeniy Paltsev
58f3205de9SEugeniy Paltsev /*
59f3205de9SEugeniy Paltsev * mcip_mask is same for CMD_DEBUG_SET_SELECT and CMD_DEBUG_SET_MASK
60f3205de9SEugeniy Paltsev * commands. So read it once instead of reading both CMD_DEBUG_READ_MASK
61f3205de9SEugeniy Paltsev * and CMD_DEBUG_READ_SELECT.
62f3205de9SEugeniy Paltsev */
63f3205de9SEugeniy Paltsev __mcip_cmd(CMD_DEBUG_READ_SELECT, 0);
64f3205de9SEugeniy Paltsev mcip_mask = read_aux_reg(ARC_REG_MCIP_READBACK);
65f3205de9SEugeniy Paltsev
66f3205de9SEugeniy Paltsev mcip_mask |= BIT(cpu);
67f3205de9SEugeniy Paltsev
68f3205de9SEugeniy Paltsev __mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, mcip_mask);
69f3205de9SEugeniy Paltsev /*
70f3205de9SEugeniy Paltsev * Parameter specified halt cause:
71f3205de9SEugeniy Paltsev * STATUS32[H]/actionpoint/breakpoint/self-halt
72f3205de9SEugeniy Paltsev * We choose all of them (0xF).
73f3205de9SEugeniy Paltsev */
74f3205de9SEugeniy Paltsev __mcip_cmd_data(CMD_DEBUG_SET_MASK, 0xF, mcip_mask);
75f3205de9SEugeniy Paltsev
76f3205de9SEugeniy Paltsev raw_spin_unlock_irqrestore(&mcip_lock, flags);
77f3205de9SEugeniy Paltsev }
78f3205de9SEugeniy Paltsev
mcip_setup_per_cpu(int cpu)79aa0efcdeSVineet Gupta static void mcip_setup_per_cpu(int cpu)
8082fea5a1SVineet Gupta {
8107423d00SEugeniy Paltsev struct mcip_bcr mp;
8207423d00SEugeniy Paltsev
8307423d00SEugeniy Paltsev READ_BCR(ARC_REG_MCIP_BCR, mp);
8407423d00SEugeniy Paltsev
8582fea5a1SVineet Gupta smp_ipi_irq_setup(cpu, IPI_IRQ);
86bb143f81SVineet Gupta smp_ipi_irq_setup(cpu, SOFTIRQ_IRQ);
8707423d00SEugeniy Paltsev
8807423d00SEugeniy Paltsev /* Update GFRC halt mask as new CPU came online */
8907423d00SEugeniy Paltsev if (mp.gfrc)
9007423d00SEugeniy Paltsev mcip_update_gfrc_halt_mask(cpu);
91f3205de9SEugeniy Paltsev
92f3205de9SEugeniy Paltsev /* Update MCIP debug mask as new CPU came online */
93f3205de9SEugeniy Paltsev if (mp.dbg)
94f3205de9SEugeniy Paltsev mcip_update_debug_halt_mask(cpu);
9582fea5a1SVineet Gupta }
9682fea5a1SVineet Gupta
mcip_ipi_send(int cpu)9782fea5a1SVineet Gupta static void mcip_ipi_send(int cpu)
9882fea5a1SVineet Gupta {
9982fea5a1SVineet Gupta unsigned long flags;
100aa6083edSVineet Gupta int ipi_was_pending;
10182fea5a1SVineet Gupta
102bb143f81SVineet Gupta /* ARConnect can only send IPI to others */
103bb143f81SVineet Gupta if (unlikely(cpu == raw_smp_processor_id())) {
104bb143f81SVineet Gupta arc_softirq_trigger(SOFTIRQ_IRQ);
105bb143f81SVineet Gupta return;
106bb143f81SVineet Gupta }
107bb143f81SVineet Gupta
10882fea5a1SVineet Gupta raw_spin_lock_irqsave(&mcip_lock, flags);
1093dea30caSVineet Gupta
1103dea30caSVineet Gupta /*
1113dea30caSVineet Gupta * If receiver already has a pending interrupt, elide sending this one.
1123dea30caSVineet Gupta * Linux cross core calling works well with concurrent IPIs
1133dea30caSVineet Gupta * coalesced into one
1143dea30caSVineet Gupta * see arch/arc/kernel/smp.c: ipi_send_msg_one()
1153dea30caSVineet Gupta */
116aa6083edSVineet Gupta __mcip_cmd(CMD_INTRPT_READ_STATUS, cpu);
117aa6083edSVineet Gupta ipi_was_pending = read_aux_reg(ARC_REG_MCIP_READBACK);
1183dea30caSVineet Gupta if (!ipi_was_pending)
11982fea5a1SVineet Gupta __mcip_cmd(CMD_INTRPT_GENERATE_IRQ, cpu);
1203dea30caSVineet Gupta
12182fea5a1SVineet Gupta raw_spin_unlock_irqrestore(&mcip_lock, flags);
12282fea5a1SVineet Gupta }
12382fea5a1SVineet Gupta
mcip_ipi_clear(int irq)12482fea5a1SVineet Gupta static void mcip_ipi_clear(int irq)
12582fea5a1SVineet Gupta {
126aa6083edSVineet Gupta unsigned int cpu, c;
12782fea5a1SVineet Gupta unsigned long flags;
12882fea5a1SVineet Gupta
129bb143f81SVineet Gupta if (unlikely(irq == SOFTIRQ_IRQ)) {
130bb143f81SVineet Gupta arc_softirq_clear(irq);
131bb143f81SVineet Gupta return;
132bb143f81SVineet Gupta }
133bb143f81SVineet Gupta
13482fea5a1SVineet Gupta raw_spin_lock_irqsave(&mcip_lock, flags);
13582fea5a1SVineet Gupta
13682fea5a1SVineet Gupta /* Who sent the IPI */
13782fea5a1SVineet Gupta __mcip_cmd(CMD_INTRPT_CHECK_SOURCE, 0);
13882fea5a1SVineet Gupta
139d73b73f5SVineet Gupta cpu = read_aux_reg(ARC_REG_MCIP_READBACK); /* 1,2,4,8... */
14082fea5a1SVineet Gupta
141aa6083edSVineet Gupta /*
142aa6083edSVineet Gupta * In rare case, multiple concurrent IPIs sent to same target can
143aa6083edSVineet Gupta * possibly be coalesced by MCIP into 1 asserted IRQ, so @cpus can be
144aa6083edSVineet Gupta * "vectored" (multiple bits sets) as opposed to typical single bit
145aa6083edSVineet Gupta */
146aa6083edSVineet Gupta do {
147aa6083edSVineet Gupta c = __ffs(cpu); /* 0,1,2,3 */
148aa6083edSVineet Gupta __mcip_cmd(CMD_INTRPT_GENERATE_ACK, c);
149aa6083edSVineet Gupta cpu &= ~(1U << c);
150aa6083edSVineet Gupta } while (cpu);
15182fea5a1SVineet Gupta
15282fea5a1SVineet Gupta raw_spin_unlock_irqrestore(&mcip_lock, flags);
15382fea5a1SVineet Gupta }
15482fea5a1SVineet Gupta
mcip_probe_n_setup(void)15526b8f996SVineet Gupta static void mcip_probe_n_setup(void)
15682fea5a1SVineet Gupta {
1573ce0fefcSVineet Gupta struct mcip_bcr mp;
15882fea5a1SVineet Gupta
15982fea5a1SVineet Gupta READ_BCR(ARC_REG_MCIP_BCR, mp);
16082fea5a1SVineet Gupta
16182fea5a1SVineet Gupta sprintf(smp_cpuinfo_buf,
162517e7610SVineet Gupta "Extn [SMP]\t: ARConnect (v%d): %d cores with %s%s%s%s\n",
16382fea5a1SVineet Gupta mp.ver, mp.num_cores,
16482fea5a1SVineet Gupta IS_AVAIL1(mp.ipi, "IPI "),
16582fea5a1SVineet Gupta IS_AVAIL1(mp.idu, "IDU "),
16682fea5a1SVineet Gupta IS_AVAIL1(mp.dbg, "DEBUG "),
167d584f0fbSVineet Gupta IS_AVAIL1(mp.gfrc, "GFRC"));
16882fea5a1SVineet Gupta }
169eaf0ecc3SVineet Gupta
17026b8f996SVineet Gupta struct plat_smp_ops plat_smp_ops = {
17126b8f996SVineet Gupta .info = smp_cpuinfo_buf,
17226b8f996SVineet Gupta .init_early_smp = mcip_probe_n_setup,
173b474a023SNoam Camus .init_per_cpu = mcip_setup_per_cpu,
17426b8f996SVineet Gupta .ipi_send = mcip_ipi_send,
17526b8f996SVineet Gupta .ipi_clear = mcip_ipi_clear,
17626b8f996SVineet Gupta };
17726b8f996SVineet Gupta
1783ce0fefcSVineet Gupta #endif
1793ce0fefcSVineet Gupta
180eaf0ecc3SVineet Gupta /***************************************************************************
181eaf0ecc3SVineet Gupta * ARCv2 Interrupt Distribution Unit (IDU)
182eaf0ecc3SVineet Gupta *
183eaf0ecc3SVineet Gupta * Connects external "COMMON" IRQs to core intc, providing:
184eaf0ecc3SVineet Gupta * -dynamic routing (IRQ affinity)
185eaf0ecc3SVineet Gupta * -load balancing (Round Robin interrupt distribution)
186eaf0ecc3SVineet Gupta * -1:N distribution
187eaf0ecc3SVineet Gupta *
188eaf0ecc3SVineet Gupta * It physically resides in the MCIP hw block
189eaf0ecc3SVineet Gupta */
190eaf0ecc3SVineet Gupta
191eaf0ecc3SVineet Gupta #include <linux/irqchip.h>
192eaf0ecc3SVineet Gupta #include <linux/of.h>
193eaf0ecc3SVineet Gupta #include <linux/of_irq.h>
194eaf0ecc3SVineet Gupta
195eaf0ecc3SVineet Gupta /*
196eaf0ecc3SVineet Gupta * Set the DEST for @cmn_irq to @cpu_mask (1 bit per core)
197eaf0ecc3SVineet Gupta */
idu_set_dest(unsigned int cmn_irq,unsigned int cpu_mask)198eaf0ecc3SVineet Gupta static void idu_set_dest(unsigned int cmn_irq, unsigned int cpu_mask)
199eaf0ecc3SVineet Gupta {
200eaf0ecc3SVineet Gupta __mcip_cmd_data(CMD_IDU_SET_DEST, cmn_irq, cpu_mask);
201eaf0ecc3SVineet Gupta }
202eaf0ecc3SVineet Gupta
idu_set_mode(unsigned int cmn_irq,bool set_lvl,unsigned int lvl,bool set_distr,unsigned int distr)203174ae4e9SMischa Jonker static void idu_set_mode(unsigned int cmn_irq, bool set_lvl, unsigned int lvl,
204174ae4e9SMischa Jonker bool set_distr, unsigned int distr)
205eaf0ecc3SVineet Gupta {
206eaf0ecc3SVineet Gupta union {
207eaf0ecc3SVineet Gupta unsigned int word;
208eaf0ecc3SVineet Gupta struct {
209eaf0ecc3SVineet Gupta unsigned int distr:2, pad:2, lvl:1, pad2:27;
210eaf0ecc3SVineet Gupta };
211eaf0ecc3SVineet Gupta } data;
212eaf0ecc3SVineet Gupta
213174ae4e9SMischa Jonker data.word = __mcip_cmd_read(CMD_IDU_READ_MODE, cmn_irq);
214174ae4e9SMischa Jonker if (set_distr)
215eaf0ecc3SVineet Gupta data.distr = distr;
216174ae4e9SMischa Jonker if (set_lvl)
217eaf0ecc3SVineet Gupta data.lvl = lvl;
218eaf0ecc3SVineet Gupta __mcip_cmd_data(CMD_IDU_SET_MODE, cmn_irq, data.word);
219eaf0ecc3SVineet Gupta }
220eaf0ecc3SVineet Gupta
idu_irq_mask_raw(irq_hw_number_t hwirq)221fc73965eSYuriy Kolerov static void idu_irq_mask_raw(irq_hw_number_t hwirq)
222eaf0ecc3SVineet Gupta {
223eaf0ecc3SVineet Gupta unsigned long flags;
224eaf0ecc3SVineet Gupta
225eaf0ecc3SVineet Gupta raw_spin_lock_irqsave(&mcip_lock, flags);
226fc73965eSYuriy Kolerov __mcip_cmd_data(CMD_IDU_SET_MASK, hwirq, 1);
227eaf0ecc3SVineet Gupta raw_spin_unlock_irqrestore(&mcip_lock, flags);
228eaf0ecc3SVineet Gupta }
229eaf0ecc3SVineet Gupta
idu_irq_mask(struct irq_data * data)230fc73965eSYuriy Kolerov static void idu_irq_mask(struct irq_data *data)
231fc73965eSYuriy Kolerov {
232fc73965eSYuriy Kolerov idu_irq_mask_raw(data->hwirq);
233fc73965eSYuriy Kolerov }
234fc73965eSYuriy Kolerov
idu_irq_unmask(struct irq_data * data)235eaf0ecc3SVineet Gupta static void idu_irq_unmask(struct irq_data *data)
236eaf0ecc3SVineet Gupta {
237eaf0ecc3SVineet Gupta unsigned long flags;
238eaf0ecc3SVineet Gupta
239eaf0ecc3SVineet Gupta raw_spin_lock_irqsave(&mcip_lock, flags);
240eaf0ecc3SVineet Gupta __mcip_cmd_data(CMD_IDU_SET_MASK, data->hwirq, 0);
241eaf0ecc3SVineet Gupta raw_spin_unlock_irqrestore(&mcip_lock, flags);
242eaf0ecc3SVineet Gupta }
243eaf0ecc3SVineet Gupta
idu_irq_ack(struct irq_data * data)244174ae4e9SMischa Jonker static void idu_irq_ack(struct irq_data *data)
245174ae4e9SMischa Jonker {
246174ae4e9SMischa Jonker unsigned long flags;
247174ae4e9SMischa Jonker
248174ae4e9SMischa Jonker raw_spin_lock_irqsave(&mcip_lock, flags);
249174ae4e9SMischa Jonker __mcip_cmd(CMD_IDU_ACK_CIRQ, data->hwirq);
250174ae4e9SMischa Jonker raw_spin_unlock_irqrestore(&mcip_lock, flags);
251174ae4e9SMischa Jonker }
252174ae4e9SMischa Jonker
idu_irq_mask_ack(struct irq_data * data)253174ae4e9SMischa Jonker static void idu_irq_mask_ack(struct irq_data *data)
254174ae4e9SMischa Jonker {
255174ae4e9SMischa Jonker unsigned long flags;
256174ae4e9SMischa Jonker
257174ae4e9SMischa Jonker raw_spin_lock_irqsave(&mcip_lock, flags);
258174ae4e9SMischa Jonker __mcip_cmd_data(CMD_IDU_SET_MASK, data->hwirq, 1);
259174ae4e9SMischa Jonker __mcip_cmd(CMD_IDU_ACK_CIRQ, data->hwirq);
260174ae4e9SMischa Jonker raw_spin_unlock_irqrestore(&mcip_lock, flags);
261174ae4e9SMischa Jonker }
262174ae4e9SMischa Jonker
263eaf0ecc3SVineet Gupta static int
idu_irq_set_affinity(struct irq_data * data,const struct cpumask * cpumask,bool force)26483ce3e6fSVineet Gupta idu_irq_set_affinity(struct irq_data *data, const struct cpumask *cpumask,
26583ce3e6fSVineet Gupta bool force)
266eaf0ecc3SVineet Gupta {
26783ce3e6fSVineet Gupta unsigned long flags;
26883ce3e6fSVineet Gupta cpumask_t online;
2690a0a047dSYuriy Kolerov unsigned int destination_bits;
2700a0a047dSYuriy Kolerov unsigned int distribution_mode;
27183ce3e6fSVineet Gupta
27283ce3e6fSVineet Gupta /* errout if no online cpu per @cpumask */
27383ce3e6fSVineet Gupta if (!cpumask_and(&online, cpumask, cpu_online_mask))
27483ce3e6fSVineet Gupta return -EINVAL;
27583ce3e6fSVineet Gupta
27683ce3e6fSVineet Gupta raw_spin_lock_irqsave(&mcip_lock, flags);
27783ce3e6fSVineet Gupta
2780a0a047dSYuriy Kolerov destination_bits = cpumask_bits(&online)[0];
2790a0a047dSYuriy Kolerov idu_set_dest(data->hwirq, destination_bits);
2800a0a047dSYuriy Kolerov
2810a0a047dSYuriy Kolerov if (ffs(destination_bits) == fls(destination_bits))
2820a0a047dSYuriy Kolerov distribution_mode = IDU_M_DISTRI_DEST;
2830a0a047dSYuriy Kolerov else
2840a0a047dSYuriy Kolerov distribution_mode = IDU_M_DISTRI_RR;
2850a0a047dSYuriy Kolerov
286174ae4e9SMischa Jonker idu_set_mode(data->hwirq, false, 0, true, distribution_mode);
28783ce3e6fSVineet Gupta
28883ce3e6fSVineet Gupta raw_spin_unlock_irqrestore(&mcip_lock, flags);
28983ce3e6fSVineet Gupta
290eaf0ecc3SVineet Gupta return IRQ_SET_MASK_OK;
291eaf0ecc3SVineet Gupta }
29292fdb527SYuriy Kolerov
idu_irq_set_type(struct irq_data * data,u32 type)293174ae4e9SMischa Jonker static int idu_irq_set_type(struct irq_data *data, u32 type)
294174ae4e9SMischa Jonker {
295174ae4e9SMischa Jonker unsigned long flags;
296174ae4e9SMischa Jonker
297174ae4e9SMischa Jonker /*
298174ae4e9SMischa Jonker * ARCv2 IDU HW does not support inverse polarity, so these are the
299174ae4e9SMischa Jonker * only interrupt types supported.
300174ae4e9SMischa Jonker */
301174ae4e9SMischa Jonker if (type & ~(IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_HIGH))
302174ae4e9SMischa Jonker return -EINVAL;
303174ae4e9SMischa Jonker
304174ae4e9SMischa Jonker raw_spin_lock_irqsave(&mcip_lock, flags);
305174ae4e9SMischa Jonker
306174ae4e9SMischa Jonker idu_set_mode(data->hwirq, true,
307174ae4e9SMischa Jonker type & IRQ_TYPE_EDGE_RISING ? IDU_M_TRIG_EDGE :
308174ae4e9SMischa Jonker IDU_M_TRIG_LEVEL,
309174ae4e9SMischa Jonker false, 0);
310174ae4e9SMischa Jonker
311174ae4e9SMischa Jonker raw_spin_unlock_irqrestore(&mcip_lock, flags);
312174ae4e9SMischa Jonker
313174ae4e9SMischa Jonker return 0;
314174ae4e9SMischa Jonker }
315174ae4e9SMischa Jonker
idu_irq_enable(struct irq_data * data)31692fdb527SYuriy Kolerov static void idu_irq_enable(struct irq_data *data)
31792fdb527SYuriy Kolerov {
31892fdb527SYuriy Kolerov /*
31992fdb527SYuriy Kolerov * By default send all common interrupts to all available online CPUs.
32092fdb527SYuriy Kolerov * The affinity of common interrupts in IDU must be set manually since
32192fdb527SYuriy Kolerov * in some cases the kernel will not call irq_set_affinity() by itself:
32292fdb527SYuriy Kolerov * 1. When the kernel is not configured with support of SMP.
32392fdb527SYuriy Kolerov * 2. When the kernel is configured with support of SMP but upper
32492fdb527SYuriy Kolerov * interrupt controllers does not support setting of the affinity
32592fdb527SYuriy Kolerov * and cannot propagate it to IDU.
32692fdb527SYuriy Kolerov */
32792fdb527SYuriy Kolerov idu_irq_set_affinity(data, cpu_online_mask, false);
32892fdb527SYuriy Kolerov idu_irq_unmask(data);
32992fdb527SYuriy Kolerov }
330eaf0ecc3SVineet Gupta
331eaf0ecc3SVineet Gupta static struct irq_chip idu_irq_chip = {
332eaf0ecc3SVineet Gupta .name = "MCIP IDU Intc",
333eaf0ecc3SVineet Gupta .irq_mask = idu_irq_mask,
334eaf0ecc3SVineet Gupta .irq_unmask = idu_irq_unmask,
335174ae4e9SMischa Jonker .irq_ack = idu_irq_ack,
336174ae4e9SMischa Jonker .irq_mask_ack = idu_irq_mask_ack,
33792fdb527SYuriy Kolerov .irq_enable = idu_irq_enable,
338174ae4e9SMischa Jonker .irq_set_type = idu_irq_set_type,
339eaf0ecc3SVineet Gupta #ifdef CONFIG_SMP
340eaf0ecc3SVineet Gupta .irq_set_affinity = idu_irq_set_affinity,
341eaf0ecc3SVineet Gupta #endif
342eaf0ecc3SVineet Gupta
343eaf0ecc3SVineet Gupta };
344eaf0ecc3SVineet Gupta
idu_cascade_isr(struct irq_desc * desc)345bd0b9ac4SThomas Gleixner static void idu_cascade_isr(struct irq_desc *desc)
346eaf0ecc3SVineet Gupta {
34734e71e4cSYuriy Kolerov struct irq_domain *idu_domain = irq_desc_get_handler_data(desc);
348e51d5d02SYuriy Kolerov struct irq_chip *core_chip = irq_desc_get_chip(desc);
34934e71e4cSYuriy Kolerov irq_hw_number_t core_hwirq = irqd_to_hwirq(irq_desc_get_irq_data(desc));
3506f0310a1SYuriy Kolerov irq_hw_number_t idu_hwirq = core_hwirq - FIRST_EXT_IRQ;
351eaf0ecc3SVineet Gupta
352e51d5d02SYuriy Kolerov chained_irq_enter(core_chip, desc);
353*c9604dddSMarc Zyngier generic_handle_domain_irq(idu_domain, idu_hwirq);
354e51d5d02SYuriy Kolerov chained_irq_exit(core_chip, desc);
355eaf0ecc3SVineet Gupta }
356eaf0ecc3SVineet Gupta
idu_irq_map(struct irq_domain * d,unsigned int virq,irq_hw_number_t hwirq)357eaf0ecc3SVineet Gupta static int idu_irq_map(struct irq_domain *d, unsigned int virq, irq_hw_number_t hwirq)
358eaf0ecc3SVineet Gupta {
359eaf0ecc3SVineet Gupta irq_set_chip_and_handler(virq, &idu_irq_chip, handle_level_irq);
360eaf0ecc3SVineet Gupta irq_set_status_flags(virq, IRQ_MOVE_PCNTXT);
361eaf0ecc3SVineet Gupta
362eaf0ecc3SVineet Gupta return 0;
363eaf0ecc3SVineet Gupta }
364eaf0ecc3SVineet Gupta
365eaf0ecc3SVineet Gupta static const struct irq_domain_ops idu_irq_ops = {
366174ae4e9SMischa Jonker .xlate = irq_domain_xlate_onetwocell,
367eaf0ecc3SVineet Gupta .map = idu_irq_map,
368eaf0ecc3SVineet Gupta };
369eaf0ecc3SVineet Gupta
370eaf0ecc3SVineet Gupta /*
371eaf0ecc3SVineet Gupta * [16, 23]: Statically assigned always private-per-core (Timers, WDT, IPI)
372eaf0ecc3SVineet Gupta * [24, 23+C]: If C > 0 then "C" common IRQs
373eaf0ecc3SVineet Gupta * [24+C, N]: Not statically assigned, private-per-core
374eaf0ecc3SVineet Gupta */
375eaf0ecc3SVineet Gupta
376eaf0ecc3SVineet Gupta
377eaf0ecc3SVineet Gupta static int __init
idu_of_init(struct device_node * intc,struct device_node * parent)378eaf0ecc3SVineet Gupta idu_of_init(struct device_node *intc, struct device_node *parent)
379eaf0ecc3SVineet Gupta {
380eaf0ecc3SVineet Gupta struct irq_domain *domain;
3816f0310a1SYuriy Kolerov int nr_irqs;
38234e71e4cSYuriy Kolerov int i, virq;
3833ce0fefcSVineet Gupta struct mcip_bcr mp;
3846f0310a1SYuriy Kolerov struct mcip_idu_bcr idu_bcr;
385eaf0ecc3SVineet Gupta
3863ce0fefcSVineet Gupta READ_BCR(ARC_REG_MCIP_BCR, mp);
3873ce0fefcSVineet Gupta
3883ce0fefcSVineet Gupta if (!mp.idu)
389eaf0ecc3SVineet Gupta panic("IDU not detected, but DeviceTree using it");
390eaf0ecc3SVineet Gupta
3916f0310a1SYuriy Kolerov READ_BCR(ARC_REG_MCIP_IDU_BCR, idu_bcr);
3926f0310a1SYuriy Kolerov nr_irqs = mcip_idu_bcr_to_nr_irqs(idu_bcr);
3936f0310a1SYuriy Kolerov
3946f0310a1SYuriy Kolerov pr_info("MCIP: IDU supports %u common irqs\n", nr_irqs);
395eaf0ecc3SVineet Gupta
396eaf0ecc3SVineet Gupta domain = irq_domain_add_linear(intc, nr_irqs, &idu_irq_ops, NULL);
397eaf0ecc3SVineet Gupta
398eaf0ecc3SVineet Gupta /* Parent interrupts (core-intc) are already mapped */
399eaf0ecc3SVineet Gupta
400eaf0ecc3SVineet Gupta for (i = 0; i < nr_irqs; i++) {
401fc73965eSYuriy Kolerov /* Mask all common interrupts by default */
402fc73965eSYuriy Kolerov idu_irq_mask_raw(i);
403fc73965eSYuriy Kolerov
404eaf0ecc3SVineet Gupta /*
405eaf0ecc3SVineet Gupta * Return parent uplink IRQs (towards core intc) 24,25,.....
406eaf0ecc3SVineet Gupta * this step has been done before already
407eaf0ecc3SVineet Gupta * however we need it to get the parent virq and set IDU handler
408eaf0ecc3SVineet Gupta * as first level isr
409eaf0ecc3SVineet Gupta */
4106f0310a1SYuriy Kolerov virq = irq_create_mapping(NULL, i + FIRST_EXT_IRQ);
4116f0310a1SYuriy Kolerov BUG_ON(!virq);
41234e71e4cSYuriy Kolerov irq_set_chained_handler_and_data(virq, idu_cascade_isr, domain);
413eaf0ecc3SVineet Gupta }
414eaf0ecc3SVineet Gupta
415eaf0ecc3SVineet Gupta __mcip_cmd(CMD_IDU_ENABLE, 0);
416eaf0ecc3SVineet Gupta
417eaf0ecc3SVineet Gupta return 0;
418eaf0ecc3SVineet Gupta }
419eaf0ecc3SVineet Gupta IRQCHIP_DECLARE(arcv2_idu_intc, "snps,archs-idu-intc", idu_of_init);
420