irq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * linux/arch/x86_64/kernel/irq.c
  3. *
  4. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  5. *
  6. * This file contains the lowest level x86_64-specific interrupt
  7. * entry and irq statistics code. All the remaining irq logic is
  8. * done by the generic kernel/irq/ code and in the
  9. * x86_64-specific irq controller code. (e.g. i8259.c and
  10. * io_apic.c.)
  11. */
  12. #include <linux/kernel_stat.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/module.h>
  16. #include <linux/delay.h>
  17. #include <asm/uaccess.h>
  18. #include <asm/io_apic.h>
  19. #include <asm/idle.h>
  20. atomic_t irq_err_count;
  21. #ifdef CONFIG_X86_IO_APIC
  22. #ifdef APIC_MISMATCH_DEBUG
  23. atomic_t irq_mis_count;
  24. #endif
  25. #endif
  26. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  27. /*
  28. * Probabilistic stack overflow check:
  29. *
  30. * Only check the stack in process context, because everything else
  31. * runs on the big interrupt stacks. Checking reliably is too expensive,
  32. * so we just check from interrupts.
  33. */
  34. static inline void stack_overflow_check(struct pt_regs *regs)
  35. {
  36. u64 curbase = (u64) current->thread_info;
  37. static unsigned long warned = -60*HZ;
  38. if (regs->rsp >= curbase && regs->rsp <= curbase + THREAD_SIZE &&
  39. regs->rsp < curbase + sizeof(struct thread_info) + 128 &&
  40. time_after(jiffies, warned + 60*HZ)) {
  41. printk("do_IRQ: %s near stack overflow (cur:%Lx,rsp:%lx)\n",
  42. current->comm, curbase, regs->rsp);
  43. show_stack(NULL,NULL);
  44. warned = jiffies;
  45. }
  46. }
  47. #endif
  48. /*
  49. * Generic, controller-independent functions:
  50. */
  51. int show_interrupts(struct seq_file *p, void *v)
  52. {
  53. int i = *(loff_t *) v, j;
  54. struct irqaction * action;
  55. unsigned long flags;
  56. if (i == 0) {
  57. seq_printf(p, " ");
  58. for_each_online_cpu(j)
  59. seq_printf(p, "CPU%-8d",j);
  60. seq_putc(p, '\n');
  61. }
  62. if (i < NR_IRQS) {
  63. spin_lock_irqsave(&irq_desc[i].lock, flags);
  64. action = irq_desc[i].action;
  65. if (!action)
  66. goto skip;
  67. seq_printf(p, "%3d: ",i);
  68. #ifndef CONFIG_SMP
  69. seq_printf(p, "%10u ", kstat_irqs(i));
  70. #else
  71. for_each_online_cpu(j)
  72. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  73. #endif
  74. seq_printf(p, " %14s", irq_desc[i].chip->typename);
  75. seq_printf(p, " %s", action->name);
  76. for (action=action->next; action; action = action->next)
  77. seq_printf(p, ", %s", action->name);
  78. seq_putc(p, '\n');
  79. skip:
  80. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  81. } else if (i == NR_IRQS) {
  82. seq_printf(p, "NMI: ");
  83. for_each_online_cpu(j)
  84. seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
  85. seq_putc(p, '\n');
  86. #ifdef CONFIG_X86_LOCAL_APIC
  87. seq_printf(p, "LOC: ");
  88. for_each_online_cpu(j)
  89. seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
  90. seq_putc(p, '\n');
  91. #endif
  92. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  93. #ifdef CONFIG_X86_IO_APIC
  94. #ifdef APIC_MISMATCH_DEBUG
  95. seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
  96. #endif
  97. #endif
  98. }
  99. return 0;
  100. }
  101. /*
  102. * do_IRQ handles all normal device IRQ's (the special
  103. * SMP cross-CPU interrupts have their own specific
  104. * handlers).
  105. */
  106. asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
  107. {
  108. /* high bit used in ret_from_ code */
  109. unsigned irq = ~regs->orig_rax;
  110. if (unlikely(irq >= NR_IRQS)) {
  111. printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
  112. __FUNCTION__, irq);
  113. BUG();
  114. }
  115. exit_idle();
  116. irq_enter();
  117. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  118. stack_overflow_check(regs);
  119. #endif
  120. __do_IRQ(irq, regs);
  121. irq_exit();
  122. return 1;
  123. }
  124. #ifdef CONFIG_HOTPLUG_CPU
  125. void fixup_irqs(cpumask_t map)
  126. {
  127. unsigned int irq;
  128. static int warned;
  129. for (irq = 0; irq < NR_IRQS; irq++) {
  130. cpumask_t mask;
  131. if (irq == 2)
  132. continue;
  133. cpus_and(mask, irq_desc[irq].affinity, map);
  134. if (any_online_cpu(mask) == NR_CPUS) {
  135. printk("Breaking affinity for irq %i\n", irq);
  136. mask = map;
  137. }
  138. if (irq_desc[irq].chip->set_affinity)
  139. irq_desc[irq].chip->set_affinity(irq, mask);
  140. else if (irq_desc[irq].action && !(warned++))
  141. printk("Cannot set affinity for irq %i\n", irq);
  142. }
  143. /* That doesn't seem sufficient. Give it 1ms. */
  144. local_irq_enable();
  145. mdelay(1);
  146. local_irq_disable();
  147. }
  148. #endif
  149. extern void call_softirq(void);
  150. asmlinkage void do_softirq(void)
  151. {
  152. __u32 pending;
  153. unsigned long flags;
  154. if (in_interrupt())
  155. return;
  156. local_irq_save(flags);
  157. pending = local_softirq_pending();
  158. /* Switch to interrupt stack */
  159. if (pending) {
  160. call_softirq();
  161. WARN_ON_ONCE(softirq_count());
  162. }
  163. local_irq_restore(flags);
  164. }
  165. EXPORT_SYMBOL(do_softirq);