irq.c 4.2 KB

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