irqchip.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 2005-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later
  5. */
  6. #include <linux/kernel_stat.h>
  7. #include <linux/module.h>
  8. #include <linux/random.h>
  9. #include <linux/seq_file.h>
  10. #include <linux/kallsyms.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/irq.h>
  13. #include <asm/trace.h>
  14. #include <asm/pda.h>
  15. static atomic_t irq_err_count;
  16. void ack_bad_irq(unsigned int irq)
  17. {
  18. atomic_inc(&irq_err_count);
  19. printk(KERN_ERR "IRQ: spurious interrupt %d\n", irq);
  20. }
  21. static struct irq_desc bad_irq_desc = {
  22. .handle_irq = handle_bad_irq,
  23. .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
  24. };
  25. #ifdef CONFIG_CPUMASK_OFFSTACK
  26. /* We are not allocating a variable-sized bad_irq_desc.affinity */
  27. #error "Blackfin architecture does not support CONFIG_CPUMASK_OFFSTACK."
  28. #endif
  29. #ifdef CONFIG_PROC_FS
  30. int show_interrupts(struct seq_file *p, void *v)
  31. {
  32. int i = *(loff_t *) v, j;
  33. struct irqaction *action;
  34. unsigned long flags;
  35. if (i < NR_IRQS) {
  36. spin_lock_irqsave(&irq_desc[i].lock, flags);
  37. action = irq_desc[i].action;
  38. if (!action)
  39. goto skip;
  40. seq_printf(p, "%3d: ", i);
  41. for_each_online_cpu(j)
  42. seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
  43. seq_printf(p, " %8s", irq_desc[i].chip->name);
  44. seq_printf(p, " %s", action->name);
  45. for (action = action->next; action; action = action->next)
  46. seq_printf(p, " %s", action->name);
  47. seq_putc(p, '\n');
  48. skip:
  49. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  50. } else if (i == NR_IRQS) {
  51. seq_printf(p, "NMI: ");
  52. for_each_online_cpu(j)
  53. seq_printf(p, "%10u ", cpu_pda[j].__nmi_count);
  54. seq_printf(p, " CORE Non Maskable Interrupt\n");
  55. seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
  56. }
  57. return 0;
  58. }
  59. #endif
  60. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  61. static void check_stack_overflow(int irq)
  62. {
  63. /* Debugging check for stack overflow: is there less than STACK_WARN free? */
  64. long sp = __get_SP() & (THREAD_SIZE - 1);
  65. if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
  66. dump_stack();
  67. pr_emerg("irq%i: possible stack overflow only %ld bytes free\n",
  68. irq, sp - sizeof(struct thread_info));
  69. }
  70. }
  71. #else
  72. static inline void check_stack_overflow(int irq) { }
  73. #endif
  74. #ifndef CONFIG_IPIPE
  75. static void maybe_lower_to_irq14(void)
  76. {
  77. unsigned short pending, other_ints;
  78. /*
  79. * If we're the only interrupt running (ignoring IRQ15 which
  80. * is for syscalls), lower our priority to IRQ14 so that
  81. * softirqs run at that level. If there's another,
  82. * lower-level interrupt, irq_exit will defer softirqs to
  83. * that. If the interrupt pipeline is enabled, we are already
  84. * running at IRQ14 priority, so we don't need this code.
  85. */
  86. CSYNC();
  87. pending = bfin_read_IPEND() & ~0x8000;
  88. other_ints = pending & (pending - 1);
  89. if (other_ints == 0)
  90. lower_to_irq14();
  91. }
  92. #else
  93. static inline void maybe_lower_to_irq14(void) { }
  94. #endif
  95. /*
  96. * do_IRQ handles all hardware IRQs. Decoded IRQs should not
  97. * come via this function. Instead, they should provide their
  98. * own 'handler'
  99. */
  100. #ifdef CONFIG_DO_IRQ_L1
  101. __attribute__((l1_text))
  102. #endif
  103. asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
  104. {
  105. struct pt_regs *old_regs = set_irq_regs(regs);
  106. irq_enter();
  107. check_stack_overflow(irq);
  108. /*
  109. * Some hardware gives randomly wrong interrupts. Rather
  110. * than crashing, do something sensible.
  111. */
  112. if (irq >= NR_IRQS)
  113. handle_bad_irq(irq, &bad_irq_desc);
  114. else
  115. generic_handle_irq(irq);
  116. maybe_lower_to_irq14();
  117. irq_exit();
  118. set_irq_regs(old_regs);
  119. }
  120. void __init init_IRQ(void)
  121. {
  122. init_arch_irq();
  123. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  124. /* Now that evt_ivhw is set up, turn this on */
  125. trace_buff_offset = 0;
  126. bfin_write_TBUFCTL(BFIN_TRACE_ON);
  127. printk(KERN_INFO "Hardware Trace expanded to %ik\n",
  128. 1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN);
  129. #endif
  130. }