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 static int disable_irq_remap
;
26 static struct irq_remap_ops
*remap_ops
;
28 static bool irq_remapped(struct irq_cfg
*cfg
)
30 return (cfg
->remapped
== 1);
33 static void irq_remapping_disable_io_apic(void)
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
42 if (cpu_has_apic
|| apic_from_smp_config())
43 disconnect_bsp_APIC(0);
46 static void __init
irq_remapping_modify_x86_ops(void)
48 x86_io_apic_ops
.disable
= irq_remapping_disable_io_apic
;
51 static __init
int setup_nointremap(char *str
)
53 disable_irq_remap
= 1;
56 early_param("nointremap", setup_nointremap
);
58 static __init
int setup_irqremap(char *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))
73 str
+= strcspn(str
, ",");
80 early_param("intremap", setup_irqremap
);
82 void set_irq_remapping_broken(void)
87 int __init
irq_remapping_prepare(void)
89 if (disable_irq_remap
)
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
;
103 int __init
irq_remapping_enable(void)
107 if (!remap_ops
->enable
)
110 ret
= remap_ops
->enable();
112 if (irq_remapping_enabled
)
113 irq_remapping_modify_x86_ops();
118 void irq_remapping_disable(void)
120 if (irq_remapping_enabled
&& remap_ops
->disable
)
121 remap_ops
->disable();
124 int irq_remapping_reenable(int mode
)
126 if (irq_remapping_enabled
&& remap_ops
->reenable
)
127 return remap_ops
->reenable(mode
);
132 int __init
irq_remap_enable_fault_handling(void)
134 if (!irq_remapping_enabled
)
137 if (!remap_ops
->enable_faulting
)
140 return remap_ops
->enable_faulting();
143 void free_remapped_irq(int irq
)
145 struct irq_cfg
*cfg
= irq_cfg(irq
);
147 if (irq_remapped(cfg
) && remap_ops
->free_irq
)
148 remap_ops
->free_irq(irq
);
151 void panic_if_irq_remap(const char *msg
)
153 if (irq_remapping_enabled
)
157 void ir_ack_apic_edge(struct irq_data
*data
)
162 static void ir_print_prefix(struct irq_data
*data
, struct seq_file
*p
)
164 seq_printf(p
, " IR-%s", data
->chip
->name
);
167 void irq_remap_modify_chip_defaults(struct irq_chip
*chip
)
169 chip
->irq_print_chip
= ir_print_prefix
;
170 chip
->irq_ack
= ir_ack_apic_edge
;
173 bool setup_remapped_irq(int irq
, struct irq_cfg
*cfg
, struct irq_chip
*chip
)
175 if (!irq_remapped(cfg
))
177 irq_set_status_flags(irq
, IRQ_MOVE_PCNTXT
);
178 irq_remap_modify_chip_defaults(chip
);
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
187 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
188 * Returns pointer to IRQ domain, or NULL on failure.
191 irq_remapping_get_ir_irq_domain(struct irq_alloc_info
*info
)
193 if (!remap_ops
|| !remap_ops
->get_ir_irq_domain
)
196 return remap_ops
->get_ir_irq_domain(info
);
200 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
201 * @info: interrupt allocation information, used to identify the IOMMU device
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.
209 irq_remapping_get_irq_domain(struct irq_alloc_info
*info
)
211 if (!remap_ops
|| !remap_ops
->get_irq_domain
)
214 return remap_ops
->get_irq_domain(info
);