irq.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Code to handle x86 style IRQs plus some generic interrupt stuff.
  7. *
  8. * Copyright (C) 1992 Linus Torvalds
  9. * Copyright (C) 1994 - 2000 Ralf Baechle
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/delay.h>
  13. #include <linux/init.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/kernel_stat.h>
  16. #include <linux/proc_fs.h>
  17. #include <linux/mm.h>
  18. #include <linux/random.h>
  19. #include <linux/sched.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/kallsyms.h>
  22. #include <linux/kgdb.h>
  23. #include <linux/ftrace.h>
  24. #include <linux/atomic.h>
  25. #include <asm/system.h>
  26. #include <asm/uaccess.h>
  27. #ifdef CONFIG_KGDB
  28. int kgdb_early_setup;
  29. #endif
  30. static unsigned long irq_map[NR_IRQS / BITS_PER_LONG];
  31. int allocate_irqno(void)
  32. {
  33. int irq;
  34. again:
  35. irq = find_first_zero_bit(irq_map, NR_IRQS);
  36. if (irq >= NR_IRQS)
  37. return -ENOSPC;
  38. if (test_and_set_bit(irq, irq_map))
  39. goto again;
  40. return irq;
  41. }
  42. /*
  43. * Allocate the 16 legacy interrupts for i8259 devices. This happens early
  44. * in the kernel initialization so treating allocation failure as BUG() is
  45. * ok.
  46. */
  47. void __init alloc_legacy_irqno(void)
  48. {
  49. int i;
  50. for (i = 0; i <= 16; i++)
  51. BUG_ON(test_and_set_bit(i, irq_map));
  52. }
  53. void free_irqno(unsigned int irq)
  54. {
  55. smp_mb__before_clear_bit();
  56. clear_bit(irq, irq_map);
  57. smp_mb__after_clear_bit();
  58. }
  59. /*
  60. * 'what should we do if we get a hw irq event on an illegal vector'.
  61. * each architecture has to answer this themselves.
  62. */
  63. void ack_bad_irq(unsigned int irq)
  64. {
  65. smtc_im_ack_irq(irq);
  66. printk("unexpected IRQ # %d\n", irq);
  67. }
  68. atomic_t irq_err_count;
  69. int arch_show_interrupts(struct seq_file *p, int prec)
  70. {
  71. seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
  72. return 0;
  73. }
  74. asmlinkage void spurious_interrupt(void)
  75. {
  76. atomic_inc(&irq_err_count);
  77. }
  78. void __init init_IRQ(void)
  79. {
  80. int i;
  81. #ifdef CONFIG_KGDB
  82. if (kgdb_early_setup)
  83. return;
  84. #endif
  85. for (i = 0; i < NR_IRQS; i++)
  86. irq_set_noprobe(i);
  87. arch_init_irq();
  88. #ifdef CONFIG_KGDB
  89. if (!kgdb_early_setup)
  90. kgdb_early_setup = 1;
  91. #endif
  92. }
  93. #ifdef DEBUG_STACKOVERFLOW
  94. static inline void check_stack_overflow(void)
  95. {
  96. unsigned long sp;
  97. __asm__ __volatile__("move %0, $sp" : "=r" (sp));
  98. sp &= THREAD_MASK;
  99. /*
  100. * Check for stack overflow: is there less than STACK_WARN free?
  101. * STACK_WARN is defined as 1/8 of THREAD_SIZE by default.
  102. */
  103. if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
  104. printk("do_IRQ: stack overflow: %ld\n",
  105. sp - sizeof(struct thread_info));
  106. dump_stack();
  107. }
  108. }
  109. #else
  110. static inline void check_stack_overflow(void) {}
  111. #endif
  112. /*
  113. * do_IRQ handles all normal device IRQ's (the special
  114. * SMP cross-CPU interrupts have their own specific
  115. * handlers).
  116. */
  117. void __irq_entry do_IRQ(unsigned int irq)
  118. {
  119. irq_enter();
  120. check_stack_overflow();
  121. if (!smtc_handle_on_other_cpu(irq))
  122. generic_handle_irq(irq);
  123. irq_exit();
  124. }
  125. #ifdef CONFIG_MIPS_MT_SMTC_IRQAFF
  126. /*
  127. * To avoid inefficient and in some cases pathological re-checking of
  128. * IRQ affinity, we have this variant that skips the affinity check.
  129. */
  130. void __irq_entry do_IRQ_no_affinity(unsigned int irq)
  131. {
  132. irq_enter();
  133. smtc_im_backstop(irq);
  134. generic_handle_irq(irq);
  135. irq_exit();
  136. }
  137. #endif /* CONFIG_MIPS_MT_SMTC_IRQAFF */