1 #include <linux/cpumask.h>
2 #include <linux/kernel.h>
3 #include <linux/string.h>
4 #include <linux/cpumask.h>
5 #include <linux/errno.h>
8 #include <asm/hw_irq.h>
9 #include <asm/irq_remapping.h>
10 #include <asm/processor.h>
11 #include <asm/x86_init.h>
14 #include "irq_remapping.h"
16 int irq_remapping_enabled;
18 int disable_irq_remap;
19 int disable_sourceid_checking;
22 static struct irq_remap_ops *remap_ops;
24 static void irq_remapping_disable_io_apic(void)
27 * With interrupt-remapping, for now we will use virtual wire A
28 * mode, as virtual wire B is little complex (need to configure
29 * both IOAPIC RTE as well as interrupt-remapping table entry).
30 * As this gets called during crash dump, keep this simple for
33 if (cpu_has_apic || apic_from_smp_config())
34 disconnect_bsp_APIC(0);
37 static void __init irq_remapping_modify_x86_ops(void)
39 x86_io_apic_ops.disable = irq_remapping_disable_io_apic;
40 x86_msi.setup_hpet_msi = setup_hpet_msi_remapped;
43 static __init int setup_nointremap(char *str)
45 disable_irq_remap = 1;
48 early_param("nointremap", setup_nointremap);
50 static __init int setup_irqremap(char *str)
56 if (!strncmp(str, "on", 2))
57 disable_irq_remap = 0;
58 else if (!strncmp(str, "off", 3))
59 disable_irq_remap = 1;
60 else if (!strncmp(str, "nosid", 5))
61 disable_sourceid_checking = 1;
62 else if (!strncmp(str, "no_x2apic_optout", 16))
65 str += strcspn(str, ",");
72 early_param("intremap", setup_irqremap);
74 void __init setup_irq_remapping_ops(void)
76 remap_ops = &intel_irq_remap_ops;
78 #ifdef CONFIG_AMD_IOMMU
79 if (amd_iommu_irq_ops.prepare() == 0)
80 remap_ops = &amd_iommu_irq_ops;
84 int irq_remapping_supported(void)
86 if (disable_irq_remap)
89 if (!remap_ops || !remap_ops->supported)
92 return remap_ops->supported();
95 int __init irq_remapping_prepare(void)
97 if (!remap_ops || !remap_ops->prepare)
100 return remap_ops->prepare();
103 int __init irq_remapping_enable(void)
107 if (!remap_ops || !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 ||
125 remap_ops->disable();
128 int irq_remapping_reenable(int mode)
130 if (!irq_remapping_enabled ||
132 !remap_ops->reenable)
135 return remap_ops->reenable(mode);
138 int __init irq_remap_enable_fault_handling(void)
140 if (!irq_remapping_enabled)
143 if (!remap_ops || !remap_ops->enable_faulting)
146 return remap_ops->enable_faulting();
149 int setup_ioapic_remapped_entry(int irq,
150 struct IO_APIC_route_entry *entry,
151 unsigned int destination, int vector,
152 struct io_apic_irq_attr *attr)
154 if (!remap_ops || !remap_ops->setup_ioapic_entry)
157 return remap_ops->setup_ioapic_entry(irq, entry, destination,
161 int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask,
164 if (!config_enabled(CONFIG_SMP) || !remap_ops ||
165 !remap_ops->set_affinity)
168 return remap_ops->set_affinity(data, mask, force);
171 void free_remapped_irq(int irq)
173 if (!remap_ops || !remap_ops->free_irq)
176 remap_ops->free_irq(irq);
179 void compose_remapped_msi_msg(struct pci_dev *pdev,
180 unsigned int irq, unsigned int dest,
181 struct msi_msg *msg, u8 hpet_id)
183 if (!remap_ops || !remap_ops->compose_msi_msg)
186 remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id);
189 int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec)
191 if (!remap_ops || !remap_ops->msi_alloc_irq)
194 return remap_ops->msi_alloc_irq(pdev, irq, nvec);
197 int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq,
198 int index, int sub_handle)
200 if (!remap_ops || !remap_ops->msi_setup_irq)
203 return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle);
206 int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
208 if (!remap_ops || !remap_ops->setup_hpet_msi)
211 return remap_ops->setup_hpet_msi(irq, id);