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;
42 static __init int setup_nointremap(char *str)
44 disable_irq_remap = 1;
47 early_param("nointremap", setup_nointremap);
49 static __init int setup_irqremap(char *str)
55 if (!strncmp(str, "on", 2))
56 disable_irq_remap = 0;
57 else if (!strncmp(str, "off", 3))
58 disable_irq_remap = 1;
59 else if (!strncmp(str, "nosid", 5))
60 disable_sourceid_checking = 1;
61 else if (!strncmp(str, "no_x2apic_optout", 16))
64 str += strcspn(str, ",");
71 early_param("intremap", setup_irqremap);
73 void __init setup_irq_remapping_ops(void)
75 remap_ops = &intel_irq_remap_ops;
77 #ifdef CONFIG_AMD_IOMMU
78 if (amd_iommu_irq_ops.prepare() == 0)
79 remap_ops = &amd_iommu_irq_ops;
83 int irq_remapping_supported(void)
85 if (disable_irq_remap)
88 if (!remap_ops || !remap_ops->supported)
91 return remap_ops->supported();
94 int __init irq_remapping_prepare(void)
96 if (!remap_ops || !remap_ops->prepare)
99 return remap_ops->prepare();
102 int __init irq_remapping_enable(void)
106 if (!remap_ops || !remap_ops->enable)
109 ret = remap_ops->enable();
111 if (irq_remapping_enabled)
112 irq_remapping_modify_x86_ops();
117 void irq_remapping_disable(void)
119 if (!irq_remapping_enabled ||
124 remap_ops->disable();
127 int irq_remapping_reenable(int mode)
129 if (!irq_remapping_enabled ||
131 !remap_ops->reenable)
134 return remap_ops->reenable(mode);
137 int __init irq_remap_enable_fault_handling(void)
139 if (!irq_remapping_enabled)
142 if (!remap_ops || !remap_ops->enable_faulting)
145 return remap_ops->enable_faulting();
148 int setup_ioapic_remapped_entry(int irq,
149 struct IO_APIC_route_entry *entry,
150 unsigned int destination, int vector,
151 struct io_apic_irq_attr *attr)
153 if (!remap_ops || !remap_ops->setup_ioapic_entry)
156 return remap_ops->setup_ioapic_entry(irq, entry, destination,
160 int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask,
163 if (!config_enabled(CONFIG_SMP) || !remap_ops ||
164 !remap_ops->set_affinity)
167 return remap_ops->set_affinity(data, mask, force);
170 void free_remapped_irq(int irq)
172 if (!remap_ops || !remap_ops->free_irq)
175 remap_ops->free_irq(irq);
178 void compose_remapped_msi_msg(struct pci_dev *pdev,
179 unsigned int irq, unsigned int dest,
180 struct msi_msg *msg, u8 hpet_id)
182 if (!remap_ops || !remap_ops->compose_msi_msg)
185 remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id);
188 int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec)
190 if (!remap_ops || !remap_ops->msi_alloc_irq)
193 return remap_ops->msi_alloc_irq(pdev, irq, nvec);
196 int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq,
197 int index, int sub_handle)
199 if (!remap_ops || !remap_ops->msi_setup_irq)
202 return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle);
205 int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
207 if (!remap_ops || !remap_ops->setup_hpet_msi)
210 return remap_ops->setup_hpet_msi(irq, id);