blob: 151690db692c642dbfb73854ea49059b5077f628 [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;
54}
55
Suresh Siddha95a02e92012-03-30 11:47:07 -070056int irq_remapping_supported(void)
Joerg Roedel736baef2012-03-30 11:47:00 -070057{
Suresh Siddha95a02e92012-03-30 11:47:07 -070058 if (disable_irq_remap)
Joerg Roedel736baef2012-03-30 11:47:00 -070059 return 0;
60
61 if (!remap_ops || !remap_ops->supported)
62 return 0;
63
64 return remap_ops->supported();
65}
66
Suresh Siddha95a02e92012-03-30 11:47:07 -070067int __init irq_remapping_prepare(void)
Joerg Roedel736baef2012-03-30 11:47:00 -070068{
Suresh Siddha95a02e92012-03-30 11:47:07 -070069 if (!remap_ops || !remap_ops->prepare)
Joerg Roedel736baef2012-03-30 11:47:00 -070070 return -ENODEV;
71
Suresh Siddha95a02e92012-03-30 11:47:07 -070072 return remap_ops->prepare();
Joerg Roedel736baef2012-03-30 11:47:00 -070073}
74
Suresh Siddha95a02e92012-03-30 11:47:07 -070075int __init irq_remapping_enable(void)
Joerg Roedel736baef2012-03-30 11:47:00 -070076{
Suresh Siddha95a02e92012-03-30 11:47:07 -070077 if (!remap_ops || !remap_ops->enable)
Joerg Roedel736baef2012-03-30 11:47:00 -070078 return -ENODEV;
79
Suresh Siddha95a02e92012-03-30 11:47:07 -070080 return remap_ops->enable();
Joerg Roedel736baef2012-03-30 11:47:00 -070081}
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070082
Suresh Siddha95a02e92012-03-30 11:47:07 -070083void irq_remapping_disable(void)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070084{
Suresh Siddha95a02e92012-03-30 11:47:07 -070085 if (!remap_ops || !remap_ops->disable)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070086 return;
87
Suresh Siddha95a02e92012-03-30 11:47:07 -070088 remap_ops->disable();
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070089}
90
Suresh Siddha95a02e92012-03-30 11:47:07 -070091int irq_remapping_reenable(int mode)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070092{
Suresh Siddha95a02e92012-03-30 11:47:07 -070093 if (!remap_ops || !remap_ops->reenable)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070094 return 0;
95
Suresh Siddha95a02e92012-03-30 11:47:07 -070096 return remap_ops->reenable(mode);
Joerg Roedel4f3d8b62012-03-30 11:47:01 -070097}
98
Suresh Siddha95a02e92012-03-30 11:47:07 -070099int __init irq_remap_enable_fault_handling(void)
Joerg Roedel4f3d8b62012-03-30 11:47:01 -0700100{
101 if (!remap_ops || !remap_ops->enable_faulting)
102 return -ENODEV;
103
104 return remap_ops->enable_faulting();
105}
Joerg Roedel0c3f1732012-03-30 11:47:02 -0700106
Suresh Siddha95a02e92012-03-30 11:47:07 -0700107int setup_ioapic_remapped_entry(int irq,
108 struct IO_APIC_route_entry *entry,
109 unsigned int destination, int vector,
110 struct io_apic_irq_attr *attr)
Joerg Roedel0c3f1732012-03-30 11:47:02 -0700111{
112 if (!remap_ops || !remap_ops->setup_ioapic_entry)
113 return -ENODEV;
114
115 return remap_ops->setup_ioapic_entry(irq, entry, destination,
116 vector, attr);
117}
Joerg Roedel4c1bad62012-03-30 11:47:03 -0700118
Suresh Siddha95a02e92012-03-30 11:47:07 -0700119int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask,
120 bool force)
Joerg Roedel4c1bad62012-03-30 11:47:03 -0700121{
Suresh Siddha7eb9ae02012-06-14 18:28:49 -0700122 if (!config_enabled(CONFIG_SMP) || !remap_ops ||
123 !remap_ops->set_affinity)
Joerg Roedel4c1bad62012-03-30 11:47:03 -0700124 return 0;
125
126 return remap_ops->set_affinity(data, mask, force);
127}
Joerg Roedel9d619f62012-03-30 11:47:04 -0700128
Suresh Siddha95a02e92012-03-30 11:47:07 -0700129void free_remapped_irq(int irq)
Joerg Roedel9d619f62012-03-30 11:47:04 -0700130{
131 if (!remap_ops || !remap_ops->free_irq)
132 return;
133
134 remap_ops->free_irq(irq);
135}
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700136
Suresh Siddha95a02e92012-03-30 11:47:07 -0700137void compose_remapped_msi_msg(struct pci_dev *pdev,
138 unsigned int irq, unsigned int dest,
139 struct msi_msg *msg, u8 hpet_id)
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700140{
141 if (!remap_ops || !remap_ops->compose_msi_msg)
142 return;
143
144 remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id);
145}
146
Suresh Siddha95a02e92012-03-30 11:47:07 -0700147int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec)
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700148{
149 if (!remap_ops || !remap_ops->msi_alloc_irq)
150 return -ENODEV;
151
152 return remap_ops->msi_alloc_irq(pdev, irq, nvec);
153}
154
Suresh Siddha95a02e92012-03-30 11:47:07 -0700155int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq,
156 int index, int sub_handle)
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700157{
158 if (!remap_ops || !remap_ops->msi_setup_irq)
159 return -ENODEV;
160
161 return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle);
162}
163
Suresh Siddha95a02e92012-03-30 11:47:07 -0700164int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
Joerg Roedel5e2b9302012-03-30 11:47:05 -0700165{
166 if (!remap_ops || !remap_ops->setup_hpet_msi)
167 return -ENODEV;
168
169 return remap_ops->setup_hpet_msi(irq, id);
170}