irqinit_32.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #include <linux/errno.h>
  2. #include <linux/signal.h>
  3. #include <linux/sched.h>
  4. #include <linux/ioport.h>
  5. #include <linux/interrupt.h>
  6. #include <linux/slab.h>
  7. #include <linux/random.h>
  8. #include <linux/init.h>
  9. #include <linux/kernel_stat.h>
  10. #include <linux/sysdev.h>
  11. #include <linux/bitops.h>
  12. #include <linux/io.h>
  13. #include <linux/delay.h>
  14. #include <asm/atomic.h>
  15. #include <asm/system.h>
  16. #include <asm/timer.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/desc.h>
  19. #include <asm/apic.h>
  20. #include <asm/setup.h>
  21. #include <asm/i8259.h>
  22. #include <asm/traps.h>
  23. /*
  24. * Note that on a 486, we don't want to do a SIGFPE on an irq13
  25. * as the irq is unreliable, and exception 16 works correctly
  26. * (ie as explained in the intel literature). On a 386, you
  27. * can't use exception 16 due to bad IBM design, so we have to
  28. * rely on the less exact irq13.
  29. *
  30. * Careful.. Not only is IRQ13 unreliable, but it is also
  31. * leads to races. IBM designers who came up with it should
  32. * be shot.
  33. */
  34. static irqreturn_t math_error_irq(int cpl, void *dev_id)
  35. {
  36. outb(0, 0xF0);
  37. if (ignore_fpu_irq || !boot_cpu_data.hard_math)
  38. return IRQ_NONE;
  39. math_error((void __user *)get_irq_regs()->ip);
  40. return IRQ_HANDLED;
  41. }
  42. /*
  43. * New motherboards sometimes make IRQ 13 be a PCI interrupt,
  44. * so allow interrupt sharing.
  45. */
  46. static struct irqaction fpu_irq = {
  47. .handler = math_error_irq,
  48. .name = "fpu",
  49. };
  50. /*
  51. * IRQ2 is cascade interrupt to second interrupt controller
  52. */
  53. static struct irqaction irq2 = {
  54. .handler = no_action,
  55. .name = "cascade",
  56. };
  57. DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
  58. [0 ... IRQ0_VECTOR - 1] = -1,
  59. [IRQ0_VECTOR] = 0,
  60. [IRQ1_VECTOR] = 1,
  61. [IRQ2_VECTOR] = 2,
  62. [IRQ3_VECTOR] = 3,
  63. [IRQ4_VECTOR] = 4,
  64. [IRQ5_VECTOR] = 5,
  65. [IRQ6_VECTOR] = 6,
  66. [IRQ7_VECTOR] = 7,
  67. [IRQ8_VECTOR] = 8,
  68. [IRQ9_VECTOR] = 9,
  69. [IRQ10_VECTOR] = 10,
  70. [IRQ11_VECTOR] = 11,
  71. [IRQ12_VECTOR] = 12,
  72. [IRQ13_VECTOR] = 13,
  73. [IRQ14_VECTOR] = 14,
  74. [IRQ15_VECTOR] = 15,
  75. [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1
  76. };
  77. int vector_used_by_percpu_irq(unsigned int vector)
  78. {
  79. int cpu;
  80. for_each_online_cpu(cpu) {
  81. if (per_cpu(vector_irq, cpu)[vector] != -1)
  82. return 1;
  83. }
  84. return 0;
  85. }
  86. static void __init init_ISA_irqs(void)
  87. {
  88. int i;
  89. #if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
  90. init_bsp_APIC();
  91. #endif
  92. init_8259A(0);
  93. /*
  94. * 16 old-style INTA-cycle interrupts:
  95. */
  96. for (i = 0; i < NR_IRQS_LEGACY; i++) {
  97. struct irq_desc *desc = irq_to_desc(i);
  98. desc->status = IRQ_DISABLED;
  99. desc->action = NULL;
  100. desc->depth = 1;
  101. set_irq_chip_and_handler_name(i, &i8259A_chip,
  102. handle_level_irq, "XT");
  103. }
  104. }
  105. /* Overridden in paravirt.c */
  106. void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ")));
  107. static void __init smp_intr_init(void)
  108. {
  109. #ifdef CONFIG_SMP
  110. #if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
  111. /*
  112. * The reschedule interrupt is a CPU-to-CPU reschedule-helper
  113. * IPI, driven by wakeup.
  114. */
  115. alloc_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
  116. /* IPIs for invalidation */
  117. alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+0, invalidate_interrupt0);
  118. alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+1, invalidate_interrupt1);
  119. alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+2, invalidate_interrupt2);
  120. alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+3, invalidate_interrupt3);
  121. alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+4, invalidate_interrupt4);
  122. alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+5, invalidate_interrupt5);
  123. alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+6, invalidate_interrupt6);
  124. alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+7, invalidate_interrupt7);
  125. /* IPI for generic function call */
  126. alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
  127. /* IPI for generic single function call */
  128. alloc_intr_gate(CALL_FUNCTION_SINGLE_VECTOR,
  129. call_function_single_interrupt);
  130. /* Low priority IPI to cleanup after moving an irq */
  131. set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt);
  132. set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors);
  133. #endif
  134. #endif /* CONFIG_SMP */
  135. }
  136. /**
  137. * x86_quirk_pre_intr_init - initialisation prior to setting up interrupt vectors
  138. *
  139. * Description:
  140. * Perform any necessary interrupt initialisation prior to setting up
  141. * the "ordinary" interrupt call gates. For legacy reasons, the ISA
  142. * interrupts should be initialised here if the machine emulates a PC
  143. * in any way.
  144. **/
  145. static void __init x86_quirk_pre_intr_init(void)
  146. {
  147. if (x86_quirks->arch_pre_intr_init) {
  148. if (x86_quirks->arch_pre_intr_init())
  149. return;
  150. }
  151. init_ISA_irqs();
  152. }
  153. static void __init apic_intr_init(void)
  154. {
  155. smp_intr_init();
  156. #ifdef CONFIG_X86_LOCAL_APIC
  157. /* self generated IPI for local APIC timer */
  158. alloc_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
  159. /* generic IPI for platform specific use */
  160. alloc_intr_gate(GENERIC_INTERRUPT_VECTOR, generic_interrupt);
  161. /* IPI vectors for APIC spurious and error interrupts */
  162. alloc_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
  163. alloc_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
  164. #endif
  165. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_MCE_P4THERMAL)
  166. /* thermal monitor LVT interrupt */
  167. alloc_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
  168. #endif
  169. }
  170. void __init native_init_IRQ(void)
  171. {
  172. int i;
  173. /* Execute any quirks before the call gates are initialised: */
  174. x86_quirk_pre_intr_init();
  175. /*
  176. * Cover the whole vector space, no vector can escape
  177. * us. (some of these will be overridden and become
  178. * 'special' SMP interrupts)
  179. */
  180. for (i = FIRST_EXTERNAL_VECTOR; i < NR_VECTORS; i++) {
  181. /* SYSCALL_VECTOR was reserved in trap_init. */
  182. if (i != SYSCALL_VECTOR)
  183. set_intr_gate(i, interrupt[i-FIRST_EXTERNAL_VECTOR]);
  184. }
  185. apic_intr_init();
  186. if (!acpi_ioapic)
  187. setup_irq(2, &irq2);
  188. /*
  189. * Call quirks after call gates are initialised (usually add in
  190. * the architecture specific gates):
  191. */
  192. x86_quirk_intr_init();
  193. /*
  194. * External FPU? Set up irq13 if so, for
  195. * original braindamaged IBM FERR coupling.
  196. */
  197. if (boot_cpu_data.hard_math && !cpu_has_fpu)
  198. setup_irq(FPU_IRQ, &fpu_irq);
  199. irq_ctx_init(smp_processor_id());
  200. }