irqchip.c 3.18 KB
Newer Older
Bryan Wu's avatar
Bryan Wu committed
1
/*
2
 * Copyright 2005-2009 Analog Devices Inc.
Bryan Wu's avatar
Bryan Wu committed
3
 *
4
 * Licensed under the GPL-2 or later
Bryan Wu's avatar
Bryan Wu committed
5 6 7 8 9 10 11 12 13
 */

#include <linux/kernel_stat.h>
#include <linux/module.h>
#include <linux/random.h>
#include <linux/seq_file.h>
#include <linux/kallsyms.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
14
#include <linux/seq_file.h>
15
#include <asm/irq_handler.h>
16
#include <asm/trace.h>
17
#include <asm/pda.h>
Bryan Wu's avatar
Bryan Wu committed
18

19
static atomic_t irq_err_count;
Bryan Wu's avatar
Bryan Wu committed
20 21
void ack_bad_irq(unsigned int irq)
{
22
	atomic_inc(&irq_err_count);
Bryan Wu's avatar
Bryan Wu committed
23 24 25 26 27
	printk(KERN_ERR "IRQ: spurious interrupt %d\n", irq);
}

static struct irq_desc bad_irq_desc = {
	.handle_irq = handle_bad_irq,
28
	.lock = __RAW_SPIN_LOCK_UNLOCKED(bad_irq_desc.lock),
Bryan Wu's avatar
Bryan Wu committed
29 30
};

31 32 33 34 35
#ifdef CONFIG_CPUMASK_OFFSTACK
/* We are not allocating a variable-sized bad_irq_desc.affinity */
#error "Blackfin architecture does not support CONFIG_CPUMASK_OFFSTACK."
#endif

36
#ifdef CONFIG_PROC_FS
37
int arch_show_interrupts(struct seq_file *p, int prec)
Bryan Wu's avatar
Bryan Wu committed
38
{
39
	int j;
Bryan Wu's avatar
Bryan Wu committed
40

41 42 43 44 45
	seq_printf(p, "%*s: ", prec, "NMI");
	for_each_online_cpu(j)
		seq_printf(p, "%10u ", cpu_pda[j].__nmi_count);
	seq_printf(p, "  CORE  Non Maskable Interrupt\n");
	seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
Bryan Wu's avatar
Bryan Wu committed
46 47
	return 0;
}
48
#endif
Bryan Wu's avatar
Bryan Wu committed
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#ifdef CONFIG_DEBUG_STACKOVERFLOW
static void check_stack_overflow(int irq)
{
	/* Debugging check for stack overflow: is there less than STACK_WARN free? */
	long sp = __get_SP() & (THREAD_SIZE - 1);

	if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
		dump_stack();
		pr_emerg("irq%i: possible stack overflow only %ld bytes free\n",
			irq, sp - sizeof(struct thread_info));
	}
}
#else
static inline void check_stack_overflow(int irq) { }
#endif

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#ifndef CONFIG_IPIPE
static void maybe_lower_to_irq14(void)
{
	unsigned short pending, other_ints;

	/*
	 * If we're the only interrupt running (ignoring IRQ15 which
	 * is for syscalls), lower our priority to IRQ14 so that
	 * softirqs run at that level.  If there's another,
	 * lower-level interrupt, irq_exit will defer softirqs to
	 * that. If the interrupt pipeline is enabled, we are already
	 * running at IRQ14 priority, so we don't need this code.
	 */
	CSYNC();
	pending = bfin_read_IPEND() & ~0x8000;
	other_ints = pending & (pending - 1);
	if (other_ints == 0)
		lower_to_irq14();
}
#else
static inline void maybe_lower_to_irq14(void) { }
#endif

Bryan Wu's avatar
Bryan Wu committed
89
/*
Simon Arlott's avatar
Simon Arlott committed
90
 * do_IRQ handles all hardware IRQs.  Decoded IRQs should not
Bryan Wu's avatar
Bryan Wu committed
91 92 93 94
 * come via this function.  Instead, they should provide their
 * own 'handler'
 */
#ifdef CONFIG_DO_IRQ_L1
95
__attribute__((l1_text))
Bryan Wu's avatar
Bryan Wu committed
96 97 98
#endif
asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
{
99
	struct pt_regs *old_regs = set_irq_regs(regs);
Bryan Wu's avatar
Bryan Wu committed
100 101

	irq_enter();
102

103
	check_stack_overflow(irq);
104 105 106 107 108 109

	/*
	 * Some hardware gives randomly wrong interrupts.  Rather
	 * than crashing, do something sensible.
	 */
	if (irq >= NR_IRQS)
110
		handle_bad_irq(&bad_irq_desc);
111 112
	else
		generic_handle_irq(irq);
Bryan Wu's avatar
Bryan Wu committed
113

114 115
	maybe_lower_to_irq14();

Bryan Wu's avatar
Bryan Wu committed
116 117 118 119 120 121 122 123
	irq_exit();

	set_irq_regs(old_regs);
}

void __init init_IRQ(void)
{
	init_arch_irq();
124 125 126 127 128 129 130 131

#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
	/* Now that evt_ivhw is set up, turn this on */
	trace_buff_offset = 0;
	bfin_write_TBUFCTL(BFIN_TRACE_ON);
	printk(KERN_INFO "Hardware Trace expanded to %ik\n",
	  1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN);
#endif
Bryan Wu's avatar
Bryan Wu committed
132
}