irqchip.c 3.8 KB

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