iommu, x86: Setup Posted-Interrupts capability for Intel iommu
[deliverable/linux.git] / drivers / iommu / irq_remapping.c
CommitLineData
9b1b0e42 1#include <linux/seq_file.h>
1c4248ca 2#include <linux/cpumask.h>
736baef4
JR
3#include <linux/kernel.h>
4#include <linux/string.h>
5#include <linux/errno.h>
98f1ad25 6#include <linux/msi.h>
5afba62c
JR
7#include <linux/irq.h>
8#include <linux/pci.h>
a62b32cd 9#include <linux/irqdomain.h>
98f1ad25
JR
10
11#include <asm/hw_irq.h>
12#include <asm/irq_remapping.h>
1c4248ca
JR
13#include <asm/processor.h>
14#include <asm/x86_init.h>
15#include <asm/apic.h>
5fc24d8c 16#include <asm/hpet.h>
736baef4 17
8a8f422d 18#include "irq_remapping.h"
736baef4 19
95a02e97 20int irq_remapping_enabled;
03bbcb2e 21int irq_remap_broken;
736baef4
JR
22int disable_sourceid_checking;
23int no_x2apic_optout;
24
3d9b98f4
FW
25int disable_irq_post = 1;
26
7fa1c842 27static int disable_irq_remap;
736baef4
JR
28static struct irq_remap_ops *remap_ops;
29
1c4248ca
JR
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{
71054d88 45 x86_io_apic_ops.disable = irq_remapping_disable_io_apic;
1c4248ca
JR
46}
47
736baef4
JR
48static __init int setup_nointremap(char *str)
49{
95a02e97 50 disable_irq_remap = 1;
736baef4
JR
51 return 0;
52}
53early_param("nointremap", setup_nointremap);
54
95a02e97 55static __init int setup_irqremap(char *str)
736baef4
JR
56{
57 if (!str)
58 return -EINVAL;
59
60 while (*str) {
61 if (!strncmp(str, "on", 2))
95a02e97 62 disable_irq_remap = 0;
736baef4 63 else if (!strncmp(str, "off", 3))
95a02e97 64 disable_irq_remap = 1;
736baef4
JR
65 else if (!strncmp(str, "nosid", 5))
66 disable_sourceid_checking = 1;
67 else if (!strncmp(str, "no_x2apic_optout", 16))
68 no_x2apic_optout = 1;
69
70 str += strcspn(str, ",");
71 while (*str == ',')
72 str++;
73 }
74
75 return 0;
76}
95a02e97 77early_param("intremap", setup_irqremap);
736baef4 78
03bbcb2e
NH
79void set_irq_remapping_broken(void)
80{
81 irq_remap_broken = 1;
82}
83
c392f56c 84int __init irq_remapping_prepare(void)
736baef4 85{
95a02e97 86 if (disable_irq_remap)
c392f56c 87 return -ENOSYS;
736baef4 88
30969e34
JL
89 if (intel_irq_remap_ops.prepare() == 0)
90 remap_ops = &intel_irq_remap_ops;
91 else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
92 amd_iommu_irq_ops.prepare() == 0)
a1dafe85 93 remap_ops = &amd_iommu_irq_ops;
30969e34
JL
94 else
95 return -ENOSYS;
96
97 return 0;
736baef4
JR
98}
99
95a02e97 100int __init irq_remapping_enable(void)
736baef4 101{
1c4248ca
JR
102 int ret;
103
e9011760 104 if (!remap_ops->enable)
736baef4
JR
105 return -ENODEV;
106
1c4248ca
JR
107 ret = remap_ops->enable();
108
109 if (irq_remapping_enabled)
110 irq_remapping_modify_x86_ops();
111
112 return ret;
736baef4 113}
4f3d8b67 114
95a02e97 115void irq_remapping_disable(void)
4f3d8b67 116{
e9011760
JL
117 if (irq_remapping_enabled && remap_ops->disable)
118 remap_ops->disable();
4f3d8b67
JR
119}
120
95a02e97 121int irq_remapping_reenable(int mode)
4f3d8b67 122{
e9011760
JL
123 if (irq_remapping_enabled && remap_ops->reenable)
124 return remap_ops->reenable(mode);
4f3d8b67 125
e9011760 126 return 0;
4f3d8b67
JR
127}
128
95a02e97 129int __init irq_remap_enable_fault_handling(void)
4f3d8b67 130{
70733e0c
JR
131 if (!irq_remapping_enabled)
132 return 0;
133
e9011760 134 if (!remap_ops->enable_faulting)
4f3d8b67
JR
135 return -ENODEV;
136
137 return remap_ops->enable_faulting();
138}
0c3f173a 139
6a9f5de2
JR
140void panic_if_irq_remap(const char *msg)
141{
142 if (irq_remapping_enabled)
143 panic(msg);
144}
9b1b0e42 145
947045a2 146void ir_ack_apic_edge(struct irq_data *data)
9b1b0e42
JR
147{
148 ack_APIC_irq();
149}
150
947045a2
JL
151/**
152 * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
153 * device serving request @info
154 * @info: interrupt allocation information, used to identify the IOMMU device
155 *
156 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
157 * Returns pointer to IRQ domain, or NULL on failure.
158 */
159struct irq_domain *
160irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
161{
162 if (!remap_ops || !remap_ops->get_ir_irq_domain)
163 return NULL;
164
165 return remap_ops->get_ir_irq_domain(info);
166}
167
168/**
169 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
170 * @info: interrupt allocation information, used to identify the IOMMU device
171 *
172 * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
173 * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
174 * irqdomain serving request @info.
175 * Returns pointer to IRQ domain, or NULL on failure.
176 */
177struct irq_domain *
178irq_remapping_get_irq_domain(struct irq_alloc_info *info)
179{
180 if (!remap_ops || !remap_ops->get_irq_domain)
181 return NULL;
182
183 return remap_ops->get_irq_domain(info);
184}
This page took 0.198536 seconds and 5 git commands to generate.