irq.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 i = *(loff_t *) v;
  62. struct irqaction * action;
  63. unsigned long flags;
  64. #ifdef CONFIG_SMP
  65. if (i == 0) {
  66. seq_puts(p, " ");
  67. for (i = 0; i < NR_CPUS; i++)
  68. if (cpu_online(i))
  69. seq_printf(p, "CPU%d ", i);
  70. seq_putc(p, '\n');
  71. }
  72. #endif
  73. if (i < ACTUAL_NR_IRQS) {
  74. spin_lock_irqsave(&irq_desc[i].lock, flags);
  75. action = irq_desc[i].action;
  76. if (!action)
  77. goto unlock;
  78. seq_printf(p, "%3d: ",i);
  79. #ifndef CONFIG_SMP
  80. seq_printf(p, "%10u ", kstat_irqs(i));
  81. #else
  82. for (j = 0; j < NR_CPUS; j++)
  83. if (cpu_online(j))
  84. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  85. #endif
  86. seq_printf(p, " %14s", irq_desc[i].handler->typename);
  87. seq_printf(p, " %c%s",
  88. (action->flags & SA_INTERRUPT)?'+':' ',
  89. action->name);
  90. for (action=action->next; action; action = action->next) {
  91. seq_printf(p, ", %c%s",
  92. (action->flags & SA_INTERRUPT)?'+':' ',
  93. action->name);
  94. }
  95. seq_putc(p, '\n');
  96. unlock:
  97. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  98. } else if (i == ACTUAL_NR_IRQS) {
  99. #ifdef CONFIG_SMP
  100. seq_puts(p, "IPI: ");
  101. for (i = 0; i < NR_CPUS; i++)
  102. if (cpu_online(i))
  103. seq_printf(p, "%10lu ", cpu_data[i].ipi_count);
  104. seq_putc(p, '\n');
  105. #endif
  106. seq_printf(p, "ERR: %10lu\n", irq_err_count);
  107. }
  108. return 0;
  109. }
  110. /*
  111. * handle_irq handles all normal device IRQ's (the special
  112. * SMP cross-CPU interrupts have their own specific
  113. * handlers).
  114. */
  115. #define MAX_ILLEGAL_IRQS 16
  116. void
  117. handle_irq(int irq, struct pt_regs * regs)
  118. {
  119. /*
  120. * We ack quickly, we don't want the irq controller
  121. * thinking we're snobs just because some other CPU has
  122. * disabled global interrupts (we have already done the
  123. * INT_ACK cycles, it's too late to try to pretend to the
  124. * controller that we aren't taking the interrupt).
  125. *
  126. * 0 return value means that this irq is already being
  127. * handled by some other CPU. (or is disabled)
  128. */
  129. static unsigned int illegal_count=0;
  130. if ((unsigned) irq > ACTUAL_NR_IRQS && illegal_count < MAX_ILLEGAL_IRQS ) {
  131. irq_err_count++;
  132. illegal_count++;
  133. printk(KERN_CRIT "device_interrupt: invalid interrupt %d\n",
  134. irq);
  135. return;
  136. }
  137. irq_enter();
  138. local_irq_disable();
  139. __do_IRQ(irq, regs);
  140. local_irq_enable();
  141. irq_exit();
  142. }