Commit | Line | Data |
---|---|---|
1c4248ca | 1 | #include <linux/cpumask.h> |
736baef4 JR |
2 | #include <linux/kernel.h> |
3 | #include <linux/string.h> | |
4 | #include <linux/errno.h> | |
98f1ad25 | 5 | #include <linux/msi.h> |
5afba62c JR |
6 | #include <linux/irq.h> |
7 | #include <linux/pci.h> | |
a62b32cd | 8 | #include <linux/irqdomain.h> |
98f1ad25 JR |
9 | |
10 | #include <asm/hw_irq.h> | |
11 | #include <asm/irq_remapping.h> | |
1c4248ca JR |
12 | #include <asm/processor.h> |
13 | #include <asm/x86_init.h> | |
14 | #include <asm/apic.h> | |
5fc24d8c | 15 | #include <asm/hpet.h> |
736baef4 | 16 | |
8a8f422d | 17 | #include "irq_remapping.h" |
736baef4 | 18 | |
95a02e97 | 19 | int irq_remapping_enabled; |
03bbcb2e | 20 | int irq_remap_broken; |
736baef4 JR |
21 | int disable_sourceid_checking; |
22 | int no_x2apic_optout; | |
23 | ||
b7d20631 | 24 | int disable_irq_post = 0; |
3d9b98f4 | 25 | |
7fa1c842 | 26 | static int disable_irq_remap; |
736baef4 JR |
27 | static struct irq_remap_ops *remap_ops; |
28 | ||
51b146c5 | 29 | static void irq_remapping_restore_boot_irq_mode(void) |
1c4248ca JR |
30 | { |
31 | /* | |
32 | * With interrupt-remapping, for now we will use virtual wire A | |
33 | * mode, as virtual wire B is little complex (need to configure | |
34 | * both IOAPIC RTE as well as interrupt-remapping table entry). | |
35 | * As this gets called during crash dump, keep this simple for | |
36 | * now. | |
37 | */ | |
93984fbd | 38 | if (boot_cpu_has(X86_FEATURE_APIC) || apic_from_smp_config()) |
1c4248ca JR |
39 | disconnect_bsp_APIC(0); |
40 | } | |
41 | ||
42 | static void __init irq_remapping_modify_x86_ops(void) | |
43 | { | |
51b146c5 | 44 | x86_apic_ops.restore = irq_remapping_restore_boot_irq_mode; |
1c4248ca JR |
45 | } |
46 | ||
736baef4 JR |
47 | static __init int setup_nointremap(char *str) |
48 | { | |
95a02e97 | 49 | disable_irq_remap = 1; |
736baef4 JR |
50 | return 0; |
51 | } | |
52 | early_param("nointremap", setup_nointremap); | |
53 | ||
95a02e97 | 54 | static __init int setup_irqremap(char *str) |
736baef4 JR |
55 | { |
56 | if (!str) | |
57 | return -EINVAL; | |
58 | ||
59 | while (*str) { | |
b7d20631 | 60 | if (!strncmp(str, "on", 2)) { |
95a02e97 | 61 | disable_irq_remap = 0; |
b7d20631 FW |
62 | disable_irq_post = 0; |
63 | } else if (!strncmp(str, "off", 3)) { | |
95a02e97 | 64 | disable_irq_remap = 1; |
b7d20631 FW |
65 | disable_irq_post = 1; |
66 | } else if (!strncmp(str, "nosid", 5)) | |
736baef4 JR |
67 | disable_sourceid_checking = 1; |
68 | else if (!strncmp(str, "no_x2apic_optout", 16)) | |
69 | no_x2apic_optout = 1; | |
b7d20631 FW |
70 | else if (!strncmp(str, "nopost", 6)) |
71 | disable_irq_post = 1; | |
736baef4 JR |
72 | |
73 | str += strcspn(str, ","); | |
74 | while (*str == ',') | |
75 | str++; | |
76 | } | |
77 | ||
78 | return 0; | |
79 | } | |
95a02e97 | 80 | early_param("intremap", setup_irqremap); |
736baef4 | 81 | |
03bbcb2e NH |
82 | void set_irq_remapping_broken(void) |
83 | { | |
84 | irq_remap_broken = 1; | |
85 | } | |
86 | ||
959c870f FW |
87 | bool irq_remapping_cap(enum irq_remap_cap cap) |
88 | { | |
89 | if (!remap_ops || disable_irq_post) | |
30e93761 | 90 | return false; |
959c870f FW |
91 | |
92 | return (remap_ops->capability & (1 << cap)); | |
93 | } | |
94 | EXPORT_SYMBOL_GPL(irq_remapping_cap); | |
95 | ||
c392f56c | 96 | int __init irq_remapping_prepare(void) |
736baef4 | 97 | { |
95a02e97 | 98 | if (disable_irq_remap) |
c392f56c | 99 | return -ENOSYS; |
736baef4 | 100 | |
30969e34 JL |
101 | if (intel_irq_remap_ops.prepare() == 0) |
102 | remap_ops = &intel_irq_remap_ops; | |
103 | else if (IS_ENABLED(CONFIG_AMD_IOMMU) && | |
104 | amd_iommu_irq_ops.prepare() == 0) | |
a1dafe85 | 105 | remap_ops = &amd_iommu_irq_ops; |
29217a47 LT |
106 | else if (IS_ENABLED(CONFIG_HYPERV_IOMMU) && |
107 | hyperv_irq_remap_ops.prepare() == 0) | |
108 | remap_ops = &hyperv_irq_remap_ops; | |
30969e34 JL |
109 | else |
110 | return -ENOSYS; | |
111 | ||
112 | return 0; | |
736baef4 JR |
113 | } |
114 | ||
95a02e97 | 115 | int __init irq_remapping_enable(void) |
736baef4 | 116 | { |
1c4248ca JR |
117 | int ret; |
118 | ||
e9011760 | 119 | if (!remap_ops->enable) |
736baef4 JR |
120 | return -ENODEV; |
121 | ||
1c4248ca JR |
122 | ret = remap_ops->enable(); |
123 | ||
124 | if (irq_remapping_enabled) | |
125 | irq_remapping_modify_x86_ops(); | |
126 | ||
127 | return ret; | |
736baef4 | 128 | } |
4f3d8b67 | 129 | |
95a02e97 | 130 | void irq_remapping_disable(void) |
4f3d8b67 | 131 | { |
e9011760 JL |
132 | if (irq_remapping_enabled && remap_ops->disable) |
133 | remap_ops->disable(); | |
4f3d8b67 JR |
134 | } |
135 | ||
95a02e97 | 136 | int irq_remapping_reenable(int mode) |
4f3d8b67 | 137 | { |
e9011760 JL |
138 | if (irq_remapping_enabled && remap_ops->reenable) |
139 | return remap_ops->reenable(mode); | |
4f3d8b67 | 140 | |
e9011760 | 141 | return 0; |
4f3d8b67 JR |
142 | } |
143 | ||
95a02e97 | 144 | int __init irq_remap_enable_fault_handling(void) |
4f3d8b67 | 145 | { |
70733e0c JR |
146 | if (!irq_remapping_enabled) |
147 | return 0; | |
148 | ||
e9011760 | 149 | if (!remap_ops->enable_faulting) |
4f3d8b67 JR |
150 | return -ENODEV; |
151 | ||
152 | return remap_ops->enable_faulting(); | |
153 | } | |
0c3f173a | 154 | |
6a9f5de2 JR |
155 | void panic_if_irq_remap(const char *msg) |
156 | { | |
157 | if (irq_remapping_enabled) | |
158 | panic(msg); | |
159 | } | |
9b1b0e42 | 160 | |
947045a2 JL |
161 | /** |
162 | * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU | |
163 | * device serving request @info | |
164 | * @info: interrupt allocation information, used to identify the IOMMU device | |
165 | * | |
166 | * It's used to get parent irqdomain for HPET and IOAPIC irqdomains. | |
167 | * Returns pointer to IRQ domain, or NULL on failure. | |
168 | */ | |
169 | struct irq_domain * | |
170 | irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info) | |
171 | { | |
172 | if (!remap_ops || !remap_ops->get_ir_irq_domain) | |
173 | return NULL; | |
174 | ||
175 | return remap_ops->get_ir_irq_domain(info); | |
176 | } | |
177 | ||
178 | /** | |
179 | * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info | |
180 | * @info: interrupt allocation information, used to identify the IOMMU device | |
181 | * | |
182 | * There will be one PCI MSI/MSIX irqdomain associated with each interrupt | |
183 | * remapping device, so this interface is used to retrieve the PCI MSI/MSIX | |
184 | * irqdomain serving request @info. | |
185 | * Returns pointer to IRQ domain, or NULL on failure. | |
186 | */ | |
187 | struct irq_domain * | |
188 | irq_remapping_get_irq_domain(struct irq_alloc_info *info) | |
189 | { | |
190 | if (!remap_ops || !remap_ops->get_irq_domain) | |
191 | return NULL; | |
192 | ||
193 | return remap_ops->get_irq_domain(info); | |
194 | } |