irq_64.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 <linux/ftrace.h>
  16. #include <linux/uaccess.h>
  17. #include <linux/smp.h>
  18. #include <asm/io_apic.h>
  19. #include <asm/idle.h>
  20. DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
  21. EXPORT_PER_CPU_SYMBOL(irq_stat);
  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. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  32. u64 curbase = (u64)task_stack_page(current);
  33. WARN_ONCE(regs->sp >= curbase &&
  34. regs->sp <= curbase + THREAD_SIZE &&
  35. regs->sp < curbase + sizeof(struct thread_info) +
  36. sizeof(struct pt_regs) + 128,
  37. "do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n",
  38. current->comm, curbase, regs->sp);
  39. #endif
  40. }
  41. /*
  42. * do_IRQ handles all normal device IRQ's (the special
  43. * SMP cross-CPU interrupts have their own specific
  44. * handlers).
  45. */
  46. asmlinkage unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
  47. {
  48. struct pt_regs *old_regs = set_irq_regs(regs);
  49. struct irq_desc *desc;
  50. /* high bit used in ret_from_ code */
  51. unsigned vector = ~regs->orig_ax;
  52. unsigned irq;
  53. exit_idle();
  54. irq_enter();
  55. irq = __get_cpu_var(vector_irq)[vector];
  56. stack_overflow_check(regs);
  57. desc = irq_to_desc(irq);
  58. if (likely(desc))
  59. generic_handle_irq_desc(irq, desc);
  60. else {
  61. if (!disable_apic)
  62. ack_APIC_irq();
  63. if (printk_ratelimit())
  64. printk(KERN_EMERG "%s: %d.%d No irq handler for vector\n",
  65. __func__, smp_processor_id(), vector);
  66. }
  67. irq_exit();
  68. set_irq_regs(old_regs);
  69. return 1;
  70. }
  71. #ifdef CONFIG_HOTPLUG_CPU
  72. /* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
  73. void fixup_irqs(void)
  74. {
  75. unsigned int irq;
  76. static int warned;
  77. struct irq_desc *desc;
  78. for_each_irq_desc(irq, desc) {
  79. int break_affinity = 0;
  80. int set_affinity = 1;
  81. const struct cpumask *affinity;
  82. if (!desc)
  83. continue;
  84. if (irq == 2)
  85. continue;
  86. /* interrupt's are disabled at this point */
  87. spin_lock(&desc->lock);
  88. affinity = desc->affinity;
  89. if (!irq_has_action(irq) ||
  90. cpumask_equal(affinity, cpu_online_mask)) {
  91. spin_unlock(&desc->lock);
  92. continue;
  93. }
  94. if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) {
  95. break_affinity = 1;
  96. affinity = cpu_all_mask;
  97. }
  98. if (desc->chip->mask)
  99. desc->chip->mask(irq);
  100. if (desc->chip->set_affinity)
  101. desc->chip->set_affinity(irq, affinity);
  102. else if (!(warned++))
  103. set_affinity = 0;
  104. if (desc->chip->unmask)
  105. desc->chip->unmask(irq);
  106. spin_unlock(&desc->lock);
  107. if (break_affinity && set_affinity)
  108. printk("Broke affinity for irq %i\n", irq);
  109. else if (!set_affinity)
  110. printk("Cannot set affinity for irq %i\n", irq);
  111. }
  112. /* That doesn't seem sufficient. Give it 1ms. */
  113. local_irq_enable();
  114. mdelay(1);
  115. local_irq_disable();
  116. }
  117. #endif
  118. extern void call_softirq(void);
  119. asmlinkage void do_softirq(void)
  120. {
  121. __u32 pending;
  122. unsigned long flags;
  123. if (in_interrupt())
  124. return;
  125. local_irq_save(flags);
  126. pending = local_softirq_pending();
  127. /* Switch to interrupt stack */
  128. if (pending) {
  129. call_softirq();
  130. WARN_ON_ONCE(softirq_count());
  131. }
  132. local_irq_restore(flags);
  133. }