blob: 0706010cc99f676947c90288279c524e96b0caf0 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Marc St-Jean35832e22007-06-14 15:54:47 -06002/*
Anoop P A92592c92011-01-25 13:50:10 +05303 * Copyright 2010 PMC-Sierra, Inc, derived from irq_cpu.c
Marc St-Jean35832e22007-06-14 15:54:47 -06004 *
Anoop P A92592c92011-01-25 13:50:10 +05305 * This file define the irq handler for MSP CIC subsystem interrupts.
Marc St-Jean35832e22007-06-14 15:54:47 -06006 */
7
8#include <linux/init.h>
9#include <linux/interrupt.h>
10#include <linux/kernel.h>
11#include <linux/bitops.h>
David Howellsca4d3e672010-10-07 14:08:54 +010012#include <linux/irq.h>
Marc St-Jean35832e22007-06-14 15:54:47 -060013
Anoop P A92592c92011-01-25 13:50:10 +053014#include <asm/mipsregs.h>
Marc St-Jean35832e22007-06-14 15:54:47 -060015
16#include <msp_cic_int.h>
17#include <msp_regs.h>
18
19/*
Anoop P A92592c92011-01-25 13:50:10 +053020 * External API
Marc St-Jean35832e22007-06-14 15:54:47 -060021 */
Anoop P A92592c92011-01-25 13:50:10 +053022extern void msp_per_irq_init(void);
23extern void msp_per_irq_dispatch(void);
Marc St-Jean35832e22007-06-14 15:54:47 -060024
Marc St-Jean35832e22007-06-14 15:54:47 -060025
26/*
Anoop P A92592c92011-01-25 13:50:10 +053027 * Convenience Macro. Should be somewhere generic.
Marc St-Jean35832e22007-06-14 15:54:47 -060028 */
Anoop P A92592c92011-01-25 13:50:10 +053029#define get_current_vpe() \
30 ((read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) & TCBIND_CURVPE)
31
32#ifdef CONFIG_SMP
33
34#define LOCK_VPE(flags, mtflags) \
35do { \
36 local_irq_save(flags); \
37 mtflags = dmt(); \
38} while (0)
39
40#define UNLOCK_VPE(flags, mtflags) \
41do { \
42 emt(mtflags); \
43 local_irq_restore(flags);\
44} while (0)
45
46#define LOCK_CORE(flags, mtflags) \
47do { \
48 local_irq_save(flags); \
49 mtflags = dvpe(); \
50} while (0)
51
52#define UNLOCK_CORE(flags, mtflags) \
53do { \
54 evpe(mtflags); \
55 local_irq_restore(flags);\
56} while (0)
57
58#else
59
60#define LOCK_VPE(flags, mtflags)
61#define UNLOCK_VPE(flags, mtflags)
62#endif
63
64/* ensure writes to cic are completed */
65static inline void cic_wmb(void)
Marc St-Jean35832e22007-06-14 15:54:47 -060066{
Anoop P A92592c92011-01-25 13:50:10 +053067 const volatile void __iomem *cic_mem = CIC_VPE0_MSK_REG;
68 volatile u32 dummy_read;
69
70 wmb();
71 dummy_read = __raw_readl(cic_mem);
72 dummy_read++;
73}
74
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +000075static void unmask_cic_irq(struct irq_data *d)
Anoop P A92592c92011-01-25 13:50:10 +053076{
77 volatile u32 *cic_msk_reg = CIC_VPE0_MSK_REG;
78 int vpe;
79#ifdef CONFIG_SMP
80 unsigned int mtflags;
81 unsigned long flags;
Marc St-Jean35832e22007-06-14 15:54:47 -060082
83 /*
Anoop P A92592c92011-01-25 13:50:10 +053084 * Make sure we have IRQ affinity. It may have changed while
85 * we were processing the IRQ.
86 */
Jiang Liu5c159422015-07-13 20:45:59 +000087 if (!cpumask_test_cpu(smp_processor_id(),
88 irq_data_get_affinity_mask(d)))
Anoop P A92592c92011-01-25 13:50:10 +053089 return;
90#endif
Marc St-Jean35832e22007-06-14 15:54:47 -060091
Anoop P A92592c92011-01-25 13:50:10 +053092 vpe = get_current_vpe();
93 LOCK_VPE(flags, mtflags);
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +000094 cic_msk_reg[vpe] |= (1 << (d->irq - MSP_CIC_INTBASE));
Anoop P A92592c92011-01-25 13:50:10 +053095 UNLOCK_VPE(flags, mtflags);
96 cic_wmb();
Marc St-Jean35832e22007-06-14 15:54:47 -060097}
98
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +000099static void mask_cic_irq(struct irq_data *d)
Anoop P A92592c92011-01-25 13:50:10 +0530100{
101 volatile u32 *cic_msk_reg = CIC_VPE0_MSK_REG;
102 int vpe = get_current_vpe();
103#ifdef CONFIG_SMP
104 unsigned long flags, mtflags;
105#endif
106 LOCK_VPE(flags, mtflags);
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000107 cic_msk_reg[vpe] &= ~(1 << (d->irq - MSP_CIC_INTBASE));
Anoop P A92592c92011-01-25 13:50:10 +0530108 UNLOCK_VPE(flags, mtflags);
109 cic_wmb();
110}
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000111static void msp_cic_irq_ack(struct irq_data *d)
Anoop P A92592c92011-01-25 13:50:10 +0530112{
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000113 mask_cic_irq(d);
Anoop P A92592c92011-01-25 13:50:10 +0530114 /*
115 * Only really necessary for 18, 16-14 and sometimes 3:0
116 * (since these can be edge sensitive) but it doesn't
117 * hurt for the others
118 */
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000119 *CIC_STS_REG = (1 << (d->irq - MSP_CIC_INTBASE));
Anoop P A92592c92011-01-25 13:50:10 +0530120}
121
Ralf Baechleb6336482014-05-23 16:29:44 +0200122/* Note: Limiting to VSMP. */
Anoop P A92592c92011-01-25 13:50:10 +0530123
124#ifdef CONFIG_MIPS_MT_SMP
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000125static int msp_cic_irq_set_affinity(struct irq_data *d,
126 const struct cpumask *cpumask, bool force)
Anoop P A92592c92011-01-25 13:50:10 +0530127{
128 int cpu;
129 unsigned long flags;
130 unsigned int mtflags;
Stefan Hengelein6fa88d92014-10-19 20:04:26 +0200131 unsigned long imask = (1 << (d->irq - MSP_CIC_INTBASE));
Anoop P A92592c92011-01-25 13:50:10 +0530132 volatile u32 *cic_mask = (volatile u32 *)CIC_VPE0_MSK_REG;
133
134 /* timer balancing should be disabled in kernel code */
Stefan Hengelein6fa88d92014-10-19 20:04:26 +0200135 BUG_ON(d->irq == MSP_INT_VPE0_TIMER || d->irq == MSP_INT_VPE1_TIMER);
Anoop P A92592c92011-01-25 13:50:10 +0530136
137 LOCK_CORE(flags, mtflags);
138 /* enable if any of each VPE's TCs require this IRQ */
139 for_each_online_cpu(cpu) {
140 if (cpumask_test_cpu(cpu, cpumask))
141 cic_mask[cpu] |= imask;
142 else
143 cic_mask[cpu] &= ~imask;
144
145 }
146
147 UNLOCK_CORE(flags, mtflags);
148 return 0;
149
150}
151#endif
152
Marc St-Jean35832e22007-06-14 15:54:47 -0600153static struct irq_chip msp_cic_irq_controller = {
154 .name = "MSP_CIC",
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000155 .irq_mask = mask_cic_irq,
156 .irq_mask_ack = msp_cic_irq_ack,
157 .irq_unmask = unmask_cic_irq,
158 .irq_ack = msp_cic_irq_ack,
Anoop P A92592c92011-01-25 13:50:10 +0530159#ifdef CONFIG_MIPS_MT_SMP
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000160 .irq_set_affinity = msp_cic_irq_set_affinity,
Anoop P A92592c92011-01-25 13:50:10 +0530161#endif
Marc St-Jean35832e22007-06-14 15:54:47 -0600162};
163
Marc St-Jean35832e22007-06-14 15:54:47 -0600164void __init msp_cic_irq_init(void)
165{
166 int i;
Marc St-Jean35832e22007-06-14 15:54:47 -0600167 /* Mask/clear interrupts. */
168 *CIC_VPE0_MSK_REG = 0x00000000;
Anoop P A92592c92011-01-25 13:50:10 +0530169 *CIC_VPE1_MSK_REG = 0x00000000;
Ralf Baechle70342282013-01-22 12:59:30 +0100170 *CIC_STS_REG = 0xFFFFFFFF;
Marc St-Jean35832e22007-06-14 15:54:47 -0600171 /*
Anoop P A92592c92011-01-25 13:50:10 +0530172 * The MSP7120 RG and EVBD boards use IRQ[6:4] for PCI.
173 * These inputs map to EXT_INT_POL[6:4] inside the CIC.
174 * They are to be active low, level sensitive.
175 */
Marc St-Jean35832e22007-06-14 15:54:47 -0600176 *CIC_EXT_CFG_REG &= 0xFFFF8F8F;
Marc St-Jean35832e22007-06-14 15:54:47 -0600177
178 /* initialize all the IRQ descriptors */
Anoop P A92592c92011-01-25 13:50:10 +0530179 for (i = MSP_CIC_INTBASE ; i < MSP_CIC_INTBASE + 32 ; i++) {
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200180 irq_set_chip_and_handler(i, &msp_cic_irq_controller,
Marc St-Jean35832e22007-06-14 15:54:47 -0600181 handle_level_irq);
Anoop P A92592c92011-01-25 13:50:10 +0530182 }
183
184 /* Initialize the PER interrupt sub-system */
185 msp_per_irq_init();
Marc St-Jean35832e22007-06-14 15:54:47 -0600186}
187
Anoop P A92592c92011-01-25 13:50:10 +0530188/* CIC masked by CIC vector processing before dispatch called */
Marc St-Jean35832e22007-06-14 15:54:47 -0600189void msp_cic_irq_dispatch(void)
190{
Anoop P A92592c92011-01-25 13:50:10 +0530191 volatile u32 *cic_msk_reg = (volatile u32 *)CIC_VPE0_MSK_REG;
192 u32 cic_mask;
193 u32 pending;
194 int cic_status = *CIC_STS_REG;
195 cic_mask = cic_msk_reg[get_current_vpe()];
196 pending = cic_status & cic_mask;
197 if (pending & (1 << (MSP_INT_VPE0_TIMER - MSP_CIC_INTBASE))) {
Marc St-Jean35832e22007-06-14 15:54:47 -0600198 do_IRQ(MSP_INT_VPE0_TIMER);
Anoop P A92592c92011-01-25 13:50:10 +0530199 } else if (pending & (1 << (MSP_INT_VPE1_TIMER - MSP_CIC_INTBASE))) {
200 do_IRQ(MSP_INT_VPE1_TIMER);
201 } else if (pending & (1 << (MSP_INT_PER - MSP_CIC_INTBASE))) {
202 msp_per_irq_dispatch();
203 } else if (pending) {
204 do_IRQ(ffs(pending) + MSP_CIC_INTBASE - 1);
205 } else{
206 spurious_interrupt();
Anoop P A92592c92011-01-25 13:50:10 +0530207 }
Marc St-Jean35832e22007-06-14 15:54:47 -0600208}