irq_remapping.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include <linux/cpumask.h>
  2. #include <linux/kernel.h>
  3. #include <linux/string.h>
  4. #include <linux/cpumask.h>
  5. #include <linux/errno.h>
  6. #include <linux/msi.h>
  7. #include <asm/hw_irq.h>
  8. #include <asm/irq_remapping.h>
  9. #include <asm/processor.h>
  10. #include <asm/x86_init.h>
  11. #include <asm/apic.h>
  12. #include "irq_remapping.h"
  13. int irq_remapping_enabled;
  14. int disable_irq_remap;
  15. int disable_sourceid_checking;
  16. int no_x2apic_optout;
  17. static struct irq_remap_ops *remap_ops;
  18. static void irq_remapping_disable_io_apic(void)
  19. {
  20. /*
  21. * With interrupt-remapping, for now we will use virtual wire A
  22. * mode, as virtual wire B is little complex (need to configure
  23. * both IOAPIC RTE as well as interrupt-remapping table entry).
  24. * As this gets called during crash dump, keep this simple for
  25. * now.
  26. */
  27. if (cpu_has_apic || apic_from_smp_config())
  28. disconnect_bsp_APIC(0);
  29. }
  30. static void __init irq_remapping_modify_x86_ops(void)
  31. {
  32. x86_io_apic_ops.disable = irq_remapping_disable_io_apic;
  33. }
  34. static __init int setup_nointremap(char *str)
  35. {
  36. disable_irq_remap = 1;
  37. return 0;
  38. }
  39. early_param("nointremap", setup_nointremap);
  40. static __init int setup_irqremap(char *str)
  41. {
  42. if (!str)
  43. return -EINVAL;
  44. while (*str) {
  45. if (!strncmp(str, "on", 2))
  46. disable_irq_remap = 0;
  47. else if (!strncmp(str, "off", 3))
  48. disable_irq_remap = 1;
  49. else if (!strncmp(str, "nosid", 5))
  50. disable_sourceid_checking = 1;
  51. else if (!strncmp(str, "no_x2apic_optout", 16))
  52. no_x2apic_optout = 1;
  53. str += strcspn(str, ",");
  54. while (*str == ',')
  55. str++;
  56. }
  57. return 0;
  58. }
  59. early_param("intremap", setup_irqremap);
  60. void __init setup_irq_remapping_ops(void)
  61. {
  62. remap_ops = &intel_irq_remap_ops;
  63. #ifdef CONFIG_AMD_IOMMU
  64. if (amd_iommu_irq_ops.prepare() == 0)
  65. remap_ops = &amd_iommu_irq_ops;
  66. #endif
  67. }
  68. int irq_remapping_supported(void)
  69. {
  70. if (disable_irq_remap)
  71. return 0;
  72. if (!remap_ops || !remap_ops->supported)
  73. return 0;
  74. return remap_ops->supported();
  75. }
  76. int __init irq_remapping_prepare(void)
  77. {
  78. if (!remap_ops || !remap_ops->prepare)
  79. return -ENODEV;
  80. return remap_ops->prepare();
  81. }
  82. int __init irq_remapping_enable(void)
  83. {
  84. int ret;
  85. if (!remap_ops || !remap_ops->enable)
  86. return -ENODEV;
  87. ret = remap_ops->enable();
  88. if (irq_remapping_enabled)
  89. irq_remapping_modify_x86_ops();
  90. return ret;
  91. }
  92. void irq_remapping_disable(void)
  93. {
  94. if (!irq_remapping_enabled ||
  95. !remap_ops ||
  96. !remap_ops->disable)
  97. return;
  98. remap_ops->disable();
  99. }
  100. int irq_remapping_reenable(int mode)
  101. {
  102. if (!irq_remapping_enabled ||
  103. !remap_ops ||
  104. !remap_ops->reenable)
  105. return 0;
  106. return remap_ops->reenable(mode);
  107. }
  108. int __init irq_remap_enable_fault_handling(void)
  109. {
  110. if (!irq_remapping_enabled)
  111. return 0;
  112. if (!remap_ops || !remap_ops->enable_faulting)
  113. return -ENODEV;
  114. return remap_ops->enable_faulting();
  115. }
  116. int setup_ioapic_remapped_entry(int irq,
  117. struct IO_APIC_route_entry *entry,
  118. unsigned int destination, int vector,
  119. struct io_apic_irq_attr *attr)
  120. {
  121. if (!remap_ops || !remap_ops->setup_ioapic_entry)
  122. return -ENODEV;
  123. return remap_ops->setup_ioapic_entry(irq, entry, destination,
  124. vector, attr);
  125. }
  126. int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask,
  127. bool force)
  128. {
  129. if (!config_enabled(CONFIG_SMP) || !remap_ops ||
  130. !remap_ops->set_affinity)
  131. return 0;
  132. return remap_ops->set_affinity(data, mask, force);
  133. }
  134. void free_remapped_irq(int irq)
  135. {
  136. if (!remap_ops || !remap_ops->free_irq)
  137. return;
  138. remap_ops->free_irq(irq);
  139. }
  140. void compose_remapped_msi_msg(struct pci_dev *pdev,
  141. unsigned int irq, unsigned int dest,
  142. struct msi_msg *msg, u8 hpet_id)
  143. {
  144. if (!remap_ops || !remap_ops->compose_msi_msg)
  145. return;
  146. remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id);
  147. }
  148. int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec)
  149. {
  150. if (!remap_ops || !remap_ops->msi_alloc_irq)
  151. return -ENODEV;
  152. return remap_ops->msi_alloc_irq(pdev, irq, nvec);
  153. }
  154. int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq,
  155. int index, int sub_handle)
  156. {
  157. if (!remap_ops || !remap_ops->msi_setup_irq)
  158. return -ENODEV;
  159. return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle);
  160. }
  161. int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
  162. {
  163. if (!remap_ops || !remap_ops->setup_hpet_msi)
  164. return -ENODEV;
  165. return remap_ops->setup_hpet_msi(irq, id);
  166. }