x86/irq: Remove x86_io_apic_ops.eoi_ioapic_pin 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 __init irq_remapping_modify_x86_ops(void)
47 {
48 x86_io_apic_ops.disable = irq_remapping_disable_io_apic;
49 }
50
51 static __init int setup_nointremap(char *str)
52 {
53 disable_irq_remap = 1;
54 return 0;
55 }
56 early_param("nointremap", setup_nointremap);
57
58 static __init int setup_irqremap(char *str)
59 {
60 if (!str)
61 return -EINVAL;
62
63 while (*str) {
64 if (!strncmp(str, "on", 2))
65 disable_irq_remap = 0;
66 else if (!strncmp(str, "off", 3))
67 disable_irq_remap = 1;
68 else if (!strncmp(str, "nosid", 5))
69 disable_sourceid_checking = 1;
70 else if (!strncmp(str, "no_x2apic_optout", 16))
71 no_x2apic_optout = 1;
72
73 str += strcspn(str, ",");
74 while (*str == ',')
75 str++;
76 }
77
78 return 0;
79 }
80 early_param("intremap", setup_irqremap);
81
82 void set_irq_remapping_broken(void)
83 {
84 irq_remap_broken = 1;
85 }
86
87 int __init irq_remapping_prepare(void)
88 {
89 if (disable_irq_remap)
90 return -ENOSYS;
91
92 if (intel_irq_remap_ops.prepare() == 0)
93 remap_ops = &intel_irq_remap_ops;
94 else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
95 amd_iommu_irq_ops.prepare() == 0)
96 remap_ops = &amd_iommu_irq_ops;
97 else
98 return -ENOSYS;
99
100 return 0;
101 }
102
103 int __init irq_remapping_enable(void)
104 {
105 int ret;
106
107 if (!remap_ops->enable)
108 return -ENODEV;
109
110 ret = remap_ops->enable();
111
112 if (irq_remapping_enabled)
113 irq_remapping_modify_x86_ops();
114
115 return ret;
116 }
117
118 void irq_remapping_disable(void)
119 {
120 if (irq_remapping_enabled && remap_ops->disable)
121 remap_ops->disable();
122 }
123
124 int irq_remapping_reenable(int mode)
125 {
126 if (irq_remapping_enabled && remap_ops->reenable)
127 return remap_ops->reenable(mode);
128
129 return 0;
130 }
131
132 int __init irq_remap_enable_fault_handling(void)
133 {
134 if (!irq_remapping_enabled)
135 return 0;
136
137 if (!remap_ops->enable_faulting)
138 return -ENODEV;
139
140 return remap_ops->enable_faulting();
141 }
142
143 void free_remapped_irq(int irq)
144 {
145 struct irq_cfg *cfg = irq_cfg(irq);
146
147 if (irq_remapped(cfg) && remap_ops->free_irq)
148 remap_ops->free_irq(irq);
149 }
150
151 void panic_if_irq_remap(const char *msg)
152 {
153 if (irq_remapping_enabled)
154 panic(msg);
155 }
156
157 void ir_ack_apic_edge(struct irq_data *data)
158 {
159 ack_APIC_irq();
160 }
161
162 static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
163 {
164 seq_printf(p, " IR-%s", data->chip->name);
165 }
166
167 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
168 {
169 chip->irq_print_chip = ir_print_prefix;
170 chip->irq_ack = ir_ack_apic_edge;
171 }
172
173 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
174 {
175 if (!irq_remapped(cfg))
176 return false;
177 irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
178 irq_remap_modify_chip_defaults(chip);
179 return true;
180 }
181
182 /**
183 * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
184 * device serving request @info
185 * @info: interrupt allocation information, used to identify the IOMMU device
186 *
187 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
188 * Returns pointer to IRQ domain, or NULL on failure.
189 */
190 struct irq_domain *
191 irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
192 {
193 if (!remap_ops || !remap_ops->get_ir_irq_domain)
194 return NULL;
195
196 return remap_ops->get_ir_irq_domain(info);
197 }
198
199 /**
200 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
201 * @info: interrupt allocation information, used to identify the IOMMU device
202 *
203 * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
204 * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
205 * irqdomain serving request @info.
206 * Returns pointer to IRQ domain, or NULL on failure.
207 */
208 struct irq_domain *
209 irq_remapping_get_irq_domain(struct irq_alloc_info *info)
210 {
211 if (!remap_ops || !remap_ops->get_irq_domain)
212 return NULL;
213
214 return remap_ops->get_irq_domain(info);
215 }
This page took 0.038484 seconds and 5 git commands to generate.