irq_64.c 4.8 KB

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