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 eoi_ioapic_pin_remapped(int apic
, int pin
, int vector
)
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.
54 io_apic_eoi(apic
, pin
);
57 static void __init
irq_remapping_modify_x86_ops(void)
59 x86_io_apic_ops
.disable
= irq_remapping_disable_io_apic
;
60 x86_io_apic_ops
.eoi_ioapic_pin
= eoi_ioapic_pin_remapped
;
63 static __init
int setup_nointremap(char *str
)
65 disable_irq_remap
= 1;
68 early_param("nointremap", setup_nointremap
);
70 static __init
int setup_irqremap(char *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))
85 str
+= strcspn(str
, ",");
92 early_param("intremap", setup_irqremap
);
94 void set_irq_remapping_broken(void)
99 int __init
irq_remapping_prepare(void)
101 if (disable_irq_remap
)
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
;
115 int __init
irq_remapping_enable(void)
119 if (!remap_ops
->enable
)
122 ret
= remap_ops
->enable();
124 if (irq_remapping_enabled
)
125 irq_remapping_modify_x86_ops();
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
);
144 int __init
irq_remap_enable_fault_handling(void)
146 if (!irq_remapping_enabled
)
149 if (!remap_ops
->enable_faulting
)
152 return remap_ops
->enable_faulting();
155 void free_remapped_irq(int irq
)
157 struct irq_cfg
*cfg
= irq_cfg(irq
);
159 if (irq_remapped(cfg
) && remap_ops
->free_irq
)
160 remap_ops
->free_irq(irq
);
163 void panic_if_irq_remap(const char *msg
)
165 if (irq_remapping_enabled
)
169 void ir_ack_apic_edge(struct irq_data
*data
)
174 static void ir_ack_apic_level(struct irq_data
*data
)
177 eoi_ioapic_irq(data
->irq
, irqd_cfg(data
));
180 static void ir_print_prefix(struct irq_data
*data
, struct seq_file
*p
)
182 seq_printf(p
, " IR-%s", data
->chip
->name
);
185 void irq_remap_modify_chip_defaults(struct irq_chip
*chip
)
187 chip
->irq_print_chip
= ir_print_prefix
;
188 chip
->irq_ack
= ir_ack_apic_edge
;
189 chip
->irq_eoi
= ir_ack_apic_level
;
192 bool setup_remapped_irq(int irq
, struct irq_cfg
*cfg
, struct irq_chip
*chip
)
194 if (!irq_remapped(cfg
))
196 irq_set_status_flags(irq
, IRQ_MOVE_PCNTXT
);
197 irq_remap_modify_chip_defaults(chip
);
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
206 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
207 * Returns pointer to IRQ domain, or NULL on failure.
210 irq_remapping_get_ir_irq_domain(struct irq_alloc_info
*info
)
212 if (!remap_ops
|| !remap_ops
->get_ir_irq_domain
)
215 return remap_ops
->get_ir_irq_domain(info
);
219 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
220 * @info: interrupt allocation information, used to identify the IOMMU device
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.
228 irq_remapping_get_irq_domain(struct irq_alloc_info
*info
)
230 if (!remap_ops
|| !remap_ops
->get_irq_domain
)
233 return remap_ops
->get_irq_domain(info
);