x86, hpet: Introduce x86_msi_ops.setup_hpet_msi
[cascardo/linux.git] / 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         x86_msi.setup_hpet_msi          = setup_hpet_msi_remapped;
41 }
42
43 static __init int setup_nointremap(char *str)
44 {
45         disable_irq_remap = 1;
46         return 0;
47 }
48 early_param("nointremap", setup_nointremap);
49
50 static __init int setup_irqremap(char *str)
51 {
52         if (!str)
53                 return -EINVAL;
54
55         while (*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))
63                         no_x2apic_optout = 1;
64
65                 str += strcspn(str, ",");
66                 while (*str == ',')
67                         str++;
68         }
69
70         return 0;
71 }
72 early_param("intremap", setup_irqremap);
73
74 void __init setup_irq_remapping_ops(void)
75 {
76         remap_ops = &intel_irq_remap_ops;
77
78 #ifdef CONFIG_AMD_IOMMU
79         if (amd_iommu_irq_ops.prepare() == 0)
80                 remap_ops = &amd_iommu_irq_ops;
81 #endif
82 }
83
84 int irq_remapping_supported(void)
85 {
86         if (disable_irq_remap)
87                 return 0;
88
89         if (!remap_ops || !remap_ops->supported)
90                 return 0;
91
92         return remap_ops->supported();
93 }
94
95 int __init irq_remapping_prepare(void)
96 {
97         if (!remap_ops || !remap_ops->prepare)
98                 return -ENODEV;
99
100         return remap_ops->prepare();
101 }
102
103 int __init irq_remapping_enable(void)
104 {
105         int ret;
106
107         if (!remap_ops || !remap_ops->enable)
108                 return -ENODEV;
109
110         ret = remap_ops->enable();
111
112         if (irq_remapping_enabled)
113                 irq_remapping_modify_x86_ops();
114
115         return ret;
116 }
117
118 void irq_remapping_disable(void)
119 {
120         if (!irq_remapping_enabled ||
121             !remap_ops ||
122             !remap_ops->disable)
123                 return;
124
125         remap_ops->disable();
126 }
127
128 int irq_remapping_reenable(int mode)
129 {
130         if (!irq_remapping_enabled ||
131             !remap_ops ||
132             !remap_ops->reenable)
133                 return 0;
134
135         return remap_ops->reenable(mode);
136 }
137
138 int __init irq_remap_enable_fault_handling(void)
139 {
140         if (!irq_remapping_enabled)
141                 return 0;
142
143         if (!remap_ops || !remap_ops->enable_faulting)
144                 return -ENODEV;
145
146         return remap_ops->enable_faulting();
147 }
148
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)
153 {
154         if (!remap_ops || !remap_ops->setup_ioapic_entry)
155                 return -ENODEV;
156
157         return remap_ops->setup_ioapic_entry(irq, entry, destination,
158                                              vector, attr);
159 }
160
161 int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask,
162                               bool force)
163 {
164         if (!config_enabled(CONFIG_SMP) || !remap_ops ||
165             !remap_ops->set_affinity)
166                 return 0;
167
168         return remap_ops->set_affinity(data, mask, force);
169 }
170
171 void free_remapped_irq(int irq)
172 {
173         if (!remap_ops || !remap_ops->free_irq)
174                 return;
175
176         remap_ops->free_irq(irq);
177 }
178
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)
182 {
183         if (!remap_ops || !remap_ops->compose_msi_msg)
184                 return;
185
186         remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id);
187 }
188
189 int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec)
190 {
191         if (!remap_ops || !remap_ops->msi_alloc_irq)
192                 return -ENODEV;
193
194         return remap_ops->msi_alloc_irq(pdev, irq, nvec);
195 }
196
197 int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq,
198                            int index, int sub_handle)
199 {
200         if (!remap_ops || !remap_ops->msi_setup_irq)
201                 return -ENODEV;
202
203         return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle);
204 }
205
206 int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
207 {
208         if (!remap_ops || !remap_ops->setup_hpet_msi)
209                 return -ENODEV;
210
211         return remap_ops->setup_hpet_msi(irq, id);
212 }