Loading...
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>
6#include <linux/msi.h>
7#include <linux/irq.h>
8#include <linux/pci.h>
9#include <linux/irqdomain.h>
10
11#include <asm/hw_irq.h>
12#include <asm/irq_remapping.h>
13#include <asm/processor.h>
14#include <asm/x86_init.h>
15#include <asm/apic.h>
16#include <asm/hpet.h>
17
18#include "irq_remapping.h"
19
20int irq_remapping_enabled;
21int irq_remap_broken;
22int disable_sourceid_checking;
23int no_x2apic_optout;
24
25int disable_irq_post = 0;
26
27static int disable_irq_remap;
28static struct irq_remap_ops *remap_ops;
29
30static void irq_remapping_disable_io_apic(void)
31{
32 /*
33 * With interrupt-remapping, for now we will use virtual wire A
34 * mode, as virtual wire B is little complex (need to configure
35 * both IOAPIC RTE as well as interrupt-remapping table entry).
36 * As this gets called during crash dump, keep this simple for
37 * now.
38 */
39 if (cpu_has_apic || apic_from_smp_config())
40 disconnect_bsp_APIC(0);
41}
42
43static void __init irq_remapping_modify_x86_ops(void)
44{
45 x86_io_apic_ops.disable = irq_remapping_disable_io_apic;
46}
47
48static __init int setup_nointremap(char *str)
49{
50 disable_irq_remap = 1;
51 return 0;
52}
53early_param("nointremap", setup_nointremap);
54
55static __init int setup_irqremap(char *str)
56{
57 if (!str)
58 return -EINVAL;
59
60 while (*str) {
61 if (!strncmp(str, "on", 2)) {
62 disable_irq_remap = 0;
63 disable_irq_post = 0;
64 } else if (!strncmp(str, "off", 3)) {
65 disable_irq_remap = 1;
66 disable_irq_post = 1;
67 } else if (!strncmp(str, "nosid", 5))
68 disable_sourceid_checking = 1;
69 else if (!strncmp(str, "no_x2apic_optout", 16))
70 no_x2apic_optout = 1;
71 else if (!strncmp(str, "nopost", 6))
72 disable_irq_post = 1;
73
74 str += strcspn(str, ",");
75 while (*str == ',')
76 str++;
77 }
78
79 return 0;
80}
81early_param("intremap", setup_irqremap);
82
83void set_irq_remapping_broken(void)
84{
85 irq_remap_broken = 1;
86}
87
88bool irq_remapping_cap(enum irq_remap_cap cap)
89{
90 if (!remap_ops || disable_irq_post)
91 return false;
92
93 return (remap_ops->capability & (1 << cap));
94}
95EXPORT_SYMBOL_GPL(irq_remapping_cap);
96
97int __init irq_remapping_prepare(void)
98{
99 if (disable_irq_remap)
100 return -ENOSYS;
101
102 if (intel_irq_remap_ops.prepare() == 0)
103 remap_ops = &intel_irq_remap_ops;
104 else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
105 amd_iommu_irq_ops.prepare() == 0)
106 remap_ops = &amd_iommu_irq_ops;
107 else
108 return -ENOSYS;
109
110 return 0;
111}
112
113int __init irq_remapping_enable(void)
114{
115 int ret;
116
117 if (!remap_ops->enable)
118 return -ENODEV;
119
120 ret = remap_ops->enable();
121
122 if (irq_remapping_enabled)
123 irq_remapping_modify_x86_ops();
124
125 return ret;
126}
127
128void irq_remapping_disable(void)
129{
130 if (irq_remapping_enabled && remap_ops->disable)
131 remap_ops->disable();
132}
133
134int irq_remapping_reenable(int mode)
135{
136 if (irq_remapping_enabled && remap_ops->reenable)
137 return remap_ops->reenable(mode);
138
139 return 0;
140}
141
142int __init irq_remap_enable_fault_handling(void)
143{
144 if (!irq_remapping_enabled)
145 return 0;
146
147 if (!remap_ops->enable_faulting)
148 return -ENODEV;
149
150 return remap_ops->enable_faulting();
151}
152
153void panic_if_irq_remap(const char *msg)
154{
155 if (irq_remapping_enabled)
156 panic(msg);
157}
158
159void ir_ack_apic_edge(struct irq_data *data)
160{
161 ack_APIC_irq();
162}
163
164/**
165 * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
166 * device serving request @info
167 * @info: interrupt allocation information, used to identify the IOMMU device
168 *
169 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
170 * Returns pointer to IRQ domain, or NULL on failure.
171 */
172struct irq_domain *
173irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
174{
175 if (!remap_ops || !remap_ops->get_ir_irq_domain)
176 return NULL;
177
178 return remap_ops->get_ir_irq_domain(info);
179}
180
181/**
182 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
183 * @info: interrupt allocation information, used to identify the IOMMU device
184 *
185 * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
186 * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
187 * irqdomain serving request @info.
188 * Returns pointer to IRQ domain, or NULL on failure.
189 */
190struct irq_domain *
191irq_remapping_get_irq_domain(struct irq_alloc_info *info)
192{
193 if (!remap_ops || !remap_ops->get_irq_domain)
194 return NULL;
195
196 return remap_ops->get_irq_domain(info);
197}
1#include <linux/kernel.h>
2#include <linux/string.h>
3#include <linux/errno.h>
4
5#include "irq_remapping.h"
6
7int irq_remapping_enabled;
8
9int disable_irq_remap;
10int disable_sourceid_checking;
11int no_x2apic_optout;
12
13static struct irq_remap_ops *remap_ops;
14
15static __init int setup_nointremap(char *str)
16{
17 disable_irq_remap = 1;
18 return 0;
19}
20early_param("nointremap", setup_nointremap);
21
22static __init int setup_irqremap(char *str)
23{
24 if (!str)
25 return -EINVAL;
26
27 while (*str) {
28 if (!strncmp(str, "on", 2))
29 disable_irq_remap = 0;
30 else if (!strncmp(str, "off", 3))
31 disable_irq_remap = 1;
32 else if (!strncmp(str, "nosid", 5))
33 disable_sourceid_checking = 1;
34 else if (!strncmp(str, "no_x2apic_optout", 16))
35 no_x2apic_optout = 1;
36
37 str += strcspn(str, ",");
38 while (*str == ',')
39 str++;
40 }
41
42 return 0;
43}
44early_param("intremap", setup_irqremap);
45
46void __init setup_irq_remapping_ops(void)
47{
48 remap_ops = &intel_irq_remap_ops;
49}
50
51int irq_remapping_supported(void)
52{
53 if (disable_irq_remap)
54 return 0;
55
56 if (!remap_ops || !remap_ops->supported)
57 return 0;
58
59 return remap_ops->supported();
60}
61
62int __init irq_remapping_prepare(void)
63{
64 if (!remap_ops || !remap_ops->prepare)
65 return -ENODEV;
66
67 return remap_ops->prepare();
68}
69
70int __init irq_remapping_enable(void)
71{
72 if (!remap_ops || !remap_ops->enable)
73 return -ENODEV;
74
75 return remap_ops->enable();
76}
77
78void irq_remapping_disable(void)
79{
80 if (!remap_ops || !remap_ops->disable)
81 return;
82
83 remap_ops->disable();
84}
85
86int irq_remapping_reenable(int mode)
87{
88 if (!remap_ops || !remap_ops->reenable)
89 return 0;
90
91 return remap_ops->reenable(mode);
92}
93
94int __init irq_remap_enable_fault_handling(void)
95{
96 if (!remap_ops || !remap_ops->enable_faulting)
97 return -ENODEV;
98
99 return remap_ops->enable_faulting();
100}
101
102int setup_ioapic_remapped_entry(int irq,
103 struct IO_APIC_route_entry *entry,
104 unsigned int destination, int vector,
105 struct io_apic_irq_attr *attr)
106{
107 if (!remap_ops || !remap_ops->setup_ioapic_entry)
108 return -ENODEV;
109
110 return remap_ops->setup_ioapic_entry(irq, entry, destination,
111 vector, attr);
112}
113
114#ifdef CONFIG_SMP
115int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask,
116 bool force)
117{
118 if (!remap_ops || !remap_ops->set_affinity)
119 return 0;
120
121 return remap_ops->set_affinity(data, mask, force);
122}
123#endif
124
125void free_remapped_irq(int irq)
126{
127 if (!remap_ops || !remap_ops->free_irq)
128 return;
129
130 remap_ops->free_irq(irq);
131}
132
133void compose_remapped_msi_msg(struct pci_dev *pdev,
134 unsigned int irq, unsigned int dest,
135 struct msi_msg *msg, u8 hpet_id)
136{
137 if (!remap_ops || !remap_ops->compose_msi_msg)
138 return;
139
140 remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id);
141}
142
143int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec)
144{
145 if (!remap_ops || !remap_ops->msi_alloc_irq)
146 return -ENODEV;
147
148 return remap_ops->msi_alloc_irq(pdev, irq, nvec);
149}
150
151int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq,
152 int index, int sub_handle)
153{
154 if (!remap_ops || !remap_ops->msi_setup_irq)
155 return -ENODEV;
156
157 return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle);
158}
159
160int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
161{
162 if (!remap_ops || !remap_ops->setup_hpet_msi)
163 return -ENODEV;
164
165 return remap_ops->setup_hpet_msi(irq, id);
166}