1 #include <linux/cpumask.h>
2 #include <linux/kernel.h>
3 #include <linux/string.h>
4 #include <linux/errno.h>
8 #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>
17 #include "irq_remapping.h"
19 int irq_remapping_enabled;
21 int disable_sourceid_checking;
24 int disable_irq_post = 0;
26 static int disable_irq_remap;
27 static struct irq_remap_ops *remap_ops;
29 static void irq_remapping_restore_boot_irq_mode(void)
32 * With interrupt-remapping, for now we will use virtual wire A
33 * mode, as virtual wire B is little complex (need to configure
34 * both IOAPIC RTE as well as interrupt-remapping table entry).
35 * As this gets called during crash dump, keep this simple for
38 if (boot_cpu_has(X86_FEATURE_APIC) || apic_from_smp_config())
39 disconnect_bsp_APIC(0);
42 static void __init irq_remapping_modify_x86_ops(void)
44 x86_apic_ops.restore = irq_remapping_restore_boot_irq_mode;
47 static __init int setup_nointremap(char *str)
49 disable_irq_remap = 1;
52 early_param("nointremap", setup_nointremap);
54 static __init int setup_irqremap(char *str)
60 if (!strncmp(str, "on", 2)) {
61 disable_irq_remap = 0;
63 } else if (!strncmp(str, "off", 3)) {
64 disable_irq_remap = 1;
66 } else if (!strncmp(str, "nosid", 5))
67 disable_sourceid_checking = 1;
68 else if (!strncmp(str, "no_x2apic_optout", 16))
70 else if (!strncmp(str, "nopost", 6))
73 str += strcspn(str, ",");
80 early_param("intremap", setup_irqremap);
82 void set_irq_remapping_broken(void)
87 bool irq_remapping_cap(enum irq_remap_cap cap)
89 if (!remap_ops || disable_irq_post)
92 return (remap_ops->capability & (1 << cap));
94 EXPORT_SYMBOL_GPL(irq_remapping_cap);
96 int __init irq_remapping_prepare(void)
98 if (disable_irq_remap)
101 if (intel_irq_remap_ops.prepare() == 0)
102 remap_ops = &intel_irq_remap_ops;
103 else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
104 amd_iommu_irq_ops.prepare() == 0)
105 remap_ops = &amd_iommu_irq_ops;
106 else if (IS_ENABLED(CONFIG_HYPERV_IOMMU) &&
107 hyperv_irq_remap_ops.prepare() == 0)
108 remap_ops = &hyperv_irq_remap_ops;
115 int __init irq_remapping_enable(void)
119 if (!remap_ops->enable)
122 ret = remap_ops->enable();
124 if (irq_remapping_enabled)
125 irq_remapping_modify_x86_ops();
130 void irq_remapping_disable(void)
132 if (irq_remapping_enabled && remap_ops->disable)
133 remap_ops->disable();
136 int irq_remapping_reenable(int mode)
138 if (irq_remapping_enabled && remap_ops->reenable)
139 return remap_ops->reenable(mode);
144 int __init irq_remap_enable_fault_handling(void)
146 if (!irq_remapping_enabled)
149 if (!remap_ops->enable_faulting)
152 return remap_ops->enable_faulting();
155 void panic_if_irq_remap(const char *msg)
157 if (irq_remapping_enabled)
162 * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
163 * device serving request @info
164 * @info: interrupt allocation information, used to identify the IOMMU device
166 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
167 * Returns pointer to IRQ domain, or NULL on failure.
170 irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
172 if (!remap_ops || !remap_ops->get_ir_irq_domain)
175 return remap_ops->get_ir_irq_domain(info);
179 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
180 * @info: interrupt allocation information, used to identify the IOMMU device
182 * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
183 * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
184 * irqdomain serving request @info.
185 * Returns pointer to IRQ domain, or NULL on failure.
188 irq_remapping_get_irq_domain(struct irq_alloc_info *info)
190 if (!remap_ops || !remap_ops->get_irq_domain)
193 return remap_ops->get_irq_domain(info);