blob: 8f079392aff07796ac1cc46edef17ba829649b10 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Copyright 2005-2009 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Licensed under the GPL-2 or later
Bryan Wu1394f032007-05-06 14:50:22 -07005 */
6
7#include <linux/kernel_stat.h>
8#include <linux/module.h>
9#include <linux/random.h>
10#include <linux/seq_file.h>
11#include <linux/kallsyms.h>
12#include <linux/interrupt.h>
13#include <linux/irq.h>
Robin Getz518039b2007-07-25 11:03:28 +080014#include <asm/trace.h>
Robin Getz3605fb02009-02-04 16:49:45 +080015#include <asm/pda.h>
Bryan Wu1394f032007-05-06 14:50:22 -070016
Graf Yang8f658732008-11-18 17:48:22 +080017static atomic_t irq_err_count;
Bryan Wu1394f032007-05-06 14:50:22 -070018void ack_bad_irq(unsigned int irq)
19{
Graf Yang8f658732008-11-18 17:48:22 +080020 atomic_inc(&irq_err_count);
Bryan Wu1394f032007-05-06 14:50:22 -070021 printk(KERN_ERR "IRQ: spurious interrupt %d\n", irq);
22}
Bryan Wu1394f032007-05-06 14:50:22 -070023
Bryan Wu1394f032007-05-06 14:50:22 -070024static struct irq_desc bad_irq_desc = {
Bryan Wu1394f032007-05-06 14:50:22 -070025 .handle_irq = handle_bad_irq,
Thomas Gleixner239007b2009-11-17 16:46:45 +010026 .lock = __RAW_SPIN_LOCK_UNLOCKED(bad_irq_desc.lock),
Bryan Wu1394f032007-05-06 14:50:22 -070027};
28
Mike Travise65e49d2009-01-12 15:27:13 -080029#ifdef CONFIG_CPUMASK_OFFSTACK
30/* We are not allocating a variable-sized bad_irq_desc.affinity */
31#error "Blackfin architecture does not support CONFIG_CPUMASK_OFFSTACK."
32#endif
33
Mike Frysinger46f288a2009-06-15 06:13:58 -040034#ifdef CONFIG_PROC_FS
Bryan Wu1394f032007-05-06 14:50:22 -070035int show_interrupts(struct seq_file *p, void *v)
36{
Graf Yang8f658732008-11-18 17:48:22 +080037 int i = *(loff_t *) v, j;
Bryan Wu1394f032007-05-06 14:50:22 -070038 struct irqaction *action;
39 unsigned long flags;
40
41 if (i < NR_IRQS) {
Thomas Gleixner9f51a872011-02-07 12:01:59 +010042 struct irq_desc *desc = irq_to_desc(i);
43
44 raw_spin_lock_irqsave(&desc->lock, flags);
45 action = desc->action;
Bryan Wu1394f032007-05-06 14:50:22 -070046 if (!action)
Graf Yang8f658732008-11-18 17:48:22 +080047 goto skip;
48 seq_printf(p, "%3d: ", i);
49 for_each_online_cpu(j)
Yinghai Ludee41022009-01-11 00:29:15 -080050 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
Thomas Gleixner9f51a872011-02-07 12:01:59 +010051 seq_printf(p, " %8s", get_irq_desc_chip(desc)->name);
Bryan Wu1394f032007-05-06 14:50:22 -070052 seq_printf(p, " %s", action->name);
53 for (action = action->next; action; action = action->next)
Graf Yang8f658732008-11-18 17:48:22 +080054 seq_printf(p, " %s", action->name);
Bryan Wu1394f032007-05-06 14:50:22 -070055
56 seq_putc(p, '\n');
Graf Yang8f658732008-11-18 17:48:22 +080057 skip:
Thomas Gleixner9f51a872011-02-07 12:01:59 +010058 raw_spin_unlock_irqrestore(&desc->lock, flags);
Robin Getz3605fb02009-02-04 16:49:45 +080059 } else if (i == NR_IRQS) {
60 seq_printf(p, "NMI: ");
61 for_each_online_cpu(j)
62 seq_printf(p, "%10u ", cpu_pda[j].__nmi_count);
63 seq_printf(p, " CORE Non Maskable Interrupt\n");
Graf Yang8f658732008-11-18 17:48:22 +080064 seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
Robin Getz3605fb02009-02-04 16:49:45 +080065 }
Bryan Wu1394f032007-05-06 14:50:22 -070066 return 0;
67}
Mike Frysinger46f288a2009-06-15 06:13:58 -040068#endif
Bryan Wu1394f032007-05-06 14:50:22 -070069
Mike Frysinger6f10fda2009-06-15 06:18:38 -040070#ifdef CONFIG_DEBUG_STACKOVERFLOW
71static void check_stack_overflow(int irq)
72{
73 /* Debugging check for stack overflow: is there less than STACK_WARN free? */
74 long sp = __get_SP() & (THREAD_SIZE - 1);
75
76 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
77 dump_stack();
78 pr_emerg("irq%i: possible stack overflow only %ld bytes free\n",
79 irq, sp - sizeof(struct thread_info));
80 }
81}
82#else
83static inline void check_stack_overflow(int irq) { }
84#endif
85
Mike Frysinger81b79c22009-06-15 06:22:08 -040086#ifndef CONFIG_IPIPE
87static void maybe_lower_to_irq14(void)
88{
89 unsigned short pending, other_ints;
90
91 /*
92 * If we're the only interrupt running (ignoring IRQ15 which
93 * is for syscalls), lower our priority to IRQ14 so that
94 * softirqs run at that level. If there's another,
95 * lower-level interrupt, irq_exit will defer softirqs to
96 * that. If the interrupt pipeline is enabled, we are already
97 * running at IRQ14 priority, so we don't need this code.
98 */
99 CSYNC();
100 pending = bfin_read_IPEND() & ~0x8000;
101 other_ints = pending & (pending - 1);
102 if (other_ints == 0)
103 lower_to_irq14();
104}
105#else
106static inline void maybe_lower_to_irq14(void) { }
107#endif
108
Bryan Wu1394f032007-05-06 14:50:22 -0700109/*
Simon Arlottd2d50aa2007-06-11 15:31:30 +0800110 * do_IRQ handles all hardware IRQs. Decoded IRQs should not
Bryan Wu1394f032007-05-06 14:50:22 -0700111 * come via this function. Instead, they should provide their
112 * own 'handler'
113 */
Bryan Wu1394f032007-05-06 14:50:22 -0700114#ifdef CONFIG_DO_IRQ_L1
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800115__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -0700116#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700117asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
118{
Mike Frysinger26579212009-06-15 06:10:03 -0400119 struct pt_regs *old_regs = set_irq_regs(regs);
Bryan Wu1394f032007-05-06 14:50:22 -0700120
121 irq_enter();
Mike Frysinger26579212009-06-15 06:10:03 -0400122
Mike Frysinger6f10fda2009-06-15 06:18:38 -0400123 check_stack_overflow(irq);
Mike Frysinger26579212009-06-15 06:10:03 -0400124
125 /*
126 * Some hardware gives randomly wrong interrupts. Rather
127 * than crashing, do something sensible.
128 */
129 if (irq >= NR_IRQS)
130 handle_bad_irq(irq, &bad_irq_desc);
131 else
132 generic_handle_irq(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700133
Mike Frysinger81b79c22009-06-15 06:22:08 -0400134 maybe_lower_to_irq14();
135
Bryan Wu1394f032007-05-06 14:50:22 -0700136 irq_exit();
137
138 set_irq_regs(old_regs);
139}
140
141void __init init_IRQ(void)
142{
Bryan Wu1394f032007-05-06 14:50:22 -0700143 init_arch_irq();
Robin Getz518039b2007-07-25 11:03:28 +0800144
145#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
146 /* Now that evt_ivhw is set up, turn this on */
147 trace_buff_offset = 0;
148 bfin_write_TBUFCTL(BFIN_TRACE_ON);
149 printk(KERN_INFO "Hardware Trace expanded to %ik\n",
150 1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN);
151#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700152}