x86/irq: Remove x86_io_apic_ops.set_affinity and related interfaces
[deliverable/linux.git] / drivers / iommu / irq_remapping.c
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
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>
17
18 #include "irq_remapping.h"
19
20 int irq_remapping_enabled;
21 int irq_remap_broken;
22 int disable_sourceid_checking;
23 int no_x2apic_optout;
24
25 static int disable_irq_remap;
26 static struct irq_remap_ops *remap_ops;
27
28 static bool irq_remapped(struct irq_cfg *cfg)
29 {
30 return (cfg->remapped == 1);
31 }
32
33 static void irq_remapping_disable_io_apic(void)
34 {
35 /*
36 * With interrupt-remapping, for now we will use virtual wire A
37 * mode, as virtual wire B is little complex (need to configure
38 * both IOAPIC RTE as well as interrupt-remapping table entry).
39 * As this gets called during crash dump, keep this simple for
40 * now.
41 */
42 if (cpu_has_apic || apic_from_smp_config())
43 disconnect_bsp_APIC(0);
44 }
45
46 static void eoi_ioapic_pin_remapped(int apic, int pin, int vector)
47 {
48 /*
49 * Intr-remapping uses pin number as the virtual vector
50 * in the RTE. Actual vector is programmed in
51 * intr-remapping table entry. Hence for the io-apic
52 * EOI we use the pin number.
53 */
54 io_apic_eoi(apic, pin);
55 }
56
57 static void __init irq_remapping_modify_x86_ops(void)
58 {
59 x86_io_apic_ops.disable = irq_remapping_disable_io_apic;
60 x86_io_apic_ops.eoi_ioapic_pin = eoi_ioapic_pin_remapped;
61 }
62
63 static __init int setup_nointremap(char *str)
64 {
65 disable_irq_remap = 1;
66 return 0;
67 }
68 early_param("nointremap", setup_nointremap);
69
70 static __init int setup_irqremap(char *str)
71 {
72 if (!str)
73 return -EINVAL;
74
75 while (*str) {
76 if (!strncmp(str, "on", 2))
77 disable_irq_remap = 0;
78 else if (!strncmp(str, "off", 3))
79 disable_irq_remap = 1;
80 else if (!strncmp(str, "nosid", 5))
81 disable_sourceid_checking = 1;
82 else if (!strncmp(str, "no_x2apic_optout", 16))
83 no_x2apic_optout = 1;
84
85 str += strcspn(str, ",");
86 while (*str == ',')
87 str++;
88 }
89
90 return 0;
91 }
92 early_param("intremap", setup_irqremap);
93
94 void set_irq_remapping_broken(void)
95 {
96 irq_remap_broken = 1;
97 }
98
99 int __init irq_remapping_prepare(void)
100 {
101 if (disable_irq_remap)
102 return -ENOSYS;
103
104 if (intel_irq_remap_ops.prepare() == 0)
105 remap_ops = &intel_irq_remap_ops;
106 else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
107 amd_iommu_irq_ops.prepare() == 0)
108 remap_ops = &amd_iommu_irq_ops;
109 else
110 return -ENOSYS;
111
112 return 0;
113 }
114
115 int __init irq_remapping_enable(void)
116 {
117 int ret;
118
119 if (!remap_ops->enable)
120 return -ENODEV;
121
122 ret = remap_ops->enable();
123
124 if (irq_remapping_enabled)
125 irq_remapping_modify_x86_ops();
126
127 return ret;
128 }
129
130 void irq_remapping_disable(void)
131 {
132 if (irq_remapping_enabled && remap_ops->disable)
133 remap_ops->disable();
134 }
135
136 int irq_remapping_reenable(int mode)
137 {
138 if (irq_remapping_enabled && remap_ops->reenable)
139 return remap_ops->reenable(mode);
140
141 return 0;
142 }
143
144 int __init irq_remap_enable_fault_handling(void)
145 {
146 if (!irq_remapping_enabled)
147 return 0;
148
149 if (!remap_ops->enable_faulting)
150 return -ENODEV;
151
152 return remap_ops->enable_faulting();
153 }
154
155 void free_remapped_irq(int irq)
156 {
157 struct irq_cfg *cfg = irq_cfg(irq);
158
159 if (irq_remapped(cfg) && remap_ops->free_irq)
160 remap_ops->free_irq(irq);
161 }
162
163 void panic_if_irq_remap(const char *msg)
164 {
165 if (irq_remapping_enabled)
166 panic(msg);
167 }
168
169 void ir_ack_apic_edge(struct irq_data *data)
170 {
171 ack_APIC_irq();
172 }
173
174 static void ir_ack_apic_level(struct irq_data *data)
175 {
176 ack_APIC_irq();
177 eoi_ioapic_irq(data->irq, irqd_cfg(data));
178 }
179
180 static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
181 {
182 seq_printf(p, " IR-%s", data->chip->name);
183 }
184
185 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
186 {
187 chip->irq_print_chip = ir_print_prefix;
188 chip->irq_ack = ir_ack_apic_edge;
189 chip->irq_eoi = ir_ack_apic_level;
190 }
191
192 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
193 {
194 if (!irq_remapped(cfg))
195 return false;
196 irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
197 irq_remap_modify_chip_defaults(chip);
198 return true;
199 }
200
201 /**
202 * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
203 * device serving request @info
204 * @info: interrupt allocation information, used to identify the IOMMU device
205 *
206 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
207 * Returns pointer to IRQ domain, or NULL on failure.
208 */
209 struct irq_domain *
210 irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
211 {
212 if (!remap_ops || !remap_ops->get_ir_irq_domain)
213 return NULL;
214
215 return remap_ops->get_ir_irq_domain(info);
216 }
217
218 /**
219 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
220 * @info: interrupt allocation information, used to identify the IOMMU device
221 *
222 * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
223 * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
224 * irqdomain serving request @info.
225 * Returns pointer to IRQ domain, or NULL on failure.
226 */
227 struct irq_domain *
228 irq_remapping_get_irq_domain(struct irq_alloc_info *info)
229 {
230 if (!remap_ops || !remap_ops->get_irq_domain)
231 return NULL;
232
233 return remap_ops->get_irq_domain(info);
234 }
This page took 0.038234 seconds and 6 git commands to generate.