irq_remapping.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include <linux/seq_file.h>
  2. #include <linux/cpumask.h>
  3. #include <linux/kernel.h>
  4. #include <linux/string.h>
  5. #include <linux/errno.h>
  6. #include <linux/msi.h>
  7. #include <linux/irq.h>
  8. #include <linux/pci.h>
  9. #include <linux/irqdomain.h>
  10. #include <asm/hw_irq.h>
  11. #include <asm/irq_remapping.h>
  12. #include <asm/processor.h>
  13. #include <asm/x86_init.h>
  14. #include <asm/apic.h>
  15. #include <asm/hpet.h>
  16. #include "irq_remapping.h"
  17. int irq_remapping_enabled;
  18. int irq_remap_broken;
  19. int disable_sourceid_checking;
  20. int no_x2apic_optout;
  21. int disable_irq_post = 0;
  22. static int disable_irq_remap;
  23. static struct irq_remap_ops *remap_ops;
  24. static void irq_remapping_disable_io_apic(void)
  25. {
  26. /*
  27. * With interrupt-remapping, for now we will use virtual wire A
  28. * mode, as virtual wire B is little complex (need to configure
  29. * both IOAPIC RTE as well as interrupt-remapping table entry).
  30. * As this gets called during crash dump, keep this simple for
  31. * now.
  32. */
  33. if (cpu_has_apic || apic_from_smp_config())
  34. disconnect_bsp_APIC(0);
  35. }
  36. static void __init irq_remapping_modify_x86_ops(void)
  37. {
  38. x86_io_apic_ops.disable = irq_remapping_disable_io_apic;
  39. }
  40. static __init int setup_nointremap(char *str)
  41. {
  42. disable_irq_remap = 1;
  43. return 0;
  44. }
  45. early_param("nointremap", setup_nointremap);
  46. static __init int setup_irqremap(char *str)
  47. {
  48. if (!str)
  49. return -EINVAL;
  50. while (*str) {
  51. if (!strncmp(str, "on", 2)) {
  52. disable_irq_remap = 0;
  53. disable_irq_post = 0;
  54. } else if (!strncmp(str, "off", 3)) {
  55. disable_irq_remap = 1;
  56. disable_irq_post = 1;
  57. } else if (!strncmp(str, "nosid", 5))
  58. disable_sourceid_checking = 1;
  59. else if (!strncmp(str, "no_x2apic_optout", 16))
  60. no_x2apic_optout = 1;
  61. else if (!strncmp(str, "nopost", 6))
  62. disable_irq_post = 1;
  63. str += strcspn(str, ",");
  64. while (*str == ',')
  65. str++;
  66. }
  67. return 0;
  68. }
  69. early_param("intremap", setup_irqremap);
  70. void set_irq_remapping_broken(void)
  71. {
  72. irq_remap_broken = 1;
  73. }
  74. bool irq_remapping_cap(enum irq_remap_cap cap)
  75. {
  76. if (!remap_ops || disable_irq_post)
  77. return false;
  78. return (remap_ops->capability & (1 << cap));
  79. }
  80. EXPORT_SYMBOL_GPL(irq_remapping_cap);
  81. int __init irq_remapping_prepare(void)
  82. {
  83. if (disable_irq_remap)
  84. return -ENOSYS;
  85. if (intel_irq_remap_ops.prepare() == 0)
  86. remap_ops = &intel_irq_remap_ops;
  87. else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
  88. amd_iommu_irq_ops.prepare() == 0)
  89. remap_ops = &amd_iommu_irq_ops;
  90. else
  91. return -ENOSYS;
  92. return 0;
  93. }
  94. int __init irq_remapping_enable(void)
  95. {
  96. int ret;
  97. if (!remap_ops->enable)
  98. return -ENODEV;
  99. ret = remap_ops->enable();
  100. if (irq_remapping_enabled)
  101. irq_remapping_modify_x86_ops();
  102. return ret;
  103. }
  104. void irq_remapping_disable(void)
  105. {
  106. if (irq_remapping_enabled && remap_ops->disable)
  107. remap_ops->disable();
  108. }
  109. int irq_remapping_reenable(int mode)
  110. {
  111. if (irq_remapping_enabled && remap_ops->reenable)
  112. return remap_ops->reenable(mode);
  113. return 0;
  114. }
  115. int __init irq_remap_enable_fault_handling(void)
  116. {
  117. if (!irq_remapping_enabled)
  118. return 0;
  119. if (!remap_ops->enable_faulting)
  120. return -ENODEV;
  121. return remap_ops->enable_faulting();
  122. }
  123. void panic_if_irq_remap(const char *msg)
  124. {
  125. if (irq_remapping_enabled)
  126. panic(msg);
  127. }
  128. void ir_ack_apic_edge(struct irq_data *data)
  129. {
  130. ack_APIC_irq();
  131. }
  132. /**
  133. * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
  134. * device serving request @info
  135. * @info: interrupt allocation information, used to identify the IOMMU device
  136. *
  137. * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
  138. * Returns pointer to IRQ domain, or NULL on failure.
  139. */
  140. struct irq_domain *
  141. irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
  142. {
  143. if (!remap_ops || !remap_ops->get_ir_irq_domain)
  144. return NULL;
  145. return remap_ops->get_ir_irq_domain(info);
  146. }
  147. /**
  148. * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
  149. * @info: interrupt allocation information, used to identify the IOMMU device
  150. *
  151. * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
  152. * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
  153. * irqdomain serving request @info.
  154. * Returns pointer to IRQ domain, or NULL on failure.
  155. */
  156. struct irq_domain *
  157. irq_remapping_get_irq_domain(struct irq_alloc_info *info)
  158. {
  159. if (!remap_ops || !remap_ops->get_irq_domain)
  160. return NULL;
  161. return remap_ops->get_irq_domain(info);
  162. }