irq.c 10.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* MN10300 Arch-specific interrupt handling
 *
 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public Licence
 * as published by the Free Software Foundation; either version
 * 2 of the Licence, or (at your option) any later version.
 */
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/kernel_stat.h>
#include <linux/seq_file.h>
15
#include <linux/cpumask.h>
16
#include <asm/setup.h>
17
#include <asm/serial-regs.h>
18

19 20 21
unsigned long __mn10300_irq_enabled_epsw[NR_CPUS] __cacheline_aligned_in_smp = {
	[0 ... NR_CPUS - 1] = EPSW_IE | EPSW_IM_7
};
22 23
EXPORT_SYMBOL(__mn10300_irq_enabled_epsw);

24 25 26 27 28 29 30 31 32 33 34
#ifdef CONFIG_SMP
static char irq_affinity_online[NR_IRQS] = {
	[0 ... NR_IRQS - 1] = 0
};

#define NR_IRQ_WORDS	((NR_IRQS + 31) / 32)
static unsigned long irq_affinity_request[NR_IRQ_WORDS] = {
	[0 ... NR_IRQ_WORDS - 1] = 0
};
#endif  /* CONFIG_SMP */

35 36 37
atomic_t irq_err_count;

/*
D
David Howells 已提交
38
 * MN10300 interrupt controller operations
39
 */
40
static void mn10300_cpupic_ack(struct irq_data *d)
41
{
42
	unsigned int irq = d->irq;
43 44 45 46 47 48 49 50 51 52 53 54 55
	unsigned long flags;
	u16 tmp;

	flags = arch_local_cli_save();
	GxICR_u8(irq) = GxICR_DETECT;
	tmp = GxICR(irq);
	arch_local_irq_restore(flags);
}

static void __mask_and_set_icr(unsigned int irq,
			       unsigned int mask, unsigned int set)
{
	unsigned long flags;
56
	u16 tmp;
57 58

	flags = arch_local_cli_save();
59
	tmp = GxICR(irq);
60 61 62
	GxICR(irq) = (tmp & mask) | set;
	tmp = GxICR(irq);
	arch_local_irq_restore(flags);
63 64
}

65
static void mn10300_cpupic_mask(struct irq_data *d)
66
{
67
	__mask_and_set_icr(d->irq, GxICR_LEVEL, 0);
68 69
}

70
static void mn10300_cpupic_mask_ack(struct irq_data *d)
71
{
72
	unsigned int irq = d->irq;
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#ifdef CONFIG_SMP
	unsigned long flags;
	u16 tmp;

	flags = arch_local_cli_save();

	if (!test_and_clear_bit(irq, irq_affinity_request)) {
		tmp = GxICR(irq);
		GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT;
		tmp = GxICR(irq);
	} else {
		u16 tmp2;
		tmp = GxICR(irq);
		GxICR(irq) = (tmp & GxICR_LEVEL);
		tmp2 = GxICR(irq);

M
Mark Salter 已提交
89
		irq_affinity_online[irq] =
90
			any_online_cpu(*d->affinity);
M
Mark Salter 已提交
91 92 93
		CROSS_GxICR(irq, irq_affinity_online[irq]) =
			(tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT;
		tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
94 95 96 97 98 99
	}

	arch_local_irq_restore(flags);
#else  /* CONFIG_SMP */
	__mask_and_set_icr(irq, GxICR_LEVEL, GxICR_DETECT);
#endif /* CONFIG_SMP */
100 101
}

102
static void mn10300_cpupic_unmask(struct irq_data *d)
103
{
104
	__mask_and_set_icr(d->irq, GxICR_LEVEL, GxICR_ENABLE);
105 106
}

107
static void mn10300_cpupic_unmask_clear(struct irq_data *d)
108
{
109
	unsigned int irq = d->irq;
D
David Howells 已提交
110 111 112 113
	/* the MN10300 PIC latches its interrupt request bit, even after the
	 * device has ceased to assert its interrupt line and the interrupt
	 * channel has been disabled in the PIC, so for level-triggered
	 * interrupts we need to clear the request bit when we re-enable */
114 115 116 117 118 119 120 121 122 123 124 125 126
#ifdef CONFIG_SMP
	unsigned long flags;
	u16 tmp;

	flags = arch_local_cli_save();

	if (!test_and_clear_bit(irq, irq_affinity_request)) {
		tmp = GxICR(irq);
		GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
		tmp = GxICR(irq);
	} else {
		tmp = GxICR(irq);

127
		irq_affinity_online[irq] = any_online_cpu(*d->affinity);
M
Mark Salter 已提交
128 129
		CROSS_GxICR(irq, irq_affinity_online[irq]) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
		tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
130 131 132 133 134 135
	}

	arch_local_irq_restore(flags);
#else  /* CONFIG_SMP */
	__mask_and_set_icr(irq, GxICR_LEVEL, GxICR_ENABLE | GxICR_DETECT);
#endif /* CONFIG_SMP */
136 137
}

138 139
#ifdef CONFIG_SMP
static int
140 141
mn10300_cpupic_setaffinity(struct irq_data *d, const struct cpumask *mask,
			   bool force)
142 143 144 145 146 147 148
{
	unsigned long flags;
	int err;

	flags = arch_local_cli_save();

	/* check irq no */
149
	switch (d->irq) {
150 151 152 153 154 155
	case TMJCIRQ:
	case RESCHEDULE_IPI:
	case CALL_FUNC_SINGLE_IPI:
	case LOCAL_TIMER_IPI:
	case FLUSH_CACHE_IPI:
	case CALL_FUNCTION_NMI_IPI:
156
	case DEBUGGER_NMI_IPI:
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 183 184 185 186 187
#ifdef CONFIG_MN10300_TTYSM0
	case SC0RXIRQ:
	case SC0TXIRQ:
#ifdef CONFIG_MN10300_TTYSM0_TIMER8
	case TM8IRQ:
#elif CONFIG_MN10300_TTYSM0_TIMER2
	case TM2IRQ:
#endif /* CONFIG_MN10300_TTYSM0_TIMER8 */
#endif /* CONFIG_MN10300_TTYSM0 */

#ifdef CONFIG_MN10300_TTYSM1
	case SC1RXIRQ:
	case SC1TXIRQ:
#ifdef CONFIG_MN10300_TTYSM1_TIMER12
	case TM12IRQ:
#elif CONFIG_MN10300_TTYSM1_TIMER9
	case TM9IRQ:
#elif CONFIG_MN10300_TTYSM1_TIMER3
	case TM3IRQ:
#endif /* CONFIG_MN10300_TTYSM1_TIMER12 */
#endif /* CONFIG_MN10300_TTYSM1 */

#ifdef CONFIG_MN10300_TTYSM2
	case SC2RXIRQ:
	case SC2TXIRQ:
	case TM10IRQ:
#endif /* CONFIG_MN10300_TTYSM2 */
		err = -1;
		break;

	default:
188
		set_bit(d->irq, irq_affinity_request);
189 190 191 192 193 194 195 196 197
		err = 0;
		break;
	}

	arch_local_irq_restore(flags);
	return err;
}
#endif /* CONFIG_SMP */

D
David Howells 已提交
198 199 200 201 202 203 204 205 206 207 208
/*
 * MN10300 PIC level-triggered IRQ handling.
 *
 * The PIC has no 'ACK' function per se.  It is possible to clear individual
 * channel latches, but each latch relatches whether or not the channel is
 * masked, so we need to clear the latch when we unmask the channel.
 *
 * Also for this reason, we don't supply an ack() op (it's unused anyway if
 * mask_ack() is provided), and mask_ack() just masks.
 */
static struct irq_chip mn10300_cpu_pic_level = {
209 210 211 212 213 214 215
	.name			= "cpu_l",
	.irq_disable		= mn10300_cpupic_mask,
	.irq_enable		= mn10300_cpupic_unmask_clear,
	.irq_ack		= NULL,
	.irq_mask		= mn10300_cpupic_mask,
	.irq_mask_ack		= mn10300_cpupic_mask,
	.irq_unmask		= mn10300_cpupic_unmask_clear,
216
#ifdef CONFIG_SMP
217
	.irq_set_affinity	= mn10300_cpupic_setaffinity,
M
Mark Salter 已提交
218
#endif
D
David Howells 已提交
219 220 221 222 223 224 225 226
};

/*
 * MN10300 PIC edge-triggered IRQ handling.
 *
 * We use the latch clearing function of the PIC as the 'ACK' function.
 */
static struct irq_chip mn10300_cpu_pic_edge = {
227 228 229 230 231 232 233
	.name			= "cpu_e",
	.irq_disable		= mn10300_cpupic_mask,
	.irq_enable		= mn10300_cpupic_unmask,
	.irq_ack		= mn10300_cpupic_ack,
	.irq_mask		= mn10300_cpupic_mask,
	.irq_mask_ack		= mn10300_cpupic_mask_ack,
	.irq_unmask		= mn10300_cpupic_unmask,
234
#ifdef CONFIG_SMP
235
	.irq_set_affinity	= mn10300_cpupic_setaffinity,
M
Mark Salter 已提交
236
#endif
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
};

/*
 * 'what should we do if we get a hw irq event on an illegal vector'.
 * each architecture has to answer this themselves.
 */
void ack_bad_irq(int irq)
{
	printk(KERN_WARNING "unexpected IRQ trap at vector %02x\n", irq);
}

/*
 * change the level at which an IRQ executes
 * - must not be called whilst interrupts are being processed!
 */
void set_intr_level(int irq, u16 level)
{
254
	BUG_ON(in_interrupt());
255

256 257
	__mask_and_set_icr(irq, GxICR_ENABLE, level);
}
258 259 260 261 262 263

/*
 * mark an interrupt to be ACK'd after interrupt handlers have been run rather
 * than before
 * - see Documentation/mn10300/features.txt
 */
264
void mn10300_set_lateack_irq_type(int irq)
265
{
266
	irq_set_chip_and_handler(irq, &mn10300_cpu_pic_level,
D
David Howells 已提交
267
				 handle_level_irq);
268 269 270 271 272 273 274 275 276 277
}

/*
 * initialise the interrupt system
 */
void __init init_IRQ(void)
{
	int irq;

	for (irq = 0; irq < NR_IRQS; irq++)
278
		if (irq_get_chip(irq) == &no_irq_chip)
D
David Howells 已提交
279 280 281 282
			/* due to the PIC latching interrupt requests, even
			 * when the IRQ is disabled, IRQ_PENDING is superfluous
			 * and we can use handle_level_irq() for edge-triggered
			 * interrupts */
283
			irq_set_chip_and_handler(irq, &mn10300_cpu_pic_edge,
D
David Howells 已提交
284
						 handle_level_irq);
285

286 287 288 289 290 291 292 293 294
	unit_init_IRQ();
}

/*
 * handle normal device IRQs
 */
asmlinkage void do_IRQ(void)
{
	unsigned long sp, epsw, irq_disabled_epsw, old_irq_enabled_epsw;
295
	unsigned int cpu_id = smp_processor_id();
296 297 298
	int irq;

	sp = current_stack_pointer();
S
Stoyan Gaydarov 已提交
299
	BUG_ON(sp - (sp & ~(THREAD_SIZE - 1)) < STACK_WARN);
300 301 302

	/* make sure local_irq_enable() doesn't muck up the interrupt priority
	 * setting in EPSW */
303
	old_irq_enabled_epsw = __mn10300_irq_enabled_epsw[cpu_id];
304
	local_save_flags(epsw);
305
	__mn10300_irq_enabled_epsw[cpu_id] = EPSW_IE | (EPSW_IM & epsw);
306 307
	irq_disabled_epsw = EPSW_IE | MN10300_CLI_LEVEL;

308 309 310
#ifdef CONFIG_MN10300_WD_TIMER
	__IRQ_STAT(cpu_id, __irq_count)++;
#endif
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329

	irq_enter();

	for (;;) {
		/* ask the interrupt controller for the next IRQ to process
		 * - the result we get depends on EPSW.IM
		 */
		irq = IAGR & IAGR_GN;
		if (!irq)
			break;

		local_irq_restore(irq_disabled_epsw);

		generic_handle_irq(irq >> 2);

		/* restore IRQ controls for IAGR access */
		local_irq_restore(epsw);
	}

330
	__mn10300_irq_enabled_epsw[cpu_id] = old_irq_enabled_epsw;
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

	irq_exit();
}

/*
 * Display interrupt management information through /proc/interrupts
 */
int show_interrupts(struct seq_file *p, void *v)
{
	int i = *(loff_t *) v, j, cpu;
	struct irqaction *action;
	unsigned long flags;

	switch (i) {
		/* display column title bar naming CPUs */
	case 0:
		seq_printf(p, "           ");
		for (j = 0; j < NR_CPUS; j++)
			if (cpu_online(j))
				seq_printf(p, "CPU%d       ", j);
		seq_putc(p, '\n');
		break;

		/* display information rows, one per active CPU */
	case 1 ... NR_IRQS - 1:
356
		raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
357 358 359 360 361

		action = irq_desc[i].action;
		if (action) {
			seq_printf(p, "%3d: ", i);
			for_each_present_cpu(cpu)
362
				seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));
363 364 365

			if (i < NR_CPU_IRQS)
				seq_printf(p, " %14s.%u",
366
					   irq_desc[i].irq_data.chip->name,
367 368 369 370
					   (GxICR(i) & GxICR_LEVEL) >>
					   GxICR_LEVEL_SHIFT);
			else
				seq_printf(p, " %14s",
371
					   irq_desc[i].irq_data.chip->name);
372

373 374 375 376 377 378 379 380 381 382
			seq_printf(p, "  %s", action->name);

			for (action = action->next;
			     action;
			     action = action->next)
				seq_printf(p, ", %s", action->name);

			seq_putc(p, '\n');
		}

383
		raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
384 385 386 387
		break;

		/* polish off with NMI and error counters */
	case NR_IRQS:
388
#ifdef CONFIG_MN10300_WD_TIMER
389 390 391 392 393
		seq_printf(p, "NMI: ");
		for (j = 0; j < NR_CPUS; j++)
			if (cpu_online(j))
				seq_printf(p, "%10u ", nmi_count(j));
		seq_putc(p, '\n');
394
#endif
395 396 397 398 399 400 401

		seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
		break;
	}

	return 0;
}
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428

#ifdef CONFIG_HOTPLUG_CPU
void migrate_irqs(void)
{
	irq_desc_t *desc;
	int irq;
	unsigned int self, new;
	unsigned long flags;

	self = smp_processor_id();
	for (irq = 0; irq < NR_IRQS; irq++) {
		desc = irq_desc + irq;

		if (desc->status == IRQ_PER_CPU)
			continue;

		if (cpu_isset(self, irq_desc[irq].affinity) &&
		    !cpus_intersects(irq_affinity[irq], cpu_online_map)) {
			int cpu_id;
			cpu_id = first_cpu(cpu_online_map);
			cpu_set(cpu_id, irq_desc[irq].affinity);
		}
		/* We need to operate irq_affinity_online atomically. */
		arch_local_cli_save(flags);
		if (irq_affinity_online[irq] == self) {
			u16 x, tmp;

M
Mark Salter 已提交
429 430 431
			x = GxICR(irq);
			GxICR(irq) = x & GxICR_LEVEL;
			tmp = GxICR(irq);
432 433 434 435 436 437 438 439 440

			new = any_online_cpu(irq_desc[irq].affinity);
			irq_affinity_online[irq] = new;

			CROSS_GxICR(irq, new) =
				(x & GxICR_LEVEL) | GxICR_DETECT;
			tmp = CROSS_GxICR(irq, new);

			x &= GxICR_LEVEL | GxICR_ENABLE;
441
			if (GxICR(irq) & GxICR_REQUEST)
442 443 444 445 446 447 448 449
				x |= GxICR_REQUEST | GxICR_DETECT;
			CROSS_GxICR(irq, new) = x;
			tmp = CROSS_GxICR(irq, new);
		}
		arch_local_irq_restore(flags);
	}
}
#endif /* CONFIG_HOTPLUG_CPU */