]> Pileus Git - ~andy/linux/blob - drivers/iommu/irq_remapping.c
x86, io_apic: Introduce x86_io_apic_ops.disable()
[~andy/linux] / drivers / iommu / irq_remapping.c
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>
6 #include <linux/msi.h>
7
8 #include <asm/hw_irq.h>
9 #include <asm/irq_remapping.h>
10 #include <asm/processor.h>
11 #include <asm/x86_init.h>
12 #include <asm/apic.h>
13
14 #include "irq_remapping.h"
15
16 int irq_remapping_enabled;
17
18 int disable_irq_remap;
19 int disable_sourceid_checking;
20 int no_x2apic_optout;
21
22 static struct irq_remap_ops *remap_ops;
23
24 static void irq_remapping_disable_io_apic(void)
25 {
26         /*
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
31          * now.
32          */
33         if (cpu_has_apic || apic_from_smp_config())
34                 disconnect_bsp_APIC(0);
35 }
36
37 static void __init irq_remapping_modify_x86_ops(void)
38 {
39         x86_io_apic_ops.disable =       irq_remapping_disable_io_apic;
40 }
41
42 static __init int setup_nointremap(char *str)
43 {
44         disable_irq_remap = 1;
45         return 0;
46 }
47 early_param("nointremap", setup_nointremap);
48
49 static __init int setup_irqremap(char *str)
50 {
51         if (!str)
52                 return -EINVAL;
53
54         while (*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))
62                         no_x2apic_optout = 1;
63
64                 str += strcspn(str, ",");
65                 while (*str == ',')
66                         str++;
67         }
68
69         return 0;
70 }
71 early_param("intremap", setup_irqremap);
72
73 void __init setup_irq_remapping_ops(void)
74 {
75         remap_ops = &intel_irq_remap_ops;
76
77 #ifdef CONFIG_AMD_IOMMU
78         if (amd_iommu_irq_ops.prepare() == 0)
79                 remap_ops = &amd_iommu_irq_ops;
80 #endif
81 }
82
83 int irq_remapping_supported(void)
84 {
85         if (disable_irq_remap)
86                 return 0;
87
88         if (!remap_ops || !remap_ops->supported)
89                 return 0;
90
91         return remap_ops->supported();
92 }
93
94 int __init irq_remapping_prepare(void)
95 {
96         if (!remap_ops || !remap_ops->prepare)
97                 return -ENODEV;
98
99         return remap_ops->prepare();
100 }
101
102 int __init irq_remapping_enable(void)
103 {
104         int ret;
105
106         if (!remap_ops || !remap_ops->enable)
107                 return -ENODEV;
108
109         ret = remap_ops->enable();
110
111         if (irq_remapping_enabled)
112                 irq_remapping_modify_x86_ops();
113
114         return ret;
115 }
116
117 void irq_remapping_disable(void)
118 {
119         if (!irq_remapping_enabled ||
120             !remap_ops ||
121             !remap_ops->disable)
122                 return;
123
124         remap_ops->disable();
125 }
126
127 int irq_remapping_reenable(int mode)
128 {
129         if (!irq_remapping_enabled ||
130             !remap_ops ||
131             !remap_ops->reenable)
132                 return 0;
133
134         return remap_ops->reenable(mode);
135 }
136
137 int __init irq_remap_enable_fault_handling(void)
138 {
139         if (!irq_remapping_enabled)
140                 return 0;
141
142         if (!remap_ops || !remap_ops->enable_faulting)
143                 return -ENODEV;
144
145         return remap_ops->enable_faulting();
146 }
147
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)
152 {
153         if (!remap_ops || !remap_ops->setup_ioapic_entry)
154                 return -ENODEV;
155
156         return remap_ops->setup_ioapic_entry(irq, entry, destination,
157                                              vector, attr);
158 }
159
160 int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask,
161                               bool force)
162 {
163         if (!config_enabled(CONFIG_SMP) || !remap_ops ||
164             !remap_ops->set_affinity)
165                 return 0;
166
167         return remap_ops->set_affinity(data, mask, force);
168 }
169
170 void free_remapped_irq(int irq)
171 {
172         if (!remap_ops || !remap_ops->free_irq)
173                 return;
174
175         remap_ops->free_irq(irq);
176 }
177
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)
181 {
182         if (!remap_ops || !remap_ops->compose_msi_msg)
183                 return;
184
185         remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id);
186 }
187
188 int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec)
189 {
190         if (!remap_ops || !remap_ops->msi_alloc_irq)
191                 return -ENODEV;
192
193         return remap_ops->msi_alloc_irq(pdev, irq, nvec);
194 }
195
196 int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq,
197                            int index, int sub_handle)
198 {
199         if (!remap_ops || !remap_ops->msi_setup_irq)
200                 return -ENODEV;
201
202         return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle);
203 }
204
205 int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
206 {
207         if (!remap_ops || !remap_ops->setup_hpet_msi)
208                 return -ENODEV;
209
210         return remap_ops->setup_hpet_msi(irq, id);
211 }