irq.c 6.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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
/*
 * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
 * reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the NetLogic
 * license below:
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/linkage.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/irq.h>

#include <asm/errno.h>
#include <asm/signal.h>
#include <asm/ptrace.h>
#include <asm/mipsregs.h>
#include <asm/thread_info.h>

#include <asm/netlogic/mips-extns.h>
#include <asm/netlogic/interrupt.h>
#include <asm/netlogic/haldefs.h>
#include <asm/netlogic/common.h>

55 56 57 58 59
#if defined(CONFIG_CPU_XLP)
#include <asm/netlogic/xlp-hal/iomap.h>
#include <asm/netlogic/xlp-hal/xlp.h>
#include <asm/netlogic/xlp-hal/pic.h>
#elif defined(CONFIG_CPU_XLR)
60 61
#include <asm/netlogic/xlr/iomap.h>
#include <asm/netlogic/xlr/pic.h>
62 63 64
#else
#error "Unknown CPU"
#endif
65 66 67 68 69 70 71 72 73 74 75
/*
 * These are the routines that handle all the low level interrupt stuff.
 * Actions handled here are: initialization of the interrupt map, requesting of
 * interrupt lines by handlers, dispatching if interrupts to handlers, probing
 * for interrupt lines
 */

/* Globals */
static void xlp_pic_enable(struct irq_data *d)
{
	unsigned long flags;
76
	struct nlm_soc_info *nodep;
77 78
	int irt;

79
	nodep = nlm_current_node();
80 81 82
	irt = nlm_irq_to_irt(d->irq);
	if (irt == -1)
		return;
83 84 85
	spin_lock_irqsave(&nodep->piclock, flags);
	nlm_pic_enable_irt(nodep->picbase, irt);
	spin_unlock_irqrestore(&nodep->piclock, flags);
86 87 88 89
}

static void xlp_pic_disable(struct irq_data *d)
{
90
	struct nlm_soc_info *nodep;
91 92 93
	unsigned long flags;
	int irt;

94
	nodep = nlm_current_node();
95 96 97
	irt = nlm_irq_to_irt(d->irq);
	if (irt == -1)
		return;
98 99 100
	spin_lock_irqsave(&nodep->piclock, flags);
	nlm_pic_disable_irt(nodep->picbase, irt);
	spin_unlock_irqrestore(&nodep->piclock, flags);
101 102 103 104 105 106 107 108 109 110 111 112
}

static void xlp_pic_mask_ack(struct irq_data *d)
{
	uint64_t mask = 1ull << d->irq;

	write_c0_eirr(mask);            /* ack by writing EIRR */
}

static void xlp_pic_unmask(struct irq_data *d)
{
	void *hd = irq_data_get_irq_handler_data(d);
113
	struct nlm_soc_info *nodep;
114 115
	int irt;

116
	nodep = nlm_current_node();
117 118 119 120 121 122 123 124 125
	irt = nlm_irq_to_irt(d->irq);
	if (irt == -1)
		return;

	if (hd) {
		void (*extra_ack)(void *) = hd;
		extra_ack(d);
	}
	/* Ack is a single write, no need to lock */
126
	nlm_pic_ack(nodep->picbase, irt);
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
}

static struct irq_chip xlp_pic = {
	.name		= "XLP-PIC",
	.irq_enable	= xlp_pic_enable,
	.irq_disable	= xlp_pic_disable,
	.irq_mask_ack	= xlp_pic_mask_ack,
	.irq_unmask	= xlp_pic_unmask,
};

static void cpuintr_disable(struct irq_data *d)
{
	uint64_t eimr;
	uint64_t mask = 1ull << d->irq;

	eimr = read_c0_eimr();
	write_c0_eimr(eimr & ~mask);
}

static void cpuintr_enable(struct irq_data *d)
{
	uint64_t eimr;
	uint64_t mask = 1ull << d->irq;

	eimr = read_c0_eimr();
	write_c0_eimr(eimr | mask);
}

static void cpuintr_ack(struct irq_data *d)
{
	uint64_t mask = 1ull << d->irq;

	write_c0_eirr(mask);
}

static void cpuintr_nop(struct irq_data *d)
{
	WARN(d->irq >= PIC_IRQ_BASE, "Bad irq %d", d->irq);
}

/*
 * Chip definition for CPU originated interrupts(timer, msg) and
 * IPIs
 */
struct irq_chip nlm_cpu_intr = {
	.name		= "XLP-CPU-INTR",
	.irq_enable	= cpuintr_enable,
	.irq_disable	= cpuintr_disable,
	.irq_mask	= cpuintr_nop,
	.irq_ack	= cpuintr_nop,
	.irq_eoi	= cpuintr_ack,
};

void __init init_nlm_common_irqs(void)
{
	int i, irq, irt;
183 184
	uint64_t irqmask;
	struct nlm_soc_info *nodep;
185

186 187
	nodep = nlm_current_node();
	irqmask = (1ULL << IRQ_TIMER);
188 189 190 191 192 193 194 195 196 197 198
	for (i = 0; i < PIC_IRT_FIRST_IRQ; i++)
		irq_set_chip_and_handler(i, &nlm_cpu_intr, handle_percpu_irq);

	for (i = PIC_IRT_FIRST_IRQ; i <= PIC_IRT_LAST_IRQ ; i++)
		irq_set_chip_and_handler(i, &xlp_pic, handle_level_irq);

#ifdef CONFIG_SMP
	irq_set_chip_and_handler(IRQ_IPI_SMP_FUNCTION, &nlm_cpu_intr,
			 nlm_smp_function_ipi_handler);
	irq_set_chip_and_handler(IRQ_IPI_SMP_RESCHEDULE, &nlm_cpu_intr,
			 nlm_smp_resched_ipi_handler);
199
	irqmask |=
200 201 202 203 204 205 206
	    ((1ULL << IRQ_IPI_SMP_FUNCTION) | (1ULL << IRQ_IPI_SMP_RESCHEDULE));
#endif

	for (irq = PIC_IRT_FIRST_IRQ; irq <= PIC_IRT_LAST_IRQ; irq++) {
		irt = nlm_irq_to_irt(irq);
		if (irt == -1)
			continue;
207 208
		irqmask |= (1ULL << irq);
		nlm_pic_init_irt(nodep->picbase, irt, irq, 0);
209 210
	}

211
	nodep->irqmask = irqmask;
212 213 214 215 216 217 218
}

void __init arch_init_irq(void)
{
	/* Initialize the irq descriptors */
	init_nlm_common_irqs();

219
	write_c0_eimr(nlm_current_node()->irqmask);
220 221 222 223 224
}

void __cpuinit nlm_smp_irq_init(void)
{
	/* set interrupt mask for non-zero cpus */
225
	write_c0_eimr(nlm_current_node()->irqmask);
226 227 228 229 230
}

asmlinkage void plat_irq_dispatch(void)
{
	uint64_t eirr;
231
	int i, node;
232

233
	node = nlm_nodeid();
234 235 236 237 238
	eirr = read_c0_eirr() & read_c0_eimr();
	if (eirr & (1 << IRQ_TIMER)) {
		do_IRQ(IRQ_TIMER);
		return;
	}
239 240 241 242 243 244 245 246 247 248
#ifdef CONFIG_SMP
	if (eirr & IRQ_IPI_SMP_FUNCTION) {
		do_IRQ(IRQ_IPI_SMP_FUNCTION);
		return;
	}
	if (eirr & IRQ_IPI_SMP_RESCHEDULE) {
		do_IRQ(IRQ_IPI_SMP_RESCHEDULE);
		return;
	}
#endif
249 250 251 252
	i = __ilog2_u64(eirr);
	if (i == -1)
		return;

253
	do_IRQ(nlm_irq_to_xirq(node, i));
254
}