irq.c 3.4 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/module.h>
  17. #include <linux/proc_fs.h>
  18. #include <linux/slab.h>
  19. #include <linux/mm.h>
  20. #include <linux/random.h>
  21. #include <linux/sched.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/kallsyms.h>
  24. #include <asm/atomic.h>
  25. #include <asm/system.h>
  26. #include <asm/uaccess.h>
  27. static unsigned long irq_map[NR_IRQS / BITS_PER_LONG];
  28. int __devinit allocate_irqno(void)
  29. {
  30. int irq;
  31. again:
  32. irq = find_first_zero_bit(irq_map, NR_IRQS);
  33. if (irq >= NR_IRQS)
  34. return -ENOSPC;
  35. if (test_and_set_bit(irq, irq_map))
  36. goto again;
  37. return irq;
  38. }
  39. EXPORT_SYMBOL_GPL(allocate_irqno);
  40. /*
  41. * Allocate the 16 legacy interrupts for i8259 devices. This happens early
  42. * in the kernel initialization so treating allocation failure as BUG() is
  43. * ok.
  44. */
  45. void __init alloc_legacy_irqno(void)
  46. {
  47. int i;
  48. for (i = 0; i <= 16; i++)
  49. BUG_ON(test_and_set_bit(i, irq_map));
  50. }
  51. void __devinit free_irqno(unsigned int irq)
  52. {
  53. smp_mb__before_clear_bit();
  54. clear_bit(irq, irq_map);
  55. smp_mb__after_clear_bit();
  56. }
  57. EXPORT_SYMBOL_GPL(free_irqno);
  58. /*
  59. * 'what should we do if we get a hw irq event on an illegal vector'.
  60. * each architecture has to answer this themselves.
  61. */
  62. void ack_bad_irq(unsigned int irq)
  63. {
  64. printk("unexpected IRQ # %d\n", irq);
  65. }
  66. atomic_t irq_err_count;
  67. #ifdef CONFIG_MIPS_MT_SMTC
  68. /*
  69. * SMTC Kernel needs to manipulate low-level CPU interrupt mask
  70. * in do_IRQ. These are passed in setup_irq_smtc() and stored
  71. * in this table.
  72. */
  73. unsigned long irq_hwmask[NR_IRQS];
  74. #endif /* CONFIG_MIPS_MT_SMTC */
  75. /*
  76. * Generic, controller-independent functions:
  77. */
  78. int show_interrupts(struct seq_file *p, void *v)
  79. {
  80. int i = *(loff_t *) v, j;
  81. struct irqaction * action;
  82. unsigned long flags;
  83. if (i == 0) {
  84. seq_printf(p, " ");
  85. for_each_online_cpu(j)
  86. seq_printf(p, "CPU%d ",j);
  87. seq_putc(p, '\n');
  88. }
  89. if (i < NR_IRQS) {
  90. spin_lock_irqsave(&irq_desc[i].lock, flags);
  91. action = irq_desc[i].action;
  92. if (!action)
  93. goto skip;
  94. seq_printf(p, "%3d: ",i);
  95. #ifndef CONFIG_SMP
  96. seq_printf(p, "%10u ", kstat_irqs(i));
  97. #else
  98. for_each_online_cpu(j)
  99. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  100. #endif
  101. seq_printf(p, " %14s", irq_desc[i].chip->name);
  102. seq_printf(p, " %s", action->name);
  103. for (action=action->next; action; action = action->next)
  104. seq_printf(p, ", %s", action->name);
  105. seq_putc(p, '\n');
  106. skip:
  107. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  108. } else if (i == NR_IRQS) {
  109. seq_putc(p, '\n');
  110. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  111. }
  112. return 0;
  113. }
  114. asmlinkage void spurious_interrupt(void)
  115. {
  116. atomic_inc(&irq_err_count);
  117. }
  118. #ifdef CONFIG_KGDB
  119. extern void breakpoint(void);
  120. extern void set_debug_traps(void);
  121. static int kgdb_flag = 1;
  122. static int __init nokgdb(char *str)
  123. {
  124. kgdb_flag = 0;
  125. return 1;
  126. }
  127. __setup("nokgdb", nokgdb);
  128. #endif
  129. void __init init_IRQ(void)
  130. {
  131. arch_init_irq();
  132. #ifdef CONFIG_KGDB
  133. if (kgdb_flag) {
  134. printk("Wait for gdb client connection ...\n");
  135. set_debug_traps();
  136. breakpoint();
  137. }
  138. #endif
  139. }