blob: b8df2f7b3328e61f8fc7d9da9f78b777bf829632 [file] [log] [blame]
Marc St-Jean35832e22007-06-14 15:54:47 -06001/*
Anoop P A92592c92011-01-25 13:50:10 +05302 * Copyright 2010 PMC-Sierra, Inc, derived from irq_cpu.c
Marc St-Jean35832e22007-06-14 15:54:47 -06003 *
Anoop P A92592c92011-01-25 13:50:10 +05304 * This file define the irq handler for MSP CIC subsystem interrupts.
Marc St-Jean35832e22007-06-14 15:54:47 -06005 *
Ralf Baechle70342282013-01-22 12:59:30 +01006 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
Marc St-Jean35832e22007-06-14 15:54:47 -06008 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/init.h>
13#include <linux/interrupt.h>
14#include <linux/kernel.h>
15#include <linux/bitops.h>
David Howellsca4d3e672010-10-07 14:08:54 +010016#include <linux/irq.h>
Marc St-Jean35832e22007-06-14 15:54:47 -060017
Anoop P A92592c92011-01-25 13:50:10 +053018#include <asm/mipsregs.h>
Marc St-Jean35832e22007-06-14 15:54:47 -060019
20#include <msp_cic_int.h>
21#include <msp_regs.h>
22
23/*
Anoop P A92592c92011-01-25 13:50:10 +053024 * External API
Marc St-Jean35832e22007-06-14 15:54:47 -060025 */
Anoop P A92592c92011-01-25 13:50:10 +053026extern void msp_per_irq_init(void);
27extern void msp_per_irq_dispatch(void);
Marc St-Jean35832e22007-06-14 15:54:47 -060028
Marc St-Jean35832e22007-06-14 15:54:47 -060029
30/*
Anoop P A92592c92011-01-25 13:50:10 +053031 * Convenience Macro. Should be somewhere generic.
Marc St-Jean35832e22007-06-14 15:54:47 -060032 */
Anoop P A92592c92011-01-25 13:50:10 +053033#define get_current_vpe() \
34 ((read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) & TCBIND_CURVPE)
35
36#ifdef CONFIG_SMP
37
38#define LOCK_VPE(flags, mtflags) \
39do { \
40 local_irq_save(flags); \
41 mtflags = dmt(); \
42} while (0)
43
44#define UNLOCK_VPE(flags, mtflags) \
45do { \
46 emt(mtflags); \
47 local_irq_restore(flags);\
48} while (0)
49
50#define LOCK_CORE(flags, mtflags) \
51do { \
52 local_irq_save(flags); \
53 mtflags = dvpe(); \
54} while (0)
55
56#define UNLOCK_CORE(flags, mtflags) \
57do { \
58 evpe(mtflags); \
59 local_irq_restore(flags);\
60} while (0)
61
62#else
63
64#define LOCK_VPE(flags, mtflags)
65#define UNLOCK_VPE(flags, mtflags)
66#endif
67
68/* ensure writes to cic are completed */
69static inline void cic_wmb(void)
Marc St-Jean35832e22007-06-14 15:54:47 -060070{
Anoop P A92592c92011-01-25 13:50:10 +053071 const volatile void __iomem *cic_mem = CIC_VPE0_MSK_REG;
72 volatile u32 dummy_read;
73
74 wmb();
75 dummy_read = __raw_readl(cic_mem);
76 dummy_read++;
77}
78
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +000079static void unmask_cic_irq(struct irq_data *d)
Anoop P A92592c92011-01-25 13:50:10 +053080{
81 volatile u32 *cic_msk_reg = CIC_VPE0_MSK_REG;
82 int vpe;
83#ifdef CONFIG_SMP
84 unsigned int mtflags;
85 unsigned long flags;
Marc St-Jean35832e22007-06-14 15:54:47 -060086
87 /*
Anoop P A92592c92011-01-25 13:50:10 +053088 * Make sure we have IRQ affinity. It may have changed while
89 * we were processing the IRQ.
90 */
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +000091 if (!cpumask_test_cpu(smp_processor_id(), d->affinity))
Anoop P A92592c92011-01-25 13:50:10 +053092 return;
93#endif
Marc St-Jean35832e22007-06-14 15:54:47 -060094
Anoop P A92592c92011-01-25 13:50:10 +053095 vpe = get_current_vpe();
96 LOCK_VPE(flags, mtflags);
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +000097 cic_msk_reg[vpe] |= (1 << (d->irq - MSP_CIC_INTBASE));
Anoop P A92592c92011-01-25 13:50:10 +053098 UNLOCK_VPE(flags, mtflags);
99 cic_wmb();
Marc St-Jean35832e22007-06-14 15:54:47 -0600100}
101
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000102static void mask_cic_irq(struct irq_data *d)
Anoop P A92592c92011-01-25 13:50:10 +0530103{
104 volatile u32 *cic_msk_reg = CIC_VPE0_MSK_REG;
105 int vpe = get_current_vpe();
106#ifdef CONFIG_SMP
107 unsigned long flags, mtflags;
108#endif
109 LOCK_VPE(flags, mtflags);
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000110 cic_msk_reg[vpe] &= ~(1 << (d->irq - MSP_CIC_INTBASE));
Anoop P A92592c92011-01-25 13:50:10 +0530111 UNLOCK_VPE(flags, mtflags);
112 cic_wmb();
113}
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000114static void msp_cic_irq_ack(struct irq_data *d)
Anoop P A92592c92011-01-25 13:50:10 +0530115{
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000116 mask_cic_irq(d);
Anoop P A92592c92011-01-25 13:50:10 +0530117 /*
118 * Only really necessary for 18, 16-14 and sometimes 3:0
119 * (since these can be edge sensitive) but it doesn't
120 * hurt for the others
121 */
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000122 *CIC_STS_REG = (1 << (d->irq - MSP_CIC_INTBASE));
Anoop P A92592c92011-01-25 13:50:10 +0530123}
124
Ralf Baechleb633648c52014-05-23 16:29:44 +0200125/* Note: Limiting to VSMP. */
Anoop P A92592c92011-01-25 13:50:10 +0530126
127#ifdef CONFIG_MIPS_MT_SMP
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000128static int msp_cic_irq_set_affinity(struct irq_data *d,
129 const struct cpumask *cpumask, bool force)
Anoop P A92592c92011-01-25 13:50:10 +0530130{
131 int cpu;
132 unsigned long flags;
133 unsigned int mtflags;
134 unsigned long imask = (1 << (irq - MSP_CIC_INTBASE));
135 volatile u32 *cic_mask = (volatile u32 *)CIC_VPE0_MSK_REG;
136
137 /* timer balancing should be disabled in kernel code */
138 BUG_ON(irq == MSP_INT_VPE0_TIMER || irq == MSP_INT_VPE1_TIMER);
139
140 LOCK_CORE(flags, mtflags);
141 /* enable if any of each VPE's TCs require this IRQ */
142 for_each_online_cpu(cpu) {
143 if (cpumask_test_cpu(cpu, cpumask))
144 cic_mask[cpu] |= imask;
145 else
146 cic_mask[cpu] &= ~imask;
147
148 }
149
150 UNLOCK_CORE(flags, mtflags);
151 return 0;
152
153}
154#endif
155
Marc St-Jean35832e22007-06-14 15:54:47 -0600156static struct irq_chip msp_cic_irq_controller = {
157 .name = "MSP_CIC",
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000158 .irq_mask = mask_cic_irq,
159 .irq_mask_ack = msp_cic_irq_ack,
160 .irq_unmask = unmask_cic_irq,
161 .irq_ack = msp_cic_irq_ack,
Anoop P A92592c92011-01-25 13:50:10 +0530162#ifdef CONFIG_MIPS_MT_SMP
Thomas Gleixnerd7881fb2011-03-23 21:09:06 +0000163 .irq_set_affinity = msp_cic_irq_set_affinity,
Anoop P A92592c92011-01-25 13:50:10 +0530164#endif
Marc St-Jean35832e22007-06-14 15:54:47 -0600165};
166
Marc St-Jean35832e22007-06-14 15:54:47 -0600167void __init msp_cic_irq_init(void)
168{
169 int i;
Marc St-Jean35832e22007-06-14 15:54:47 -0600170 /* Mask/clear interrupts. */
171 *CIC_VPE0_MSK_REG = 0x00000000;
Anoop P A92592c92011-01-25 13:50:10 +0530172 *CIC_VPE1_MSK_REG = 0x00000000;
Ralf Baechle70342282013-01-22 12:59:30 +0100173 *CIC_STS_REG = 0xFFFFFFFF;
Marc St-Jean35832e22007-06-14 15:54:47 -0600174 /*
Anoop P A92592c92011-01-25 13:50:10 +0530175 * The MSP7120 RG and EVBD boards use IRQ[6:4] for PCI.
176 * These inputs map to EXT_INT_POL[6:4] inside the CIC.
177 * They are to be active low, level sensitive.
178 */
Marc St-Jean35832e22007-06-14 15:54:47 -0600179 *CIC_EXT_CFG_REG &= 0xFFFF8F8F;
Marc St-Jean35832e22007-06-14 15:54:47 -0600180
181 /* initialize all the IRQ descriptors */
Anoop P A92592c92011-01-25 13:50:10 +0530182 for (i = MSP_CIC_INTBASE ; i < MSP_CIC_INTBASE + 32 ; i++) {
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200183 irq_set_chip_and_handler(i, &msp_cic_irq_controller,
Marc St-Jean35832e22007-06-14 15:54:47 -0600184 handle_level_irq);
Anoop P A92592c92011-01-25 13:50:10 +0530185 }
186
187 /* Initialize the PER interrupt sub-system */
188 msp_per_irq_init();
Marc St-Jean35832e22007-06-14 15:54:47 -0600189}
190
Anoop P A92592c92011-01-25 13:50:10 +0530191/* CIC masked by CIC vector processing before dispatch called */
Marc St-Jean35832e22007-06-14 15:54:47 -0600192void msp_cic_irq_dispatch(void)
193{
Anoop P A92592c92011-01-25 13:50:10 +0530194 volatile u32 *cic_msk_reg = (volatile u32 *)CIC_VPE0_MSK_REG;
195 u32 cic_mask;
196 u32 pending;
197 int cic_status = *CIC_STS_REG;
198 cic_mask = cic_msk_reg[get_current_vpe()];
199 pending = cic_status & cic_mask;
200 if (pending & (1 << (MSP_INT_VPE0_TIMER - MSP_CIC_INTBASE))) {
Marc St-Jean35832e22007-06-14 15:54:47 -0600201 do_IRQ(MSP_INT_VPE0_TIMER);
Anoop P A92592c92011-01-25 13:50:10 +0530202 } else if (pending & (1 << (MSP_INT_VPE1_TIMER - MSP_CIC_INTBASE))) {
203 do_IRQ(MSP_INT_VPE1_TIMER);
204 } else if (pending & (1 << (MSP_INT_PER - MSP_CIC_INTBASE))) {
205 msp_per_irq_dispatch();
206 } else if (pending) {
207 do_IRQ(ffs(pending) + MSP_CIC_INTBASE - 1);
208 } else{
209 spurious_interrupt();
Anoop P A92592c92011-01-25 13:50:10 +0530210 }
Marc St-Jean35832e22007-06-14 15:54:47 -0600211}