blob: faf85d6e33fe0bb3dde0c229570fac156d9e9798 [file] [log] [blame]
Joerg Roedel736baef2012-03-30 11:47:00 -07001#include <linux/kernel.h>
2#include <linux/string.h>
Joerg Roedel98f1ad22012-07-06 13:28:37 +02003#include <linux/cpumask.h>
Joerg Roedel736baef2012-03-30 11:47:00 -07004#include <linux/errno.h>
Joerg Roedel98f1ad22012-07-06 13:28:37 +02005#include <linux/msi.h>
6
7#include <asm/hw_irq.h>
8#include <asm/irq_remapping.h>
Joerg Roedel736baef2012-03-30 11:47:00 -07009
Suresh Siddha8a8f4222012-03-30 11:47:08 -070010#include "irq_remapping.h"
Joerg Roedel736baef2012-03-30 11:47:00 -070011
Suresh Siddha95a02e92012-03-30 11:47:07 -070012int irq_remapping_enabled;
Joerg Roedel736baef2012-03-30 11:47:00 -070013
Suresh Siddha95a02e92012-03-30 11:47:07 -070014int disable_irq_remap;
Joerg Roedel736baef2012-03-30 11:47:00 -070015int disable_sourceid_checking;
16int no_x2apic_optout;
17
18static struct irq_remap_ops *remap_ops;
19
20static __init int setup_nointremap(char *str)
21{
Suresh Siddha95a02e92012-03-30 11:47:07 -070022 disable_irq_remap = 1;
Joerg Roedel736baef2012-03-30 11:47:00 -070023 return 0;
24}
25early_param("nointremap", setup_nointremap);
26
Suresh Siddha95a02e92012-03-30 11:47:07 -070027static __init int setup_irqremap(char *str)
Joerg Roedel736baef2012-03-30 11:47:00 -070028{
29 if (!str)
30 return -EINVAL;
31
32 while (*str) {
33 if (!strncmp(str, "on", 2))
Suresh Siddha95a02e92012-03-30 11:47:07 -070034 disable_irq_remap = 0;
Joerg Roedel736baef2012-03-30 11:47:00 -070035 else if (!strncmp(str, "off", 3))
Suresh Siddha95a02e92012-03-30 11:47:07 -070036 disable_irq_remap = 1;
Joerg Roedel736baef2012-03-30 11:47:00 -070037 else if (!strncmp(str, "nosid", 5))
38 disable_sourceid_checking = 1;
39 else if (!strncmp(str, "no_x2apic_optout", 16))
40 no_x2apic_optout = 1;
41
42 str += strcspn(str, ",");
43 while (*str == ',')
44 str++;
45 }
46
47 return 0;
48}
Suresh Siddha95a02e92012-03-30 11:47:07 -070049early_param("intremap", setup_irqremap);
Joerg Roedel736baef2012-03-30 11:47:00 -070050
Suresh Siddha95a02e92012-03-30 11:47:07 -070051void __init setup_irq_remapping_ops(void)
Joerg Roedel736baef2012-03-30 11:47:00 -070052{
53 remap_ops = &intel_irq_remap_ops;
Joerg Roedelc18d2382012-06-26 16:59:34 +020054
55#ifdef CONFIG_AMD_IOMMU
56 if (amd_iommu_irq_ops.prepare() == 0)
57 remap_ops = &amd_iommu_irq_ops;
58#endif
Joerg Roedel736baef2012-03-30 11:47:00 -070059}
60
Suresh Siddha95a02e92012-03-30 11:47:07 -070061int irq_remapping_supported(void)
Joerg Roedel736baef2012-03-30 11:47:00 -070062{
Suresh Siddha95a02e92012-03-30 11:47:07 -070063 if (disable_irq_remap)
Joerg Roedel736baef2012-03-30 11:47:00 -070064 return 0;
65
66 if (!remap_ops || !remap_ops->supported)
67 return 0;
68
69 return remap_ops->supported();
70}
71
Suresh Siddha95a02e92012-03-30 11:47:07 -070072int __init irq_remapping_prepare(void)
Joerg Roedel736baef2012-03-30 11:47:00 -070073{
Suresh Siddha95a02e92012-03-30 11:47:07 -070074 if (!remap_ops || !remap_ops->prepare)
Joerg Roedel736baef2012-03-30 11:47:00 -070075 return -ENODEV;
76
Suresh Siddha95a02e92012-03-30 11:47:07 -070077 return remap_ops->prepare();
Joerg Roedel736baef2012-03-30 11:47:00 -070078}
79
Suresh Siddha95a02e92012-03-30 11:47:07 -070080int __init irq_remapping_enable(void)
Joerg Roedel736baef2012-03-30 11:47:00 -070081{
Suresh Siddha95a02e92012-03-30 11:47:07 -070082 if (!remap_ops || !remap_ops->enable)
Joerg Roedel736baef2012-03-30 11:47:00 -070083 return -ENODEV;
84
Suresh Siddha95a02e92012-03-30 11:47:07 -070085 return remap_ops->enable();
Joerg Roedel736baef2012-03-30 11:47:00 -070086}
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070087
Suresh Siddha95a02e92012-03-30 11:47:07 -070088void irq_remapping_disable(void)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070089{
Suresh Siddha95a02e92012-03-30 11:47:07 -070090 if (!remap_ops || !remap_ops->disable)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070091 return;
92
Suresh Siddha95a02e92012-03-30 11:47:07 -070093 remap_ops->disable();
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070094}
95
Suresh Siddha95a02e92012-03-30 11:47:07 -070096int irq_remapping_reenable(int mode)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070097{
Suresh Siddha95a02e92012-03-30 11:47:07 -070098 if (!remap_ops || !remap_ops->reenable)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070099 return 0;
100
Suresh Siddha95a02e92012-03-30 11:47:07 -0700101 return remap_ops->reenable(mode);
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700102}
103
Suresh Siddha95a02e92012-03-30 11:47:07 -0700104int __init irq_remap_enable_fault_handling(void)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700105{
106 if (!remap_ops || !remap_ops->enable_faulting)
107 return -ENODEV;
108
109 return remap_ops->enable_faulting();
110}
Joerg Roedel0c3f1732012-03-30 11:47:02 -0700111
Suresh Siddha95a02e92012-03-30 11:47:07 -0700112int setup_ioapic_remapped_entry(int irq,
113 struct IO_APIC_route_entry *entry,
114 unsigned int destination, int vector,
115 struct io_apic_irq_attr *attr)
Joerg Roedel0c3f1732012-03-30 11:47:02 -0700116{
117 if (!remap_ops || !remap_ops->setup_ioapic_entry)
118 return -ENODEV;
119
120 return remap_ops->setup_ioapic_entry(irq, entry, destination,
121 vector, attr);
122}
Joerg Roedel4c1bad62012-03-30 11:47:03 -0700123
Suresh Siddha95a02e92012-03-30 11:47:07 -0700124int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask,
125 bool force)
Joerg Roedel4c1bad62012-03-30 11:47:03 -0700126{
Suresh Siddha7eb9ae02012-06-14 18:28:49 -0700127 if (!config_enabled(CONFIG_SMP) || !remap_ops ||
128 !remap_ops->set_affinity)
Joerg Roedel4c1bad62012-03-30 11:47:03 -0700129 return 0;
130
131 return remap_ops->set_affinity(data, mask, force);
132}
Joerg Roedel9d619f62012-03-30 11:47:04 -0700133
Suresh Siddha95a02e92012-03-30 11:47:07 -0700134void free_remapped_irq(int irq)
Joerg Roedel9d619f62012-03-30 11:47:04 -0700135{
136 if (!remap_ops || !remap_ops->free_irq)
137 return;
138
139 remap_ops->free_irq(irq);
140}
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700141
Suresh Siddha95a02e92012-03-30 11:47:07 -0700142void compose_remapped_msi_msg(struct pci_dev *pdev,
143 unsigned int irq, unsigned int dest,
144 struct msi_msg *msg, u8 hpet_id)
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700145{
146 if (!remap_ops || !remap_ops->compose_msi_msg)
147 return;
148
149 remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id);
150}
151
Suresh Siddha95a02e92012-03-30 11:47:07 -0700152int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec)
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700153{
154 if (!remap_ops || !remap_ops->msi_alloc_irq)
155 return -ENODEV;
156
157 return remap_ops->msi_alloc_irq(pdev, irq, nvec);
158}
159
Suresh Siddha95a02e92012-03-30 11:47:07 -0700160int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq,
161 int index, int sub_handle)
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700162{
163 if (!remap_ops || !remap_ops->msi_setup_irq)
164 return -ENODEV;
165
166 return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle);
167}
168
Suresh Siddha95a02e92012-03-30 11:47:07 -0700169int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700170{
171 if (!remap_ops || !remap_ops->setup_hpet_msi)
172 return -ENODEV;
173
174 return remap_ops->setup_hpet_msi(irq, id);
175}