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>
9 #include <linux/irqdomain.h>
11 #include <asm/hw_irq.h>
12 #include <asm/irq_remapping.h>
13 #include <asm/processor.h>
14 #include <asm/x86_init.h>
18 #include "irq_remapping.h"
20 int irq_remapping_enabled
;
22 int disable_sourceid_checking
;
25 int disable_irq_post
= 0;
27 static int disable_irq_remap
;
28 static struct irq_remap_ops
*remap_ops
;
30 static void irq_remapping_disable_io_apic(void)
33 * With interrupt-remapping, for now we will use virtual wire A
34 * mode, as virtual wire B is little complex (need to configure
35 * both IOAPIC RTE as well as interrupt-remapping table entry).
36 * As this gets called during crash dump, keep this simple for
39 if (boot_cpu_has(X86_FEATURE_APIC
) || apic_from_smp_config())
40 disconnect_bsp_APIC(0);
43 static void __init
irq_remapping_modify_x86_ops(void)
45 x86_io_apic_ops
.disable
= irq_remapping_disable_io_apic
;
48 static __init
int setup_nointremap(char *str
)
50 disable_irq_remap
= 1;
53 early_param("nointremap", setup_nointremap
);
55 static __init
int setup_irqremap(char *str
)
61 if (!strncmp(str
, "on", 2)) {
62 disable_irq_remap
= 0;
64 } else if (!strncmp(str
, "off", 3)) {
65 disable_irq_remap
= 1;
67 } else if (!strncmp(str
, "nosid", 5))
68 disable_sourceid_checking
= 1;
69 else if (!strncmp(str
, "no_x2apic_optout", 16))
71 else if (!strncmp(str
, "nopost", 6))
74 str
+= strcspn(str
, ",");
81 early_param("intremap", setup_irqremap
);
83 void set_irq_remapping_broken(void)
88 bool irq_remapping_cap(enum irq_remap_cap cap
)
90 if (!remap_ops
|| disable_irq_post
)
93 return (remap_ops
->capability
& (1 << cap
));
95 EXPORT_SYMBOL_GPL(irq_remapping_cap
);
97 int __init
irq_remapping_prepare(void)
99 if (disable_irq_remap
)
102 if (intel_irq_remap_ops
.prepare() == 0)
103 remap_ops
= &intel_irq_remap_ops
;
104 else if (IS_ENABLED(CONFIG_AMD_IOMMU
) &&
105 amd_iommu_irq_ops
.prepare() == 0)
106 remap_ops
= &amd_iommu_irq_ops
;
113 int __init
irq_remapping_enable(void)
117 if (!remap_ops
->enable
)
120 ret
= remap_ops
->enable();
122 if (irq_remapping_enabled
)
123 irq_remapping_modify_x86_ops();
128 void irq_remapping_disable(void)
130 if (irq_remapping_enabled
&& remap_ops
->disable
)
131 remap_ops
->disable();
134 int irq_remapping_reenable(int mode
)
136 if (irq_remapping_enabled
&& remap_ops
->reenable
)
137 return remap_ops
->reenable(mode
);
142 int __init
irq_remap_enable_fault_handling(void)
144 if (!irq_remapping_enabled
)
147 if (!remap_ops
->enable_faulting
)
150 return remap_ops
->enable_faulting();
153 void panic_if_irq_remap(const char *msg
)
155 if (irq_remapping_enabled
)
159 void ir_ack_apic_edge(struct irq_data
*data
)
165 * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
166 * device serving request @info
167 * @info: interrupt allocation information, used to identify the IOMMU device
169 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
170 * Returns pointer to IRQ domain, or NULL on failure.
173 irq_remapping_get_ir_irq_domain(struct irq_alloc_info
*info
)
175 if (!remap_ops
|| !remap_ops
->get_ir_irq_domain
)
178 return remap_ops
->get_ir_irq_domain(info
);
182 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
183 * @info: interrupt allocation information, used to identify the IOMMU device
185 * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
186 * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
187 * irqdomain serving request @info.
188 * Returns pointer to IRQ domain, or NULL on failure.
191 irq_remapping_get_irq_domain(struct irq_alloc_info
*info
)
193 if (!remap_ops
|| !remap_ops
->get_irq_domain
)
196 return remap_ops
->get_irq_domain(info
);