irq_remapping.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 = 1;
  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. else if (!strncmp(str, "off", 3))
  54. disable_irq_remap = 1;
  55. else if (!strncmp(str, "nosid", 5))
  56. disable_sourceid_checking = 1;
  57. else if (!strncmp(str, "no_x2apic_optout", 16))
  58. no_x2apic_optout = 1;
  59. str += strcspn(str, ",");
  60. while (*str == ',')
  61. str++;
  62. }
  63. return 0;
  64. }
  65. early_param("intremap", setup_irqremap);
  66. void set_irq_remapping_broken(void)
  67. {
  68. irq_remap_broken = 1;
  69. }
  70. bool irq_remapping_cap(enum irq_remap_cap cap)
  71. {
  72. if (!remap_ops || disable_irq_post)
  73. return false;
  74. return (remap_ops->capability & (1 << cap));
  75. }
  76. EXPORT_SYMBOL_GPL(irq_remapping_cap);
  77. int __init irq_remapping_prepare(void)
  78. {
  79. if (disable_irq_remap)
  80. return -ENOSYS;
  81. if (intel_irq_remap_ops.prepare() == 0)
  82. remap_ops = &intel_irq_remap_ops;
  83. else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
  84. amd_iommu_irq_ops.prepare() == 0)
  85. remap_ops = &amd_iommu_irq_ops;
  86. else
  87. return -ENOSYS;
  88. return 0;
  89. }
  90. int __init irq_remapping_enable(void)
  91. {
  92. int ret;
  93. if (!remap_ops->enable)
  94. return -ENODEV;
  95. ret = remap_ops->enable();
  96. if (irq_remapping_enabled)
  97. irq_remapping_modify_x86_ops();
  98. return ret;
  99. }
  100. void irq_remapping_disable(void)
  101. {
  102. if (irq_remapping_enabled && remap_ops->disable)
  103. remap_ops->disable();
  104. }
  105. int irq_remapping_reenable(int mode)
  106. {
  107. if (irq_remapping_enabled && remap_ops->reenable)
  108. return remap_ops->reenable(mode);
  109. return 0;
  110. }
  111. int __init irq_remap_enable_fault_handling(void)
  112. {
  113. if (!irq_remapping_enabled)
  114. return 0;
  115. if (!remap_ops->enable_faulting)
  116. return -ENODEV;
  117. return remap_ops->enable_faulting();
  118. }
  119. void panic_if_irq_remap(const char *msg)
  120. {
  121. if (irq_remapping_enabled)
  122. panic(msg);
  123. }
  124. void ir_ack_apic_edge(struct irq_data *data)
  125. {
  126. ack_APIC_irq();
  127. }
  128. /**
  129. * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
  130. * device serving request @info
  131. * @info: interrupt allocation information, used to identify the IOMMU device
  132. *
  133. * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
  134. * Returns pointer to IRQ domain, or NULL on failure.
  135. */
  136. struct irq_domain *
  137. irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
  138. {
  139. if (!remap_ops || !remap_ops->get_ir_irq_domain)
  140. return NULL;
  141. return remap_ops->get_ir_irq_domain(info);
  142. }
  143. /**
  144. * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
  145. * @info: interrupt allocation information, used to identify the IOMMU device
  146. *
  147. * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
  148. * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
  149. * irqdomain serving request @info.
  150. * Returns pointer to IRQ domain, or NULL on failure.
  151. */
  152. struct irq_domain *
  153. irq_remapping_get_irq_domain(struct irq_alloc_info *info)
  154. {
  155. if (!remap_ops || !remap_ops->get_irq_domain)
  156. return NULL;
  157. return remap_ops->get_irq_domain(info);
  158. }