irqchip.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 = __RAW_SPIN_LOCK_UNLOCKED(bad_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. struct irq_desc *desc = irq_to_desc(i);
  37. raw_spin_lock_irqsave(&desc->lock, flags);
  38. action = desc->action;
  39. if (!action)
  40. goto skip;
  41. seq_printf(p, "%3d: ", i);
  42. for_each_online_cpu(j)
  43. seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
  44. seq_printf(p, " %8s", irq_desc_get_chip(desc)->name);
  45. seq_printf(p, " %s", action->name);
  46. for (action = action->next; action; action = action->next)
  47. seq_printf(p, " %s", action->name);
  48. seq_putc(p, '\n');
  49. skip:
  50. raw_spin_unlock_irqrestore(&desc->lock, flags);
  51. } else if (i == NR_IRQS) {
  52. seq_printf(p, "NMI: ");
  53. for_each_online_cpu(j)
  54. seq_printf(p, "%10u ", cpu_pda[j].__nmi_count);
  55. seq_printf(p, " CORE Non Maskable Interrupt\n");
  56. seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
  57. }
  58. return 0;
  59. }
  60. #endif
  61. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  62. static void check_stack_overflow(int irq)
  63. {
  64. /* Debugging check for stack overflow: is there less than STACK_WARN free? */
  65. long sp = __get_SP() & (THREAD_SIZE - 1);
  66. if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
  67. dump_stack();
  68. pr_emerg("irq%i: possible stack overflow only %ld bytes free\n",
  69. irq, sp - sizeof(struct thread_info));
  70. }
  71. }
  72. #else
  73. static inline void check_stack_overflow(int irq) { }
  74. #endif
  75. #ifndef CONFIG_IPIPE
  76. static void maybe_lower_to_irq14(void)
  77. {
  78. unsigned short pending, other_ints;
  79. /*
  80. * If we're the only interrupt running (ignoring IRQ15 which
  81. * is for syscalls), lower our priority to IRQ14 so that
  82. * softirqs run at that level. If there's another,
  83. * lower-level interrupt, irq_exit will defer softirqs to
  84. * that. If the interrupt pipeline is enabled, we are already
  85. * running at IRQ14 priority, so we don't need this code.
  86. */
  87. CSYNC();
  88. pending = bfin_read_IPEND() & ~0x8000;
  89. other_ints = pending & (pending - 1);
  90. if (other_ints == 0)
  91. lower_to_irq14();
  92. }
  93. #else
  94. static inline void maybe_lower_to_irq14(void) { }
  95. #endif
  96. /*
  97. * do_IRQ handles all hardware IRQs. Decoded IRQs should not
  98. * come via this function. Instead, they should provide their
  99. * own 'handler'
  100. */
  101. #ifdef CONFIG_DO_IRQ_L1
  102. __attribute__((l1_text))
  103. #endif
  104. asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
  105. {
  106. struct pt_regs *old_regs = set_irq_regs(regs);
  107. irq_enter();
  108. check_stack_overflow(irq);
  109. /*
  110. * Some hardware gives randomly wrong interrupts. Rather
  111. * than crashing, do something sensible.
  112. */
  113. if (irq >= NR_IRQS)
  114. handle_bad_irq(irq, &bad_irq_desc);
  115. else
  116. generic_handle_irq(irq);
  117. maybe_lower_to_irq14();
  118. irq_exit();
  119. set_irq_regs(old_regs);
  120. }
  121. void __init init_IRQ(void)
  122. {
  123. init_arch_irq();
  124. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  125. /* Now that evt_ivhw is set up, turn this on */
  126. trace_buff_offset = 0;
  127. bfin_write_TBUFCTL(BFIN_TRACE_ON);
  128. printk(KERN_INFO "Hardware Trace expanded to %ik\n",
  129. 1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN);
  130. #endif
  131. }