Linux 5.1.15
[linux/fpc-iii.git] / drivers / iommu / irq_remapping.c
blob81cf2908c5314aae0985d70f8f2b26da53a9e03f
1 #include <linux/cpumask.h>
2 #include <linux/kernel.h>
3 #include <linux/string.h>
4 #include <linux/errno.h>
5 #include <linux/msi.h>
6 #include <linux/irq.h>
7 #include <linux/pci.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>
14 #include <asm/apic.h>
15 #include <asm/hpet.h>
17 #include "irq_remapping.h"
19 int irq_remapping_enabled;
20 int irq_remap_broken;
21 int disable_sourceid_checking;
22 int no_x2apic_optout;
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
36 * now.
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;
50 return 0;
52 early_param("nointremap", setup_nointremap);
54 static __init int setup_irqremap(char *str)
56 if (!str)
57 return -EINVAL;
59 while (*str) {
60 if (!strncmp(str, "on", 2)) {
61 disable_irq_remap = 0;
62 disable_irq_post = 0;
63 } else if (!strncmp(str, "off", 3)) {
64 disable_irq_remap = 1;
65 disable_irq_post = 1;
66 } else if (!strncmp(str, "nosid", 5))
67 disable_sourceid_checking = 1;
68 else if (!strncmp(str, "no_x2apic_optout", 16))
69 no_x2apic_optout = 1;
70 else if (!strncmp(str, "nopost", 6))
71 disable_irq_post = 1;
73 str += strcspn(str, ",");
74 while (*str == ',')
75 str++;
78 return 0;
80 early_param("intremap", setup_irqremap);
82 void set_irq_remapping_broken(void)
84 irq_remap_broken = 1;
87 bool irq_remapping_cap(enum irq_remap_cap cap)
89 if (!remap_ops || disable_irq_post)
90 return false;
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)
99 return -ENOSYS;
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;
109 else
110 return -ENOSYS;
112 return 0;
115 int __init irq_remapping_enable(void)
117 int ret;
119 if (!remap_ops->enable)
120 return -ENODEV;
122 ret = remap_ops->enable();
124 if (irq_remapping_enabled)
125 irq_remapping_modify_x86_ops();
127 return ret;
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);
141 return 0;
144 int __init irq_remap_enable_fault_handling(void)
146 if (!irq_remapping_enabled)
147 return 0;
149 if (!remap_ops->enable_faulting)
150 return -ENODEV;
152 return remap_ops->enable_faulting();
155 void panic_if_irq_remap(const char *msg)
157 if (irq_remapping_enabled)
158 panic(msg);
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.
169 struct irq_domain *
170 irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
172 if (!remap_ops || !remap_ops->get_ir_irq_domain)
173 return NULL;
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.
187 struct irq_domain *
188 irq_remapping_get_irq_domain(struct irq_alloc_info *info)
190 if (!remap_ops || !remap_ops->get_irq_domain)
191 return NULL;
193 return remap_ops->get_irq_domain(info);