irq.c 4.2 KB

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