blob: 913455a5fd40e044e21ec20095296027dad3c1e6 [file] [log] [blame]
Joerg Roedel9b1b0e42012-09-26 12:44:45 +02001#include <linux/seq_file.h>
Joerg Roedel1c4248c2012-09-26 12:44:35 +02002#include <linux/cpumask.h>
Joerg Roedel736baef2012-03-30 11:47:00 -07003#include <linux/kernel.h>
4#include <linux/string.h>
5#include <linux/errno.h>
Joerg Roedel98f1ad22012-07-06 13:28:37 +02006#include <linux/msi.h>
Joerg Roedel5afba622012-09-26 12:44:38 +02007#include <linux/irq.h>
8#include <linux/pci.h>
Jiang Liua62b32c2015-04-13 14:11:29 +08009#include <linux/irqdomain.h>
Joerg Roedel98f1ad22012-07-06 13:28:37 +020010
11#include <asm/hw_irq.h>
12#include <asm/irq_remapping.h>
Joerg Roedel1c4248c2012-09-26 12:44:35 +020013#include <asm/processor.h>
14#include <asm/x86_init.h>
15#include <asm/apic.h>
Yijing Wang5fc24d82014-09-17 17:32:19 +080016#include <asm/hpet.h>
Joerg Roedel736baef2012-03-30 11:47:00 -070017
Suresh Siddha8a8f4222012-03-30 11:47:08 -070018#include "irq_remapping.h"
Joerg Roedel736baef2012-03-30 11:47:00 -070019
Suresh Siddha95a02e92012-03-30 11:47:07 -070020int irq_remapping_enabled;
Neil Horman03bbcb22013-04-16 16:38:32 -040021int irq_remap_broken;
Joerg Roedel736baef2012-03-30 11:47:00 -070022int disable_sourceid_checking;
23int no_x2apic_optout;
24
Feng Wu3d9b98f2015-06-09 13:20:35 +080025int disable_irq_post = 1;
26
Jiang Liu7fa1c842015-01-07 15:31:42 +080027static int disable_irq_remap;
Joerg Roedel736baef2012-03-30 11:47:00 -070028static struct irq_remap_ops *remap_ops;
29
Joerg Roedel1c4248c2012-09-26 12:44:35 +020030static 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{
Joerg Roedel71054d82012-09-26 12:44:37 +020045 x86_io_apic_ops.disable = irq_remapping_disable_io_apic;
Joerg Roedel1c4248c2012-09-26 12:44:35 +020046}
47
Joerg Roedel736baef2012-03-30 11:47:00 -070048static __init int setup_nointremap(char *str)
49{
Suresh Siddha95a02e92012-03-30 11:47:07 -070050 disable_irq_remap = 1;
Joerg Roedel736baef2012-03-30 11:47:00 -070051 return 0;
52}
53early_param("nointremap", setup_nointremap);
54
Suresh Siddha95a02e92012-03-30 11:47:07 -070055static __init int setup_irqremap(char *str)
Joerg Roedel736baef2012-03-30 11:47:00 -070056{
57 if (!str)
58 return -EINVAL;
59
60 while (*str) {
61 if (!strncmp(str, "on", 2))
Suresh Siddha95a02e92012-03-30 11:47:07 -070062 disable_irq_remap = 0;
Joerg Roedel736baef2012-03-30 11:47:00 -070063 else if (!strncmp(str, "off", 3))
Suresh Siddha95a02e92012-03-30 11:47:07 -070064 disable_irq_remap = 1;
Joerg Roedel736baef2012-03-30 11:47:00 -070065 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}
Suresh Siddha95a02e92012-03-30 11:47:07 -070077early_param("intremap", setup_irqremap);
Joerg Roedel736baef2012-03-30 11:47:00 -070078
Neil Horman03bbcb22013-04-16 16:38:32 -040079void set_irq_remapping_broken(void)
80{
81 irq_remap_broken = 1;
82}
83
Feng Wu959c8702015-06-09 13:20:36 +080084bool irq_remapping_cap(enum irq_remap_cap cap)
85{
86 if (!remap_ops || disable_irq_post)
Joerg Roedel30e93762015-08-13 11:13:17 +020087 return false;
Feng Wu959c8702015-06-09 13:20:36 +080088
89 return (remap_ops->capability & (1 << cap));
90}
91EXPORT_SYMBOL_GPL(irq_remapping_cap);
92
Suresh Siddha95a02e92012-03-30 11:47:07 -070093int __init irq_remapping_prepare(void)
Joerg Roedel736baef2012-03-30 11:47:00 -070094{
Jiang Liuc392f562015-01-07 15:31:40 +080095 if (disable_irq_remap)
96 return -ENOSYS;
97
Jiang Liu30969e32015-01-07 15:31:41 +080098 if (intel_irq_remap_ops.prepare() == 0)
99 remap_ops = &intel_irq_remap_ops;
100 else if (IS_ENABLED(CONFIG_AMD_IOMMU) &&
101 amd_iommu_irq_ops.prepare() == 0)
Thomas Gleixnera1dafe82015-01-07 15:31:28 +0800102 remap_ops = &amd_iommu_irq_ops;
Jiang Liu30969e32015-01-07 15:31:41 +0800103 else
104 return -ENOSYS;
105
106 return 0;
Joerg Roedel736baef2012-03-30 11:47:00 -0700107}
108
Suresh Siddha95a02e92012-03-30 11:47:07 -0700109int __init irq_remapping_enable(void)
Joerg Roedel736baef2012-03-30 11:47:00 -0700110{
Joerg Roedel1c4248c2012-09-26 12:44:35 +0200111 int ret;
112
Jiang Liue9011762015-01-07 15:31:43 +0800113 if (!remap_ops->enable)
Joerg Roedel736baef2012-03-30 11:47:00 -0700114 return -ENODEV;
115
Joerg Roedel1c4248c2012-09-26 12:44:35 +0200116 ret = remap_ops->enable();
117
118 if (irq_remapping_enabled)
119 irq_remapping_modify_x86_ops();
120
121 return ret;
Joerg Roedel736baef2012-03-30 11:47:00 -0700122}
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700123
Suresh Siddha95a02e92012-03-30 11:47:07 -0700124void irq_remapping_disable(void)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700125{
Jiang Liue9011762015-01-07 15:31:43 +0800126 if (irq_remapping_enabled && remap_ops->disable)
127 remap_ops->disable();
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700128}
129
Suresh Siddha95a02e92012-03-30 11:47:07 -0700130int irq_remapping_reenable(int mode)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700131{
Jiang Liue9011762015-01-07 15:31:43 +0800132 if (irq_remapping_enabled && remap_ops->reenable)
133 return remap_ops->reenable(mode);
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700134
Jiang Liue9011762015-01-07 15:31:43 +0800135 return 0;
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700136}
137
Suresh Siddha95a02e92012-03-30 11:47:07 -0700138int __init irq_remap_enable_fault_handling(void)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700139{
Joerg Roedel70733e02012-09-26 12:44:33 +0200140 if (!irq_remapping_enabled)
141 return 0;
142
Jiang Liue9011762015-01-07 15:31:43 +0800143 if (!remap_ops->enable_faulting)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700144 return -ENODEV;
145
146 return remap_ops->enable_faulting();
147}
Joerg Roedel0c3f1732012-03-30 11:47:02 -0700148
Joerg Roedel6a9f5de2012-09-26 12:44:41 +0200149void panic_if_irq_remap(const char *msg)
150{
151 if (irq_remapping_enabled)
152 panic(msg);
153}
Joerg Roedel9b1b0e42012-09-26 12:44:45 +0200154
Jiang Liu947045a2015-04-13 14:11:30 +0800155void ir_ack_apic_edge(struct irq_data *data)
Joerg Roedel9b1b0e42012-09-26 12:44:45 +0200156{
157 ack_APIC_irq();
158}
159
Jiang Liu947045a2015-04-13 14:11:30 +0800160/**
161 * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU
162 * device serving request @info
163 * @info: interrupt allocation information, used to identify the IOMMU device
164 *
165 * It's used to get parent irqdomain for HPET and IOAPIC irqdomains.
166 * Returns pointer to IRQ domain, or NULL on failure.
167 */
168struct irq_domain *
169irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info)
170{
171 if (!remap_ops || !remap_ops->get_ir_irq_domain)
172 return NULL;
173
174 return remap_ops->get_ir_irq_domain(info);
175}
176
177/**
178 * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info
179 * @info: interrupt allocation information, used to identify the IOMMU device
180 *
181 * There will be one PCI MSI/MSIX irqdomain associated with each interrupt
182 * remapping device, so this interface is used to retrieve the PCI MSI/MSIX
183 * irqdomain serving request @info.
184 * Returns pointer to IRQ domain, or NULL on failure.
185 */
186struct irq_domain *
187irq_remapping_get_irq_domain(struct irq_alloc_info *info)
188{
189 if (!remap_ops || !remap_ops->get_irq_domain)
190 return NULL;
191
192 return remap_ops->get_irq_domain(info);
193}