ocfs2: fix several issues of append dio
[linux/fpc-iii.git] / drivers / iommu / irq_remapping.c
blob2d9993062ded6b2d543c89a9c09c3e6a85dfb17f
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>
11 #include <asm/hw_irq.h>
12 #include <asm/irq_remapping.h>
13 #include <asm/processor.h>
14 #include <asm/x86_init.h>
15 #include <asm/apic.h>
16 #include <asm/hpet.h>
18 #include "irq_remapping.h"
20 int irq_remapping_enabled;
21 int irq_remap_broken;
22 int disable_sourceid_checking;
23 int no_x2apic_optout;
25 int disable_irq_post = 1;
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
37 * now.
39 if (cpu_has_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;
51 return 0;
53 early_param("nointremap", setup_nointremap);
55 static __init int setup_irqremap(char *str)
57 if (!str)
58 return -EINVAL;
60 while (*str) {
61 if (!strncmp(str, "on", 2))
62 disable_irq_remap = 0;
63 else if (!strncmp(str, "off", 3))
64 disable_irq_remap = 1;
65 else if (!strncmp(str, "nosid", 5))
66 disable_sourceid_checking = 1;
67 else if (!strncmp(str, "no_x2apic_optout", 16))
68 no_x2apic_optout = 1;
70 str += strcspn(str, ",");
71 while (*str == ',')
72 str++;
75 return 0;
77 early_param("intremap", setup_irqremap);
79 void set_irq_remapping_broken(void)
81 irq_remap_broken = 1;
84 bool irq_remapping_cap(enum irq_remap_cap cap)
86 if (!remap_ops || disable_irq_post)
87 return 0;
89 return (remap_ops->capability & (1 << cap));
91 EXPORT_SYMBOL_GPL(irq_remapping_cap);
93 int __init irq_remapping_prepare(void)
95 if (disable_irq_remap)
96 return -ENOSYS;
98 if (intel_irq_remap_ops.prepare() == 0)
99 remap_ops = &intel_irq_remap_ops;
100 else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
101 amd_iommu_irq_ops.prepare() == 0)
102 remap_ops = &amd_iommu_irq_ops;
103 else
104 return -ENOSYS;
106 return 0;
109 int __init irq_remapping_enable(void)
111 int ret;
113 if (!remap_ops->enable)
114 return -ENODEV;
116 ret = remap_ops->enable();
118 if (irq_remapping_enabled)
119 irq_remapping_modify_x86_ops();
121 return ret;
124 void irq_remapping_disable(void)
126 if (irq_remapping_enabled && remap_ops->disable)
127 remap_ops->disable();
130 int irq_remapping_reenable(int mode)
132 if (irq_remapping_enabled && remap_ops->reenable)
133 return remap_ops->reenable(mode);
135 return 0;
138 int __init irq_remap_enable_fault_handling(void)
140 if (!irq_remapping_enabled)
141 return 0;
143 if (!remap_ops->enable_faulting)
144 return -ENODEV;
146 return remap_ops->enable_faulting();
149 void panic_if_irq_remap(const char *msg)
151 if (irq_remapping_enabled)
152 panic(msg);
155 void ir_ack_apic_edge(struct irq_data *data)
157 ack_APIC_irq();
161 * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
162 * device serving request @info
163 * @info: interrupt allocation information, used to identify the IOMMU device
165 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
166 * Returns pointer to IRQ domain, or NULL on failure.
168 struct irq_domain *
169 irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
171 if (!remap_ops || !remap_ops->get_ir_irq_domain)
172 return NULL;
174 return remap_ops->get_ir_irq_domain(info);
178 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
179 * @info: interrupt allocation information, used to identify the IOMMU device
181 * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
182 * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
183 * irqdomain serving request @info.
184 * Returns pointer to IRQ domain, or NULL on failure.
186 struct irq_domain *
187 irq_remapping_get_irq_domain(struct irq_alloc_info *info)
189 if (!remap_ops || !remap_ops->get_irq_domain)
190 return NULL;
192 return remap_ops->get_irq_domain(info);