irq.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #include <asm/smp.h>
  21. atomic_t irq_err_count;
  22. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  23. /*
  24. * Probabilistic stack overflow check:
  25. *
  26. * Only check the stack in process context, because everything else
  27. * runs on the big interrupt stacks. Checking reliably is too expensive,
  28. * so we just check from interrupts.
  29. */
  30. static inline void stack_overflow_check(struct pt_regs *regs)
  31. {
  32. u64 curbase = (u64)task_stack_page(current);
  33. static unsigned long warned = -60*HZ;
  34. if (regs->rsp >= curbase && regs->rsp <= curbase + THREAD_SIZE &&
  35. regs->rsp < curbase + sizeof(struct thread_info) + 128 &&
  36. time_after(jiffies, warned + 60*HZ)) {
  37. printk("do_IRQ: %s near stack overflow (cur:%Lx,rsp:%lx)\n",
  38. current->comm, curbase, regs->rsp);
  39. show_stack(NULL,NULL);
  40. warned = jiffies;
  41. }
  42. }
  43. #endif
  44. /*
  45. * Generic, controller-independent functions:
  46. */
  47. int show_interrupts(struct seq_file *p, void *v)
  48. {
  49. int i = *(loff_t *) v, j;
  50. struct irqaction * action;
  51. unsigned long flags;
  52. if (i == 0) {
  53. seq_printf(p, " ");
  54. for_each_online_cpu(j)
  55. seq_printf(p, "CPU%-8d",j);
  56. seq_putc(p, '\n');
  57. }
  58. if (i < NR_IRQS) {
  59. spin_lock_irqsave(&irq_desc[i].lock, flags);
  60. action = irq_desc[i].action;
  61. if (!action)
  62. goto skip;
  63. seq_printf(p, "%3d: ",i);
  64. #ifndef CONFIG_SMP
  65. seq_printf(p, "%10u ", kstat_irqs(i));
  66. #else
  67. for_each_online_cpu(j)
  68. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  69. #endif
  70. seq_printf(p, " %8s", irq_desc[i].chip->name);
  71. seq_printf(p, "-%-8s", irq_desc[i].name);
  72. seq_printf(p, " %s", action->name);
  73. for (action=action->next; action; action = action->next)
  74. seq_printf(p, ", %s", action->name);
  75. seq_putc(p, '\n');
  76. skip:
  77. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  78. } else if (i == NR_IRQS) {
  79. seq_printf(p, "NMI: ");
  80. for_each_online_cpu(j)
  81. seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
  82. seq_putc(p, '\n');
  83. seq_printf(p, "LOC: ");
  84. for_each_online_cpu(j)
  85. seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
  86. seq_putc(p, '\n');
  87. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  88. }
  89. return 0;
  90. }
  91. /*
  92. * do_IRQ handles all normal device IRQ's (the special
  93. * SMP cross-CPU interrupts have their own specific
  94. * handlers).
  95. */
  96. asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
  97. {
  98. struct pt_regs *old_regs = set_irq_regs(regs);
  99. /* high bit used in ret_from_ code */
  100. unsigned vector = ~regs->orig_rax;
  101. unsigned irq;
  102. exit_idle();
  103. irq_enter();
  104. irq = __get_cpu_var(vector_irq)[vector];
  105. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  106. stack_overflow_check(regs);
  107. #endif
  108. if (likely(irq < NR_IRQS))
  109. generic_handle_irq(irq);
  110. else {
  111. if (!disable_apic)
  112. ack_APIC_irq();
  113. if (printk_ratelimit())
  114. printk(KERN_EMERG "%s: %d.%d No irq handler for vector\n",
  115. __func__, smp_processor_id(), vector);
  116. }
  117. irq_exit();
  118. set_irq_regs(old_regs);
  119. return 1;
  120. }
  121. #ifdef CONFIG_HOTPLUG_CPU
  122. void fixup_irqs(cpumask_t map)
  123. {
  124. unsigned int irq;
  125. static int warned;
  126. for (irq = 0; irq < NR_IRQS; irq++) {
  127. cpumask_t mask;
  128. int break_affinity = 0;
  129. int set_affinity = 1;
  130. if (irq == 2)
  131. continue;
  132. /* interrupt's are disabled at this point */
  133. spin_lock(&irq_desc[irq].lock);
  134. if (!irq_has_action(irq) ||
  135. cpus_equal(irq_desc[irq].affinity, map)) {
  136. spin_unlock(&irq_desc[irq].lock);
  137. continue;
  138. }
  139. cpus_and(mask, irq_desc[irq].affinity, map);
  140. if (cpus_empty(mask)) {
  141. break_affinity = 1;
  142. mask = map;
  143. }
  144. if (irq_desc[irq].chip->mask)
  145. irq_desc[irq].chip->mask(irq);
  146. if (irq_desc[irq].chip->set_affinity)
  147. irq_desc[irq].chip->set_affinity(irq, mask);
  148. else if (!(warned++))
  149. set_affinity = 0;
  150. if (irq_desc[irq].chip->unmask)
  151. irq_desc[irq].chip->unmask(irq);
  152. spin_unlock(&irq_desc[irq].lock);
  153. if (break_affinity && set_affinity)
  154. printk("Broke affinity for irq %i\n", irq);
  155. else if (!set_affinity)
  156. printk("Cannot set affinity for irq %i\n", irq);
  157. }
  158. /* That doesn't seem sufficient. Give it 1ms. */
  159. local_irq_enable();
  160. mdelay(1);
  161. local_irq_disable();
  162. }
  163. #endif
  164. extern void call_softirq(void);
  165. asmlinkage void do_softirq(void)
  166. {
  167. __u32 pending;
  168. unsigned long flags;
  169. if (in_interrupt())
  170. return;
  171. local_irq_save(flags);
  172. pending = local_softirq_pending();
  173. /* Switch to interrupt stack */
  174. if (pending) {
  175. call_softirq();
  176. WARN_ON_ONCE(softirq_count());
  177. }
  178. local_irq_restore(flags);
  179. }
  180. EXPORT_SYMBOL(do_softirq);