ints-priority.c 29.5 KB
Newer Older
B
Bryan Wu 已提交
1
/*
2
 * Set up the interrupt priorities
B
Bryan Wu 已提交
3
 *
4 5 6 7 8 9
 * Copyright  2004-2009 Analog Devices Inc.
 *                 2003 Bas Vermeulen <bas@buyways.nl>
 *                 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
 *            2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
 *                 1999 D. Jeff Dionne <jeff@uclinux.org>
 *                 1996 Roman Zippel
B
Bryan Wu 已提交
10
 *
11
 * Licensed under the GPL-2
B
Bryan Wu 已提交
12 13 14 15 16 17
 */

#include <linux/module.h>
#include <linux/kernel_stat.h>
#include <linux/seq_file.h>
#include <linux/irq.h>
18 19 20
#ifdef CONFIG_IPIPE
#include <linux/ipipe.h>
#endif
B
Bryan Wu 已提交
21 22 23 24 25 26 27
#ifdef CONFIG_KGDB
#include <linux/kgdb.h>
#endif
#include <asm/traps.h>
#include <asm/blackfin.h>
#include <asm/gpio.h>
#include <asm/irq_handler.h>
28
#include <asm/dpmc.h>
29 30
#include <asm/bfin5xx_spi.h>
#include <asm/bfin_sport.h>
31
#include <asm/bfin_can.h>
B
Bryan Wu 已提交
32

33 34
#define SIC_SYSIRQ(irq)	(irq - (IRQ_CORETMR + 1))

B
Bryan Wu 已提交
35 36
#ifdef BF537_FAMILY
# define BF537_GENERIC_ERROR_INT_DEMUX
37 38 39 40 41 42
# define SPI_ERR_MASK   (BIT_STAT_TXCOL | BIT_STAT_RBSY | BIT_STAT_MODF | BIT_STAT_TXE)	/* SPI_STAT */
# define SPORT_ERR_MASK (ROVF | RUVF | TOVF | TUVF)	/* SPORT_STAT */
# define PPI_ERR_MASK   (0xFFFF & ~FLD)	/* PPI_STATUS */
# define EMAC_ERR_MASK  (PHYINT | MMCINT | RXFSINT | TXFSINT | WAKEDET | RXDMAERR | TXDMAERR | STMDONE)	/* EMAC_SYSTAT */
# define UART_ERR_MASK  (0x6)	/* UART_IIR */
# define CAN_ERR_MASK   (EWTIF | EWRIF | EPIF | BOIF | WUIF | UIAIF | AAIF | RMLIF | UCEIF | EXTIF | ADIF)	/* CAN_GIF */
B
Bryan Wu 已提交
43 44 45 46 47 48 49 50 51 52 53
#else
# undef BF537_GENERIC_ERROR_INT_DEMUX
#endif

/*
 * NOTES:
 * - we have separated the physical Hardware interrupt from the
 * levels that the LINUX kernel sees (see the description in irq.h)
 * -
 */

54
#ifndef CONFIG_SMP
55 56 57 58 59 60
/* Initialize this to an actual value to force it into the .data
 * section so that we know it is properly initialized at entry into
 * the kernel but before bss is initialized to zero (which is where
 * it would live otherwise).  The 0x1f magic represents the IRQs we
 * cannot actually mask out in hardware.
 */
61 62
unsigned long bfin_irq_flags = 0x1f;
EXPORT_SYMBOL(bfin_irq_flags);
63
#endif
B
Bryan Wu 已提交
64 65 66 67

/* The number of spurious interrupts */
atomic_t num_spurious;

68 69
#ifdef CONFIG_PM
unsigned long bfin_sic_iwr[3];	/* Up to 3 SIC_IWRx registers */
70
unsigned vr_wakeup;
71 72
#endif

B
Bryan Wu 已提交
73
struct ivgx {
74
	/* irq number for request_irq, available in mach-bf5xx/irq.h */
75
	unsigned int irqno;
B
Bryan Wu 已提交
76
	/* corresponding bit in the SIC_ISR register */
77
	unsigned int isrflag;
B
Bryan Wu 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
} ivg_table[NR_PERI_INTS];

struct ivg_slice {
	/* position of first irq in ivg_table for given ivg */
	struct ivgx *ifirst;
	struct ivgx *istop;
} ivg7_13[IVG13 - IVG7 + 1];


/*
 * Search SIC_IAR and fill tables with the irqvalues
 * and their positions in the SIC_ISR register.
 */
static void __init search_IAR(void)
{
	unsigned ivg, irq_pos = 0;
	for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
		int irqn;

97
		ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
B
Bryan Wu 已提交
98 99 100

		for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
			int iar_shift = (irqn & 7) * 4;
101
				if (ivg == (0xf &
102 103
#if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
	|| defined(CONFIG_BF539) || defined(CONFIG_BF51x)
104
			     bfin_read32((unsigned long *)SIC_IAR0 +
105 106
					 ((irqn % 32) >> 3) + ((irqn / 32) *
					 ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
107 108
#else
			     bfin_read32((unsigned long *)SIC_IAR0 +
109
					 (irqn >> 3)) >> iar_shift)) {
110
#endif
B
Bryan Wu 已提交
111
				ivg_table[irq_pos].irqno = IVG7 + irqn;
112
				ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
B
Bryan Wu 已提交
113 114 115 116 117 118 119 120
				ivg7_13[ivg].istop++;
				irq_pos++;
			}
		}
	}
}

/*
121
 * This is for core internal IRQs
B
Bryan Wu 已提交
122 123
 */

124
static void bfin_ack_noop(unsigned int irq)
B
Bryan Wu 已提交
125 126 127 128 129 130
{
	/* Dummy function.  */
}

static void bfin_core_mask_irq(unsigned int irq)
{
131
	bfin_irq_flags &= ~(1 << irq);
132 133
	if (!irqs_disabled_hw())
		local_irq_enable_hw();
B
Bryan Wu 已提交
134 135 136 137
}

static void bfin_core_unmask_irq(unsigned int irq)
{
138
	bfin_irq_flags |= 1 << irq;
B
Bryan Wu 已提交
139 140
	/*
	 * If interrupts are enabled, IMASK must contain the same value
141
	 * as bfin_irq_flags.  Make sure that invariant holds.  If interrupts
B
Bryan Wu 已提交
142 143 144
	 * are currently disabled we need not do anything; one of the
	 * callers will take care of setting IMASK to the proper value
	 * when reenabling interrupts.
145
	 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
B
Bryan Wu 已提交
146 147
	 * what we need.
	 */
148 149
	if (!irqs_disabled_hw())
		local_irq_enable_hw();
B
Bryan Wu 已提交
150 151 152 153 154
	return;
}

static void bfin_internal_mask_irq(unsigned int irq)
{
155 156
	unsigned long flags;

157
#ifdef CONFIG_BF53x
158
	local_irq_save_hw(flags);
B
Bryan Wu 已提交
159
	bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
160
			     ~(1 << SIC_SYSIRQ(irq)));
161 162
#else
	unsigned mask_bank, mask_bit;
163
	local_irq_save_hw(flags);
164 165
	mask_bank = SIC_SYSIRQ(irq) / 32;
	mask_bit = SIC_SYSIRQ(irq) % 32;
166 167
	bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
			     ~(1 << mask_bit));
168 169 170 171
#ifdef CONFIG_SMP
	bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
			     ~(1 << mask_bit));
#endif
172
#endif
173
	local_irq_restore_hw(flags);
B
Bryan Wu 已提交
174 175 176 177
}

static void bfin_internal_unmask_irq(unsigned int irq)
{
178 179
	unsigned long flags;

180
#ifdef CONFIG_BF53x
181
	local_irq_save_hw(flags);
B
Bryan Wu 已提交
182
	bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
183
			     (1 << SIC_SYSIRQ(irq)));
184 185
#else
	unsigned mask_bank, mask_bit;
186
	local_irq_save_hw(flags);
187 188
	mask_bank = SIC_SYSIRQ(irq) / 32;
	mask_bit = SIC_SYSIRQ(irq) % 32;
189 190
	bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
			     (1 << mask_bit));
191 192 193 194
#ifdef CONFIG_SMP
	bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) |
			     (1 << mask_bit));
#endif
195
#endif
196
	local_irq_restore_hw(flags);
B
Bryan Wu 已提交
197 198
}

199 200 201
#ifdef CONFIG_PM
int bfin_internal_set_wake(unsigned int irq, unsigned int state)
{
202
	u32 bank, bit, wakeup = 0;
203
	unsigned long flags;
204 205
	bank = SIC_SYSIRQ(irq) / 32;
	bit = SIC_SYSIRQ(irq) % 32;
206

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	switch (irq) {
#ifdef IRQ_RTC
	case IRQ_RTC:
	wakeup |= WAKE;
	break;
#endif
#ifdef IRQ_CAN0_RX
	case IRQ_CAN0_RX:
	wakeup |= CANWE;
	break;
#endif
#ifdef IRQ_CAN1_RX
	case IRQ_CAN1_RX:
	wakeup |= CANWE;
	break;
#endif
#ifdef IRQ_USB_INT0
	case IRQ_USB_INT0:
	wakeup |= USBWE;
	break;
#endif
#ifdef IRQ_KEY
	case IRQ_KEY:
	wakeup |= KPADWE;
	break;
#endif
233
#ifdef CONFIG_BF54x
234 235 236 237 238 239 240 241
	case IRQ_CNT:
	wakeup |= ROTWE;
	break;
#endif
	default:
	break;
	}

242
	local_irq_save_hw(flags);
243

244
	if (state) {
245
		bfin_sic_iwr[bank] |= (1 << bit);
246 247 248
		vr_wakeup  |= wakeup;

	} else {
249
		bfin_sic_iwr[bank] &= ~(1 << bit);
250 251
		vr_wakeup  &= ~wakeup;
	}
252

253
	local_irq_restore_hw(flags);
254 255 256 257 258

	return 0;
}
#endif

B
Bryan Wu 已提交
259
static struct irq_chip bfin_core_irqchip = {
260
	.name = "CORE",
261
	.ack = bfin_ack_noop,
B
Bryan Wu 已提交
262 263 264 265 266
	.mask = bfin_core_mask_irq,
	.unmask = bfin_core_unmask_irq,
};

static struct irq_chip bfin_internal_irqchip = {
267
	.name = "INTN",
268
	.ack = bfin_ack_noop,
B
Bryan Wu 已提交
269 270
	.mask = bfin_internal_mask_irq,
	.unmask = bfin_internal_unmask_irq,
271 272 273
	.mask_ack = bfin_internal_mask_irq,
	.disable = bfin_internal_mask_irq,
	.enable = bfin_internal_unmask_irq,
274 275 276
#ifdef CONFIG_PM
	.set_wake = bfin_internal_set_wake,
#endif
B
Bryan Wu 已提交
277 278
};

279 280 281 282 283 284 285 286 287 288 289 290 291
static void bfin_handle_irq(unsigned irq)
{
#ifdef CONFIG_IPIPE
	struct pt_regs regs;    /* Contents not used. */
	ipipe_trace_irq_entry(irq);
	__ipipe_handle_irq(irq, &regs);
	ipipe_trace_irq_exit(irq);
#else /* !CONFIG_IPIPE */
	struct irq_desc *desc = irq_desc + irq;
	desc->handle_irq(irq, desc);
#endif  /* !CONFIG_IPIPE */
}

B
Bryan Wu 已提交
292 293 294 295 296 297 298
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
static int error_int_mask;

static void bfin_generic_error_mask_irq(unsigned int irq)
{
	error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));

299 300
	if (!error_int_mask)
		bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
B
Bryan Wu 已提交
301 302 303 304
}

static void bfin_generic_error_unmask_irq(unsigned int irq)
{
305
	bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
B
Bryan Wu 已提交
306 307 308 309
	error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
}

static struct irq_chip bfin_generic_error_irqchip = {
310
	.name = "ERROR",
311 312
	.ack = bfin_ack_noop,
	.mask_ack = bfin_generic_error_mask_irq,
B
Bryan Wu 已提交
313 314 315 316 317
	.mask = bfin_generic_error_mask_irq,
	.unmask = bfin_generic_error_unmask_irq,
};

static void bfin_demux_error_irq(unsigned int int_err_irq,
318
				 struct irq_desc *inta_desc)
B
Bryan Wu 已提交
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
{
	int irq = 0;

#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
	if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
		irq = IRQ_MAC_ERROR;
	else
#endif
	if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
		irq = IRQ_SPORT0_ERROR;
	else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
		irq = IRQ_SPORT1_ERROR;
	else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
		irq = IRQ_PPI_ERROR;
	else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
		irq = IRQ_CAN_ERROR;
	else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
		irq = IRQ_SPI_ERROR;
337
	else if ((bfin_read_UART0_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
B
Bryan Wu 已提交
338
		irq = IRQ_UART0_ERROR;
339
	else if ((bfin_read_UART1_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
B
Bryan Wu 已提交
340 341 342
		irq = IRQ_UART1_ERROR;

	if (irq) {
343 344 345
		if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
			bfin_handle_irq(irq);
		else {
B
Bryan Wu 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376

			switch (irq) {
			case IRQ_PPI_ERROR:
				bfin_write_PPI_STATUS(PPI_ERR_MASK);
				break;
#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
			case IRQ_MAC_ERROR:
				bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
				break;
#endif
			case IRQ_SPORT0_ERROR:
				bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
				break;

			case IRQ_SPORT1_ERROR:
				bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
				break;

			case IRQ_CAN_ERROR:
				bfin_write_CAN_GIS(CAN_ERR_MASK);
				break;

			case IRQ_SPI_ERROR:
				bfin_write_SPI_STAT(SPI_ERR_MASK);
				break;

			default:
				break;
			}

			pr_debug("IRQ %d:"
377 378
				 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
				 irq);
B
Bryan Wu 已提交
379 380 381 382 383
		}
	} else
		printk(KERN_ERR
		       "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
		       " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
384
		       __func__, __FILE__, __LINE__);
B
Bryan Wu 已提交
385 386 387 388

}
#endif				/* BF537_GENERIC_ERROR_INT_DEMUX */

389 390
static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
{
391
#ifdef CONFIG_IPIPE
392
	_set_irq_handler(irq, handle_level_irq);
393
#else
394 395 396 397
	struct irq_desc *desc = irq_desc + irq;
	/* May not call generic set_irq_handler() due to spinlock
	   recursion. */
	desc->handle_irq = handle;
398
#endif
399 400
}

401
static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
402
extern void bfin_gpio_irq_prepare(unsigned gpio);
403

404 405
#if !defined(CONFIG_BF54x)

B
Bryan Wu 已提交
406 407
static void bfin_gpio_ack_irq(unsigned int irq)
{
408 409 410 411
	/* AFAIK ack_irq in case mask_ack is provided
	 * get's only called for edge sense irqs
	 */
	set_gpio_data(irq_to_gpio(irq), 0);
B
Bryan Wu 已提交
412 413 414 415
}

static void bfin_gpio_mask_ack_irq(unsigned int irq)
{
416 417
	struct irq_desc *desc = irq_desc + irq;
	u32 gpionr = irq_to_gpio(irq);
B
Bryan Wu 已提交
418

419
	if (desc->handle_irq == handle_edge_irq)
B
Bryan Wu 已提交
420 421 422 423 424 425 426
		set_gpio_data(gpionr, 0);

	set_gpio_maska(gpionr, 0);
}

static void bfin_gpio_mask_irq(unsigned int irq)
{
427
	set_gpio_maska(irq_to_gpio(irq), 0);
B
Bryan Wu 已提交
428 429 430 431
}

static void bfin_gpio_unmask_irq(unsigned int irq)
{
432
	set_gpio_maska(irq_to_gpio(irq), 1);
B
Bryan Wu 已提交
433 434 435 436
}

static unsigned int bfin_gpio_irq_startup(unsigned int irq)
{
437
	u32 gpionr = irq_to_gpio(irq);
B
Bryan Wu 已提交
438

439
	if (__test_and_set_bit(gpionr, gpio_enabled))
440
		bfin_gpio_irq_prepare(gpionr);
B
Bryan Wu 已提交
441 442 443

	bfin_gpio_unmask_irq(irq);

444
	return 0;
B
Bryan Wu 已提交
445 446 447 448
}

static void bfin_gpio_irq_shutdown(unsigned int irq)
{
449 450
	u32 gpionr = irq_to_gpio(irq);

B
Bryan Wu 已提交
451
	bfin_gpio_mask_irq(irq);
452
	__clear_bit(gpionr, gpio_enabled);
453
	bfin_gpio_irq_free(gpionr);
B
Bryan Wu 已提交
454 455 456 457
}

static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
{
458 459
	int ret;
	char buf[16];
460
	u32 gpionr = irq_to_gpio(irq);
B
Bryan Wu 已提交
461 462 463

	if (type == IRQ_TYPE_PROBE) {
		/* only probe unenabled GPIO interrupt lines */
464
		if (test_bit(gpionr, gpio_enabled))
B
Bryan Wu 已提交
465 466 467 468 469
			return 0;
		type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
	}

	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
470
		    IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
471

472 473 474 475 476
		snprintf(buf, 16, "gpio-irq%d", irq);
		ret = bfin_gpio_irq_request(gpionr, buf);
		if (ret)
			return ret;

477
		if (__test_and_set_bit(gpionr, gpio_enabled))
478
			bfin_gpio_irq_prepare(gpionr);
B
Bryan Wu 已提交
479 480

	} else {
481
		__clear_bit(gpionr, gpio_enabled);
B
Bryan Wu 已提交
482 483 484
		return 0;
	}

485
	set_gpio_inen(gpionr, 0);
B
Bryan Wu 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498
	set_gpio_dir(gpionr, 0);

	if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
	    == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
		set_gpio_both(gpionr, 1);
	else
		set_gpio_both(gpionr, 0);

	if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
		set_gpio_polar(gpionr, 1);	/* low or falling edge denoted by one */
	else
		set_gpio_polar(gpionr, 0);	/* high or rising edge denoted by zero */

499 500 501 502 503 504 505 506 507 508
	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
		set_gpio_edge(gpionr, 1);
		set_gpio_inen(gpionr, 1);
		set_gpio_data(gpionr, 0);

	} else {
		set_gpio_edge(gpionr, 0);
		set_gpio_inen(gpionr, 1);
	}

B
Bryan Wu 已提交
509
	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
510
		bfin_set_irq_handler(irq, handle_edge_irq);
B
Bryan Wu 已提交
511
	else
512
		bfin_set_irq_handler(irq, handle_level_irq);
B
Bryan Wu 已提交
513 514 515 516

	return 0;
}

517 518 519 520 521 522 523 524 525 526 527 528 529 530
#ifdef CONFIG_PM
int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
{
	unsigned gpio = irq_to_gpio(irq);

	if (state)
		gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
	else
		gpio_pm_wakeup_free(gpio);

	return 0;
}
#endif

531 532
static void bfin_demux_gpio_irq(unsigned int inta_irq,
				struct irq_desc *desc)
B
Bryan Wu 已提交
533
{
534 535 536 537 538 539 540 541 542 543 544 545 546
	unsigned int i, gpio, mask, irq, search = 0;

	switch (inta_irq) {
#if defined(CONFIG_BF53x)
	case IRQ_PROG_INTA:
		irq = IRQ_PF0;
		search = 1;
		break;
# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
	case IRQ_MAC_RX:
		irq = IRQ_PH0;
		break;
# endif
547 548 549 550
#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
	case IRQ_PORTF_INTA:
		irq = IRQ_PF0;
		break;
551
#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
	case IRQ_PORTF_INTA:
		irq = IRQ_PF0;
		break;
	case IRQ_PORTG_INTA:
		irq = IRQ_PG0;
		break;
	case IRQ_PORTH_INTA:
		irq = IRQ_PH0;
		break;
#elif defined(CONFIG_BF561)
	case IRQ_PROG0_INTA:
		irq = IRQ_PF0;
		break;
	case IRQ_PROG1_INTA:
		irq = IRQ_PF16;
		break;
	case IRQ_PROG2_INTA:
		irq = IRQ_PF32;
		break;
#endif
	default:
		BUG();
		return;
	}

	if (search) {
578
		for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
579 580
			irq += i;

581
			mask = get_gpiop_data(i) & get_gpiop_maska(i);
582 583

			while (mask) {
584 585
				if (mask & 1)
					bfin_handle_irq(irq);
586 587
				irq++;
				mask >>= 1;
B
Bryan Wu 已提交
588 589
			}
		}
590 591
	} else {
			gpio = irq_to_gpio(irq);
592
			mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
593 594

			do {
595 596
				if (mask & 1)
					bfin_handle_irq(irq);
597 598 599
				irq++;
				mask >>= 1;
			} while (mask);
B
Bryan Wu 已提交
600
	}
601

B
Bryan Wu 已提交
602 603
}

604
#else				/* CONFIG_BF54x */
605 606 607 608 609 610 611 612 613 614 615

#define NR_PINT_SYS_IRQS	4
#define NR_PINT_BITS		32
#define NR_PINTS		160
#define IRQ_NOT_AVAIL		0xFF

#define PINT_2_BANK(x)		((x) >> 5)
#define PINT_2_BIT(x)		((x) & 0x1F)
#define PINT_BIT(x)		(1 << (PINT_2_BIT(x)))

static unsigned char irq2pint_lut[NR_PINTS];
616
static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637

struct pin_int_t {
	unsigned int mask_set;
	unsigned int mask_clear;
	unsigned int request;
	unsigned int assign;
	unsigned int edge_set;
	unsigned int edge_clear;
	unsigned int invert_set;
	unsigned int invert_clear;
	unsigned int pinstate;
	unsigned int latch;
};

static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
	(struct pin_int_t *)PINT0_MASK_SET,
	(struct pin_int_t *)PINT1_MASK_SET,
	(struct pin_int_t *)PINT2_MASK_SET,
	(struct pin_int_t *)PINT3_MASK_SET,
};

638
inline unsigned int get_irq_base(u32 bank, u8 bmap)
639
{
640
	unsigned int irq_base;
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672

	if (bank < 2) {		/*PA-PB */
		irq_base = IRQ_PA0 + bmap * 16;
	} else {		/*PC-PJ */
		irq_base = IRQ_PC0 + bmap * 16;
	}

	return irq_base;
}

	/* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
void init_pint_lut(void)
{
	u16 bank, bit, irq_base, bit_pos;
	u32 pint_assign;
	u8 bmap;

	memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));

	for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {

		pint_assign = pint[bank]->assign;

		for (bit = 0; bit < NR_PINT_BITS; bit++) {

			bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;

			irq_base = get_irq_base(bank, bmap);

			irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
			bit_pos = bit + bank * NR_PINT_BITS;

673
			pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
674 675 676 677 678 679 680
			irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
		}
	}
}

static void bfin_gpio_ack_irq(unsigned int irq)
{
681 682
	struct irq_desc *desc = irq_desc + irq;
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
683
	u32 pintbit = PINT_BIT(pint_val);
684
	u32 bank = PINT_2_BANK(pint_val);
685

686
	if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
687 688 689 690 691 692
		if (pint[bank]->invert_set & pintbit)
			pint[bank]->invert_clear = pintbit;
		else
			pint[bank]->invert_set = pintbit;
	}
	pint[bank]->request = pintbit;
693 694 695 696 697

}

static void bfin_gpio_mask_ack_irq(unsigned int irq)
{
698 699
	struct irq_desc *desc = irq_desc + irq;
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
700
	u32 pintbit = PINT_BIT(pint_val);
701
	u32 bank = PINT_2_BANK(pint_val);
702

703
	if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
704 705 706 707 708 709
		if (pint[bank]->invert_set & pintbit)
			pint[bank]->invert_clear = pintbit;
		else
			pint[bank]->invert_set = pintbit;
	}

710 711
	pint[bank]->request = pintbit;
	pint[bank]->mask_clear = pintbit;
712 713 714 715
}

static void bfin_gpio_mask_irq(unsigned int irq)
{
716
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
717 718 719 720 721 722

	pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
}

static void bfin_gpio_unmask_irq(unsigned int irq)
{
723
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
724
	u32 pintbit = PINT_BIT(pint_val);
725
	u32 bank = PINT_2_BANK(pint_val);
726

727 728
	pint[bank]->request = pintbit;
	pint[bank]->mask_set = pintbit;
729 730 731 732
}

static unsigned int bfin_gpio_irq_startup(unsigned int irq)
{
733 734
	u32 gpionr = irq_to_gpio(irq);
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
735

736 737 738 739
	if (pint_val == IRQ_NOT_AVAIL) {
		printk(KERN_ERR
		"GPIO IRQ %d :Not in PINT Assign table "
		"Reconfigure Interrupt to Port Assignemt\n", irq);
740
		return -ENODEV;
741
	}
742

743
	if (__test_and_set_bit(gpionr, gpio_enabled))
744
		bfin_gpio_irq_prepare(gpionr);
745 746 747

	bfin_gpio_unmask_irq(irq);

748
	return 0;
749 750 751 752
}

static void bfin_gpio_irq_shutdown(unsigned int irq)
{
753
	u32 gpionr = irq_to_gpio(irq);
754

755
	bfin_gpio_mask_irq(irq);
756
	__clear_bit(gpionr, gpio_enabled);
757
	bfin_gpio_irq_free(gpionr);
758 759 760 761
}

static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
{
762 763
	int ret;
	char buf[16];
764 765
	u32 gpionr = irq_to_gpio(irq);
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
766
	u32 pintbit = PINT_BIT(pint_val);
767
	u32 bank = PINT_2_BANK(pint_val);
768 769 770 771 772 773

	if (pint_val == IRQ_NOT_AVAIL)
		return -ENODEV;

	if (type == IRQ_TYPE_PROBE) {
		/* only probe unenabled GPIO interrupt lines */
774
		if (test_bit(gpionr, gpio_enabled))
775 776 777 778 779 780
			return 0;
		type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
	}

	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
		    IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
781 782 783 784 785 786

		snprintf(buf, 16, "gpio-irq%d", irq);
		ret = bfin_gpio_irq_request(gpionr, buf);
		if (ret)
			return ret;

787
		if (__test_and_set_bit(gpionr, gpio_enabled))
788
			bfin_gpio_irq_prepare(gpionr);
789 790

	} else {
791
		__clear_bit(gpionr, gpio_enabled);
792 793 794 795
		return 0;
	}

	if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
796
		pint[bank]->invert_set = pintbit;	/* low or falling edge denoted by one */
797
	else
798
		pint[bank]->invert_clear = pintbit;	/* high or rising edge denoted by zero */
799

800 801 802 803 804 805 806 807 808 809
	if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
	    == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
		if (gpio_get_value(gpionr))
			pint[bank]->invert_set = pintbit;
		else
			pint[bank]->invert_clear = pintbit;
	}

	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
		pint[bank]->edge_set = pintbit;
810
		bfin_set_irq_handler(irq, handle_edge_irq);
811 812
	} else {
		pint[bank]->edge_clear = pintbit;
813
		bfin_set_irq_handler(irq, handle_level_irq);
814 815
	}

816 817 818
	return 0;
}

819 820 821 822 823 824 825
#ifdef CONFIG_PM
u32 pint_saved_masks[NR_PINT_SYS_IRQS];
u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];

int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
{
	u32 pint_irq;
826
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
	u32 bank = PINT_2_BANK(pint_val);
	u32 pintbit = PINT_BIT(pint_val);

	switch (bank) {
	case 0:
		pint_irq = IRQ_PINT0;
		break;
	case 2:
		pint_irq = IRQ_PINT2;
		break;
	case 3:
		pint_irq = IRQ_PINT3;
		break;
	case 1:
		pint_irq = IRQ_PINT1;
		break;
	default:
		return -EINVAL;
	}

	bfin_internal_set_wake(pint_irq, state);

	if (state)
		pint_wakeup_masks[bank] |= pintbit;
	else
		pint_wakeup_masks[bank] &= ~pintbit;

	return 0;
}

u32 bfin_pm_setup(void)
{
	u32 val, i;

	for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
		val = pint[i]->mask_clear;
		pint_saved_masks[i] = val;
		if (val ^ pint_wakeup_masks[i]) {
			pint[i]->mask_clear = val;
			pint[i]->mask_set = pint_wakeup_masks[i];
		}
	}

	return 0;
}

void bfin_pm_restore(void)
{
	u32 i, val;

	for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
		val = pint_saved_masks[i];
		if (val ^ pint_wakeup_masks[i]) {
			pint[i]->mask_clear = pint[i]->mask_clear;
			pint[i]->mask_set = val;
		}
	}
}
#endif

887 888
static void bfin_demux_gpio_irq(unsigned int inta_irq,
				struct irq_desc *desc)
889
{
890
	u32 bank, pint_val;
891 892
	u32 request, irq;

893
	switch (inta_irq) {
894 895 896 897 898 899 900 901 902 903 904 905
	case IRQ_PINT0:
		bank = 0;
		break;
	case IRQ_PINT2:
		bank = 2;
		break;
	case IRQ_PINT3:
		bank = 3;
		break;
	case IRQ_PINT1:
		bank = 1;
		break;
906 907
	default:
		return;
908 909 910 911 912 913 914 915
	}

	pint_val = bank * NR_PINT_BITS;

	request = pint[bank]->request;

	while (request) {
		if (request & 1) {
916
			irq = pint2irq_lut[pint_val] + SYS_IRQS;
917
			bfin_handle_irq(irq);
918 919 920 921 922 923
		}
		pint_val++;
		request >>= 1;
	}

}
924
#endif
B
Bryan Wu 已提交
925

926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
static struct irq_chip bfin_gpio_irqchip = {
	.name = "GPIO",
	.ack = bfin_gpio_ack_irq,
	.mask = bfin_gpio_mask_irq,
	.mask_ack = bfin_gpio_mask_ack_irq,
	.unmask = bfin_gpio_unmask_irq,
	.disable = bfin_gpio_mask_irq,
	.enable = bfin_gpio_unmask_irq,
	.set_type = bfin_gpio_irq_type,
	.startup = bfin_gpio_irq_startup,
	.shutdown = bfin_gpio_irq_shutdown,
#ifdef CONFIG_PM
	.set_wake = bfin_gpio_set_wake,
#endif
};

942
void __cpuinit init_exception_vectors(void)
943
{
944 945 946 947 948
	/* cannot program in software:
	 * evt0 - emulation (jtag)
	 * evt1 - reset
	 */
	bfin_write_EVT2(evt_nmi);
949 950 951 952 953 954 955 956 957 958
	bfin_write_EVT3(trap);
	bfin_write_EVT5(evt_ivhw);
	bfin_write_EVT6(evt_timer);
	bfin_write_EVT7(evt_evt7);
	bfin_write_EVT8(evt_evt8);
	bfin_write_EVT9(evt_evt9);
	bfin_write_EVT10(evt_evt10);
	bfin_write_EVT11(evt_evt11);
	bfin_write_EVT12(evt_evt12);
	bfin_write_EVT13(evt_evt13);
959
	bfin_write_EVT14(evt_evt14);
960 961 962 963
	bfin_write_EVT15(evt_system_call);
	CSYNC();
}

B
Bryan Wu 已提交
964 965 966 967
/*
 * This function should be called during kernel startup to initialize
 * the BFin IRQ handling routines.
 */
968

B
Bryan Wu 已提交
969 970 971 972 973
int __init init_arch_irq(void)
{
	int irq;
	unsigned long ilat = 0;
	/*  Disable all the peripheral intrs  - page 4-29 HW Ref manual */
974 975
#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
	|| defined(BF538_FAMILY) || defined(CONFIG_BF51x)
976 977
	bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
	bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
978
# ifdef CONFIG_BF54x
979
	bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
980
# endif
981 982 983 984
# ifdef CONFIG_SMP
	bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
	bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
# endif
985
#else
B
Bryan Wu 已提交
986
	bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
987
#endif
B
Bryan Wu 已提交
988 989 990

	local_irq_disable();

991
#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
992 993 994 995
	/* Clear EMAC Interrupt Status bits so we can demux it later */
	bfin_write_EMAC_SYSTAT(-1);
#endif

996 997
#ifdef CONFIG_BF54x
# ifdef CONFIG_PINTx_REASSIGN
998 999 1000 1001
	pint[0]->assign = CONFIG_PINT0_ASSIGN;
	pint[1]->assign = CONFIG_PINT1_ASSIGN;
	pint[2]->assign = CONFIG_PINT2_ASSIGN;
	pint[3]->assign = CONFIG_PINT3_ASSIGN;
1002
# endif
1003 1004 1005 1006 1007
	/* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
	init_pint_lut();
#endif

	for (irq = 0; irq <= SYS_IRQS; irq++) {
B
Bryan Wu 已提交
1008 1009 1010 1011 1012
		if (irq <= IRQ_CORETMR)
			set_irq_chip(irq, &bfin_core_irqchip);
		else
			set_irq_chip(irq, &bfin_internal_irqchip);

1013
		switch (irq) {
1014
#if defined(CONFIG_BF53x)
1015
		case IRQ_PROG_INTA:
1016
# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1017
		case IRQ_MAC_RX:
1018
# endif
1019
#elif defined(CONFIG_BF54x)
1020 1021 1022 1023
		case IRQ_PINT0:
		case IRQ_PINT1:
		case IRQ_PINT2:
		case IRQ_PINT3:
1024
#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1025 1026 1027
		case IRQ_PORTF_INTA:
		case IRQ_PORTG_INTA:
		case IRQ_PORTH_INTA:
1028
#elif defined(CONFIG_BF561)
1029 1030 1031
		case IRQ_PROG0_INTA:
		case IRQ_PROG1_INTA:
		case IRQ_PROG2_INTA:
1032 1033
#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
		case IRQ_PORTF_INTA:
B
Bryan Wu 已提交
1034
#endif
1035

1036 1037 1038
			set_irq_chained_handler(irq,
						bfin_demux_gpio_irq);
			break;
B
Bryan Wu 已提交
1039
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
1040
		case IRQ_GENERIC_ERROR:
1041
			set_irq_chained_handler(irq, bfin_demux_error_irq);
1042
			break;
B
Bryan Wu 已提交
1043
#endif
1044

1045
#ifdef CONFIG_SMP
1046 1047 1048 1049 1050 1051
#ifdef CONFIG_TICKSOURCE_GPTMR0
		case IRQ_TIMER0:
#endif
#ifdef CONFIG_TICKSOURCE_CORETMR
		case IRQ_CORETMR:
#endif
1052 1053 1054 1055 1056
		case IRQ_SUPPLE_0:
		case IRQ_SUPPLE_1:
			set_irq_handler(irq, handle_percpu_irq);
			break;
#endif
1057

1058
#ifdef CONFIG_IPIPE
1059 1060 1061 1062
#ifndef CONFIG_TICKSOURCE_CORETMR
		case IRQ_TIMER0:
			set_irq_handler(irq, handle_simple_irq);
			break;
1063
#endif
1064 1065 1066 1067 1068 1069
		case IRQ_CORETMR:
			set_irq_handler(irq, handle_simple_irq);
			break;
		default:
			set_irq_handler(irq, handle_level_irq);
			break;
1070
#else /* !CONFIG_IPIPE */
1071
		default:
1072 1073
			set_irq_handler(irq, handle_simple_irq);
			break;
1074
#endif /* !CONFIG_IPIPE */
1075
		}
B
Bryan Wu 已提交
1076
	}
1077

B
Bryan Wu 已提交
1078
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
1079 1080 1081
	for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
		set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
					 handle_level_irq);
B
Bryan Wu 已提交
1082 1083
#endif

1084 1085 1086 1087
	/* if configured as edge, then will be changed to do_edge_IRQ */
	for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
		set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
					 handle_level_irq);
1088

1089

B
Bryan Wu 已提交
1090 1091 1092 1093 1094 1095 1096
	bfin_write_IMASK(0);
	CSYNC();
	ilat = bfin_read_ILAT();
	CSYNC();
	bfin_write_ILAT(ilat);
	CSYNC();

1097
	printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1098
	/* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
B
Bryan Wu 已提交
1099 1100 1101 1102 1103 1104 1105
	 * local_irq_enable()
	 */
	program_IAR();
	/* Therefore it's better to setup IARs before interrupts enabled */
	search_IAR();

	/* Enable interrupts IVG7-15 */
1106
	bfin_irq_flags |= IMASK_IVG15 |
B
Bryan Wu 已提交
1107
	    IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1108
	    IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
B
Bryan Wu 已提交
1109

1110 1111 1112
	/* This implicitly covers ANOMALY_05000171
	 * Boot-ROM code modifies SICA_IWRx wakeup registers
	 */
1113
#ifdef SIC_IWR0
1114
	bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
1115
# ifdef SIC_IWR1
1116
	/* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
1117 1118 1119 1120
	 * will screw up the bootrom as it relies on MDMA0/1 waking it
	 * up from IDLE instructions.  See this report for more info:
	 * http://blackfin.uclinux.org/gf/tracker/4323
	 */
1121 1122 1123 1124
	if (ANOMALY_05000435)
		bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
	else
		bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
1125 1126
# endif
# ifdef SIC_IWR2
1127
	bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
1128 1129
# endif
#else
1130
	bfin_write_SIC_IWR(IWR_DISABLE_ALL);
1131 1132
#endif

B
Bryan Wu 已提交
1133 1134 1135 1136
	return 0;
}

#ifdef CONFIG_DO_IRQ_L1
1137
__attribute__((l1_text))
B
Bryan Wu 已提交
1138 1139 1140 1141 1142 1143 1144 1145
#endif
void do_irq(int vec, struct pt_regs *fp)
{
	if (vec == EVT_IVTMR_P) {
		vec = IRQ_CORETMR;
	} else {
		struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
		struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1146
#if defined(SIC_ISR0) || defined(SICA_ISR0)
1147
		unsigned long sic_status[3];
B
Bryan Wu 已提交
1148

1149
		if (smp_processor_id()) {
1150
# ifdef SICB_ISR0
1151 1152 1153
			/* This will be optimized out in UP mode. */
			sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
			sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1154
# endif
1155 1156 1157 1158
		} else {
			sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
			sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
		}
1159
# ifdef SIC_ISR2
1160
		sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1161
# endif
1162
		for (;; ivg++) {
1163 1164 1165 1166
			if (ivg >= ivg_stop) {
				atomic_inc(&num_spurious);
				return;
			}
1167
			if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1168 1169 1170 1171
				break;
		}
#else
		unsigned long sic_status;
1172

B
Bryan Wu 已提交
1173 1174 1175 1176 1177 1178 1179 1180 1181
		sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();

		for (;; ivg++) {
			if (ivg >= ivg_stop) {
				atomic_inc(&num_spurious);
				return;
			} else if (sic_status & ivg->isrflag)
				break;
		}
1182
#endif
B
Bryan Wu 已提交
1183 1184 1185 1186
		vec = ivg->irqno;
	}
	asm_do_IRQ(vec, fp);
}
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216

#ifdef CONFIG_IPIPE

int __ipipe_get_irq_priority(unsigned irq)
{
	int ient, prio;

	if (irq <= IRQ_CORETMR)
		return irq;

	for (ient = 0; ient < NR_PERI_INTS; ient++) {
		struct ivgx *ivg = ivg_table + ient;
		if (ivg->irqno == irq) {
			for (prio = 0; prio <= IVG13-IVG7; prio++) {
				if (ivg7_13[prio].ifirst <= ivg &&
				    ivg7_13[prio].istop > ivg)
					return IVG7 + prio;
			}
		}
	}

	return IVG15;
}

/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
#ifdef CONFIG_DO_IRQ_L1
__attribute__((l1_text))
#endif
asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
{
1217
	struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
1218
	struct ipipe_domain *this_domain = __ipipe_current_domain;
1219 1220
	struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
	struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
1221
	int irq, s;
1222

1223
	if (likely(vec == EVT_IVTMR_P))
1224
		irq = IRQ_CORETMR;
1225
	else {
1226
#if defined(SIC_ISR0) || defined(SICA_ISR0)
1227 1228 1229 1230
		unsigned long sic_status[3];

		sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
		sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1231
# ifdef SIC_ISR2
1232
		sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1233
# endif
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
		for (;; ivg++) {
			if (ivg >= ivg_stop) {
				atomic_inc(&num_spurious);
				return 0;
			}
			if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
				break;
		}
#else
		unsigned long sic_status;

		sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();

		for (;; ivg++) {
			if (ivg >= ivg_stop) {
				atomic_inc(&num_spurious);
				return 0;
			} else if (sic_status & ivg->isrflag)
				break;
		}
#endif
1255 1256
		irq = ivg->irqno;
	}
1257 1258

	if (irq == IRQ_SYSTMR) {
1259
#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
1260
		bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
1261
#endif
1262 1263 1264
		/* This is basically what we need from the register frame. */
		__raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
		__raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
1265
		if (this_domain != ipipe_root_domain)
1266
			__raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
1267 1268
		else
			__raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
1269 1270
	}

1271 1272 1273 1274
	if (this_domain == ipipe_root_domain) {
		s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
		barrier();
	}
1275 1276 1277

	ipipe_trace_irq_entry(irq);
	__ipipe_handle_irq(irq, regs);
1278
	ipipe_trace_irq_exit(irq);
1279

1280 1281 1282 1283 1284 1285 1286
	if (this_domain == ipipe_root_domain) {
		set_thread_flag(TIF_IRQ_SYNC);
		if (!s) {
			__clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
			return !test_bit(IPIPE_STALL_FLAG, &p->status);
		}
	}
1287

1288
	return 0;
1289 1290 1291
}

#endif /* CONFIG_IPIPE */