irq.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * linux/arch/alpha/kernel/irq.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. *
  6. * This file contains the code used by various IRQ handling routines:
  7. * asking for different IRQ's should be done through these routines
  8. * instead of just grabbing them. Thus setups with different IRQ numbers
  9. * shouldn't result in any weird surprises, and installing new handlers
  10. * should be easier.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/errno.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/signal.h>
  18. #include <linux/sched.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/slab.h>
  22. #include <linux/random.h>
  23. #include <linux/init.h>
  24. #include <linux/irq.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/profile.h>
  28. #include <linux/bitops.h>
  29. #include <asm/system.h>
  30. #include <asm/io.h>
  31. #include <asm/uaccess.h>
  32. volatile unsigned long irq_err_count;
  33. void ack_bad_irq(unsigned int irq)
  34. {
  35. irq_err_count++;
  36. printk(KERN_CRIT "Unexpected IRQ trap at vector %u\n", irq);
  37. }
  38. #ifdef CONFIG_SMP
  39. static char irq_user_affinity[NR_IRQS];
  40. int
  41. select_smp_affinity(unsigned int irq)
  42. {
  43. static int last_cpu;
  44. int cpu = last_cpu + 1;
  45. if (!irq_desc[irq].handler->set_affinity || irq_user_affinity[irq])
  46. return 1;
  47. while (!cpu_possible(cpu))
  48. cpu = (cpu < (NR_CPUS-1) ? cpu + 1 : 0);
  49. last_cpu = cpu;
  50. irq_affinity[irq] = cpumask_of_cpu(cpu);
  51. irq_desc[irq].handler->set_affinity(irq, cpumask_of_cpu(cpu));
  52. return 0;
  53. }
  54. #endif /* CONFIG_SMP */
  55. int
  56. show_interrupts(struct seq_file *p, void *v)
  57. {
  58. #ifdef CONFIG_SMP
  59. int j;
  60. #endif
  61. int irq = *(loff_t *) v;
  62. struct irqaction * action;
  63. unsigned long flags;
  64. #ifdef CONFIG_SMP
  65. if (irq == 0) {
  66. seq_puts(p, " ");
  67. for_each_online_cpu(j)
  68. seq_printf(p, "CPU%d ", j);
  69. seq_putc(p, '\n');
  70. }
  71. #endif
  72. if (irq < ACTUAL_NR_IRQS) {
  73. spin_lock_irqsave(&irq_desc[irq].lock, flags);
  74. action = irq_desc[irq].action;
  75. if (!action)
  76. goto unlock;
  77. seq_printf(p, "%3d: ", irq);
  78. #ifndef CONFIG_SMP
  79. seq_printf(p, "%10u ", kstat_irqs(irq));
  80. #else
  81. for_each_online_cpu(j)
  82. seq_printf(p, "%10u ", kstat_cpu(j).irqs[irq]);
  83. #endif
  84. seq_printf(p, " %14s", irq_desc[irq].handler->typename);
  85. seq_printf(p, " %c%s",
  86. (action->flags & SA_INTERRUPT)?'+':' ',
  87. action->name);
  88. for (action=action->next; action; action = action->next) {
  89. seq_printf(p, ", %c%s",
  90. (action->flags & SA_INTERRUPT)?'+':' ',
  91. action->name);
  92. }
  93. seq_putc(p, '\n');
  94. unlock:
  95. spin_unlock_irqrestore(&irq_desc[irq].lock, flags);
  96. } else if (irq == ACTUAL_NR_IRQS) {
  97. #ifdef CONFIG_SMP
  98. seq_puts(p, "IPI: ");
  99. for_each_online_cpu(j)
  100. seq_printf(p, "%10lu ", cpu_data[j].ipi_count);
  101. seq_putc(p, '\n');
  102. #endif
  103. seq_printf(p, "ERR: %10lu\n", irq_err_count);
  104. }
  105. return 0;
  106. }
  107. /*
  108. * handle_irq handles all normal device IRQ's (the special
  109. * SMP cross-CPU interrupts have their own specific
  110. * handlers).
  111. */
  112. #define MAX_ILLEGAL_IRQS 16
  113. void
  114. handle_irq(int irq, struct pt_regs * regs)
  115. {
  116. /*
  117. * We ack quickly, we don't want the irq controller
  118. * thinking we're snobs just because some other CPU has
  119. * disabled global interrupts (we have already done the
  120. * INT_ACK cycles, it's too late to try to pretend to the
  121. * controller that we aren't taking the interrupt).
  122. *
  123. * 0 return value means that this irq is already being
  124. * handled by some other CPU. (or is disabled)
  125. */
  126. static unsigned int illegal_count=0;
  127. if ((unsigned) irq > ACTUAL_NR_IRQS && illegal_count < MAX_ILLEGAL_IRQS ) {
  128. irq_err_count++;
  129. illegal_count++;
  130. printk(KERN_CRIT "device_interrupt: invalid interrupt %d\n",
  131. irq);
  132. return;
  133. }
  134. irq_enter();
  135. local_irq_disable();
  136. __do_IRQ(irq, regs);
  137. local_irq_enable();
  138. irq_exit();
  139. }