blob: 052cde5ed2e403111fd8a1639dd29835177d7496 [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>
Thomas Gleixnere8fac632014-02-23 21:40:13 +000014#include <linux/seq_file.h>
Mike Frysinger6327a572011-04-15 03:06:59 -040015#include <asm/irq_handler.h>
Robin Getz518039b2007-07-25 11:03:28 +080016#include <asm/trace.h>
Robin Getz3605fb02009-02-04 16:49:45 +080017#include <asm/pda.h>
Bryan Wu1394f032007-05-06 14:50:22 -070018
Graf Yang8f658732008-11-18 17:48:22 +080019static atomic_t irq_err_count;
Bryan Wu1394f032007-05-06 14:50:22 -070020void ack_bad_irq(unsigned int irq)
21{
Graf Yang8f658732008-11-18 17:48:22 +080022 atomic_inc(&irq_err_count);
Bryan Wu1394f032007-05-06 14:50:22 -070023 printk(KERN_ERR "IRQ: spurious interrupt %d\n", irq);
24}
Bryan Wu1394f032007-05-06 14:50:22 -070025
Bryan Wu1394f032007-05-06 14:50:22 -070026static struct irq_desc bad_irq_desc = {
Bryan Wu1394f032007-05-06 14:50:22 -070027 .handle_irq = handle_bad_irq,
Thomas Gleixner239007b2009-11-17 16:46:45 +010028 .lock = __RAW_SPIN_LOCK_UNLOCKED(bad_irq_desc.lock),
Bryan Wu1394f032007-05-06 14:50:22 -070029};
30
Mike Travise65e49d2009-01-12 15:27:13 -080031#ifdef CONFIG_CPUMASK_OFFSTACK
32/* We are not allocating a variable-sized bad_irq_desc.affinity */
33#error "Blackfin architecture does not support CONFIG_CPUMASK_OFFSTACK."
34#endif
35
Mike Frysinger46f288a2009-06-15 06:13:58 -040036#ifdef CONFIG_PROC_FS
Thomas Gleixnere8fac632014-02-23 21:40:13 +000037int arch_show_interrupts(struct seq_file *p, int prec)
Bryan Wu1394f032007-05-06 14:50:22 -070038{
Thomas Gleixnere8fac632014-02-23 21:40:13 +000039 int j;
Bryan Wu1394f032007-05-06 14:50:22 -070040
Thomas Gleixnere8fac632014-02-23 21:40:13 +000041 seq_printf(p, "%*s: ", prec, "NMI");
42 for_each_online_cpu(j)
43 seq_printf(p, "%10u ", cpu_pda[j].__nmi_count);
44 seq_printf(p, " CORE Non Maskable Interrupt\n");
45 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
Bryan Wu1394f032007-05-06 14:50:22 -070046 return 0;
47}
Mike Frysinger46f288a2009-06-15 06:13:58 -040048#endif
Bryan Wu1394f032007-05-06 14:50:22 -070049
Mike Frysinger6f10fda2009-06-15 06:18:38 -040050#ifdef CONFIG_DEBUG_STACKOVERFLOW
51static void check_stack_overflow(int irq)
52{
53 /* Debugging check for stack overflow: is there less than STACK_WARN free? */
54 long sp = __get_SP() & (THREAD_SIZE - 1);
55
56 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
57 dump_stack();
58 pr_emerg("irq%i: possible stack overflow only %ld bytes free\n",
59 irq, sp - sizeof(struct thread_info));
60 }
61}
62#else
63static inline void check_stack_overflow(int irq) { }
64#endif
65
Mike Frysinger81b79c22009-06-15 06:22:08 -040066#ifndef CONFIG_IPIPE
67static void maybe_lower_to_irq14(void)
68{
69 unsigned short pending, other_ints;
70
71 /*
72 * If we're the only interrupt running (ignoring IRQ15 which
73 * is for syscalls), lower our priority to IRQ14 so that
74 * softirqs run at that level. If there's another,
75 * lower-level interrupt, irq_exit will defer softirqs to
76 * that. If the interrupt pipeline is enabled, we are already
77 * running at IRQ14 priority, so we don't need this code.
78 */
79 CSYNC();
80 pending = bfin_read_IPEND() & ~0x8000;
81 other_ints = pending & (pending - 1);
82 if (other_ints == 0)
83 lower_to_irq14();
84}
85#else
86static inline void maybe_lower_to_irq14(void) { }
87#endif
88
Bryan Wu1394f032007-05-06 14:50:22 -070089/*
Simon Arlottd2d50aa2007-06-11 15:31:30 +080090 * do_IRQ handles all hardware IRQs. Decoded IRQs should not
Bryan Wu1394f032007-05-06 14:50:22 -070091 * come via this function. Instead, they should provide their
92 * own 'handler'
93 */
Bryan Wu1394f032007-05-06 14:50:22 -070094#ifdef CONFIG_DO_IRQ_L1
Mike Frysingerf0b5d122007-08-05 17:03:59 +080095__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -070096#endif
Bryan Wu1394f032007-05-06 14:50:22 -070097asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
98{
Mike Frysinger26579212009-06-15 06:10:03 -040099 struct pt_regs *old_regs = set_irq_regs(regs);
Bryan Wu1394f032007-05-06 14:50:22 -0700100
101 irq_enter();
Mike Frysinger26579212009-06-15 06:10:03 -0400102
Mike Frysinger6f10fda2009-06-15 06:18:38 -0400103 check_stack_overflow(irq);
Mike Frysinger26579212009-06-15 06:10:03 -0400104
105 /*
106 * Some hardware gives randomly wrong interrupts. Rather
107 * than crashing, do something sensible.
108 */
109 if (irq >= NR_IRQS)
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200110 handle_bad_irq(&bad_irq_desc);
Mike Frysinger26579212009-06-15 06:10:03 -0400111 else
112 generic_handle_irq(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700113
Mike Frysinger81b79c22009-06-15 06:22:08 -0400114 maybe_lower_to_irq14();
115
Bryan Wu1394f032007-05-06 14:50:22 -0700116 irq_exit();
117
118 set_irq_regs(old_regs);
119}
120
121void __init init_IRQ(void)
122{
Bryan Wu1394f032007-05-06 14:50:22 -0700123 init_arch_irq();
Robin Getz518039b2007-07-25 11:03:28 +0800124
125#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
126 /* Now that evt_ivhw is set up, turn this on */
127 trace_buff_offset = 0;
128 bfin_write_TBUFCTL(BFIN_TRACE_ON);
129 printk(KERN_INFO "Hardware Trace expanded to %ik\n",
130 1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN);
131#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700132}