msp_irq_cic.c 5.3 KB
Newer Older
M
Marc St-Jean 已提交
1
/*
2
 * Copyright 2010 PMC-Sierra, Inc, derived from irq_cpu.c
M
Marc St-Jean 已提交
3
 *
4
 * This file define the irq handler for MSP CIC subsystem interrupts.
M
Marc St-Jean 已提交
5 6 7 8 9 10 11 12 13 14 15
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/bitops.h>
16
#include <linux/irq.h>
M
Marc St-Jean 已提交
17

18
#include <asm/mipsregs.h>
M
Marc St-Jean 已提交
19 20 21 22 23 24
#include <asm/system.h>

#include <msp_cic_int.h>
#include <msp_regs.h>

/*
25
 * External API
M
Marc St-Jean 已提交
26
 */
27 28
extern void msp_per_irq_init(void);
extern void msp_per_irq_dispatch(void);
M
Marc St-Jean 已提交
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

/*
 * Convenience Macro.  Should be somewhere generic.
 */
#define get_current_vpe()   \
	((read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) & TCBIND_CURVPE)

#ifdef CONFIG_SMP

#define LOCK_VPE(flags, mtflags) \
do {				\
	local_irq_save(flags);	\
	mtflags = dmt();	\
} while (0)

#define UNLOCK_VPE(flags, mtflags) \
do {				\
	emt(mtflags);		\
	local_irq_restore(flags);\
} while (0)

#define LOCK_CORE(flags, mtflags) \
do {				\
	local_irq_save(flags);	\
	mtflags = dvpe();	\
} while (0)

#define UNLOCK_CORE(flags, mtflags)		\
do {				\
	evpe(mtflags);		\
	local_irq_restore(flags);\
} while (0)

#else

#define LOCK_VPE(flags, mtflags)
#define UNLOCK_VPE(flags, mtflags)
#endif

/* ensure writes to cic are completed */
static inline void cic_wmb(void)
M
Marc St-Jean 已提交
71
{
72 73
	const volatile void __iomem *cic_mem = CIC_VPE0_MSK_REG;
	volatile u32 dummy_read;
M
Marc St-Jean 已提交
74

75 76 77
	wmb();
	dummy_read = __raw_readl(cic_mem);
	dummy_read++;
M
Marc St-Jean 已提交
78 79
}

80
static inline void unmask_cic_irq(unsigned int irq)
M
Marc St-Jean 已提交
81
{
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
	volatile u32   *cic_msk_reg = CIC_VPE0_MSK_REG;
	int vpe;
#ifdef CONFIG_SMP
	unsigned int mtflags;
	unsigned long  flags;

	/*
	* Make sure we have IRQ affinity.  It may have changed while
	* we were processing the IRQ.
	*/
	if (!cpumask_test_cpu(smp_processor_id(), irq_desc[irq].affinity))
		return;
#endif

	vpe = get_current_vpe();
	LOCK_VPE(flags, mtflags);
	cic_msk_reg[vpe] |= (1 << (irq - MSP_CIC_INTBASE));
	UNLOCK_VPE(flags, mtflags);
	cic_wmb();
M
Marc St-Jean 已提交
101 102
}

103
static inline void mask_cic_irq(unsigned int irq)
M
Marc St-Jean 已提交
104
{
105 106 107 108 109 110 111 112 113 114 115 116 117
	volatile u32 *cic_msk_reg = CIC_VPE0_MSK_REG;
	int	vpe = get_current_vpe();
#ifdef CONFIG_SMP
	unsigned long flags, mtflags;
#endif
	LOCK_VPE(flags, mtflags);
	cic_msk_reg[vpe] &= ~(1 << (irq - MSP_CIC_INTBASE));
	UNLOCK_VPE(flags, mtflags);
	cic_wmb();
}
static inline void msp_cic_irq_ack(unsigned int irq)
{
	mask_cic_irq(irq);
M
Marc St-Jean 已提交
118
	/*
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
	* Only really necessary for 18, 16-14 and sometimes 3:0
	* (since these can be edge sensitive) but it doesn't
	* hurt for the others
	*/
	*CIC_STS_REG = (1 << (irq - MSP_CIC_INTBASE));
	smtc_im_ack_irq(irq);
}

static void msp_cic_irq_end(unsigned int irq)
{
	if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
		unmask_cic_irq(irq);
}

/*Note: Limiting to VSMP . Not tested in SMTC */

#ifdef CONFIG_MIPS_MT_SMP
static inline int msp_cic_irq_set_affinity(unsigned int irq,
					const struct cpumask *cpumask)
{
	int cpu;
	unsigned long flags;
	unsigned int  mtflags;
	unsigned long imask = (1 << (irq - MSP_CIC_INTBASE));
	volatile u32 *cic_mask = (volatile u32 *)CIC_VPE0_MSK_REG;

	/* timer balancing should be disabled in kernel code */
	BUG_ON(irq == MSP_INT_VPE0_TIMER || irq == MSP_INT_VPE1_TIMER);

	LOCK_CORE(flags, mtflags);
	/* enable if any of each VPE's TCs require this IRQ */
	for_each_online_cpu(cpu) {
		if (cpumask_test_cpu(cpu, cpumask))
			cic_mask[cpu] |= imask;
		else
			cic_mask[cpu] &= ~imask;

	}

	UNLOCK_CORE(flags, mtflags);
	return 0;

M
Marc St-Jean 已提交
161
}
162
#endif
M
Marc St-Jean 已提交
163 164 165

static struct irq_chip msp_cic_irq_controller = {
	.name = "MSP_CIC",
166 167 168 169 170 171 172 173
	.mask = mask_cic_irq,
	.mask_ack = msp_cic_irq_ack,
	.unmask = unmask_cic_irq,
	.ack = msp_cic_irq_ack,
	.end = msp_cic_irq_end,
#ifdef CONFIG_MIPS_MT_SMP
	.set_affinity = msp_cic_irq_set_affinity,
#endif
M
Marc St-Jean 已提交
174 175 176 177 178 179 180
};

void __init msp_cic_irq_init(void)
{
	int i;
	/* Mask/clear interrupts. */
	*CIC_VPE0_MSK_REG = 0x00000000;
181
	*CIC_VPE1_MSK_REG = 0x00000000;
M
Marc St-Jean 已提交
182 183
	*CIC_STS_REG      = 0xFFFFFFFF;
	/*
184 185 186 187
	* The MSP7120 RG and EVBD boards use IRQ[6:4] for PCI.
	* These inputs map to EXT_INT_POL[6:4] inside the CIC.
	* They are to be active low, level sensitive.
	*/
M
Marc St-Jean 已提交
188 189 190
	*CIC_EXT_CFG_REG &= 0xFFFF8F8F;

	/* initialize all the IRQ descriptors */
191
	for (i = MSP_CIC_INTBASE ; i < MSP_CIC_INTBASE + 32 ; i++) {
M
Marc St-Jean 已提交
192 193
		set_irq_chip_and_handler(i, &msp_cic_irq_controller,
					 handle_level_irq);
194 195 196 197 198 199 200 201
#ifdef CONFIG_MIPS_MT_SMTC
		/* Mask of CIC interrupt */
		irq_hwmask[i] = C_IRQ4;
#endif
	}

	/* Initialize the PER interrupt sub-system */
	 msp_per_irq_init();
M
Marc St-Jean 已提交
202 203
}

204
/* CIC masked by CIC vector processing before dispatch called */
M
Marc St-Jean 已提交
205 206
void msp_cic_irq_dispatch(void)
{
207 208 209 210 211 212 213
	volatile u32	*cic_msk_reg = (volatile u32 *)CIC_VPE0_MSK_REG;
	u32	cic_mask;
	u32	 pending;
	int	cic_status = *CIC_STS_REG;
	cic_mask = cic_msk_reg[get_current_vpe()];
	pending = cic_status & cic_mask;
	if (pending & (1 << (MSP_INT_VPE0_TIMER - MSP_CIC_INTBASE))) {
M
Marc St-Jean 已提交
214
		do_IRQ(MSP_INT_VPE0_TIMER);
215 216 217 218 219 220 221 222 223 224 225
	} else if (pending & (1 << (MSP_INT_VPE1_TIMER - MSP_CIC_INTBASE))) {
		do_IRQ(MSP_INT_VPE1_TIMER);
	} else if (pending & (1 << (MSP_INT_PER - MSP_CIC_INTBASE))) {
		msp_per_irq_dispatch();
	} else if (pending) {
		do_IRQ(ffs(pending) + MSP_CIC_INTBASE - 1);
	} else{
		spurious_interrupt();
		/* Re-enable the CIC cascaded interrupt. */
		irq_desc[MSP_INT_CIC].chip->end(MSP_INT_CIC);
	}
M
Marc St-Jean 已提交
226
}