Joerg Roedel | 9b1b0e4 | 2012-09-26 12:44:45 +0200 | [diff] [blame] | 1 | #include <linux/seq_file.h> |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 2 | #include <linux/cpumask.h> |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 3 | #include <linux/kernel.h> |
| 4 | #include <linux/string.h> |
| 5 | #include <linux/errno.h> |
Joerg Roedel | 98f1ad2 | 2012-07-06 13:28:37 +0200 | [diff] [blame] | 6 | #include <linux/msi.h> |
Joerg Roedel | 5afba62 | 2012-09-26 12:44:38 +0200 | [diff] [blame] | 7 | #include <linux/irq.h> |
| 8 | #include <linux/pci.h> |
Jiang Liu | a62b32c | 2015-04-13 14:11:29 +0800 | [diff] [blame] | 9 | #include <linux/irqdomain.h> |
Joerg Roedel | 98f1ad2 | 2012-07-06 13:28:37 +0200 | [diff] [blame] | 10 | |
| 11 | #include <asm/hw_irq.h> |
| 12 | #include <asm/irq_remapping.h> |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 13 | #include <asm/processor.h> |
| 14 | #include <asm/x86_init.h> |
| 15 | #include <asm/apic.h> |
Yijing Wang | 5fc24d8 | 2014-09-17 17:32:19 +0800 | [diff] [blame] | 16 | #include <asm/hpet.h> |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 17 | |
Suresh Siddha | 8a8f422 | 2012-03-30 11:47:08 -0700 | [diff] [blame] | 18 | #include "irq_remapping.h" |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 19 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 20 | int irq_remapping_enabled; |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 21 | int irq_remap_broken; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 22 | int disable_sourceid_checking; |
| 23 | int no_x2apic_optout; |
| 24 | |
Feng Wu | b7d2063 | 2015-09-18 22:29:56 +0800 | [diff] [blame] | 25 | int disable_irq_post = 0; |
Feng Wu | 3d9b98f | 2015-06-09 13:20:35 +0800 | [diff] [blame] | 26 | |
Jiang Liu | 7fa1c84 | 2015-01-07 15:31:42 +0800 | [diff] [blame] | 27 | static int disable_irq_remap; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 28 | static struct irq_remap_ops *remap_ops; |
| 29 | |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 30 | static 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 | |
| 43 | static void __init irq_remapping_modify_x86_ops(void) |
| 44 | { |
Joerg Roedel | 71054d8 | 2012-09-26 12:44:37 +0200 | [diff] [blame] | 45 | x86_io_apic_ops.disable = irq_remapping_disable_io_apic; |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 46 | } |
| 47 | |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 48 | static __init int setup_nointremap(char *str) |
| 49 | { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 50 | disable_irq_remap = 1; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | early_param("nointremap", setup_nointremap); |
| 54 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 55 | static __init int setup_irqremap(char *str) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 56 | { |
| 57 | if (!str) |
| 58 | return -EINVAL; |
| 59 | |
| 60 | while (*str) { |
Feng Wu | b7d2063 | 2015-09-18 22:29:56 +0800 | [diff] [blame] | 61 | if (!strncmp(str, "on", 2)) { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 62 | disable_irq_remap = 0; |
Feng Wu | b7d2063 | 2015-09-18 22:29:56 +0800 | [diff] [blame] | 63 | disable_irq_post = 0; |
| 64 | } else if (!strncmp(str, "off", 3)) { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 65 | disable_irq_remap = 1; |
Feng Wu | b7d2063 | 2015-09-18 22:29:56 +0800 | [diff] [blame] | 66 | disable_irq_post = 1; |
| 67 | } else if (!strncmp(str, "nosid", 5)) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 68 | disable_sourceid_checking = 1; |
| 69 | else if (!strncmp(str, "no_x2apic_optout", 16)) |
| 70 | no_x2apic_optout = 1; |
Feng Wu | b7d2063 | 2015-09-18 22:29:56 +0800 | [diff] [blame] | 71 | else if (!strncmp(str, "nopost", 6)) |
| 72 | disable_irq_post = 1; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 73 | |
| 74 | str += strcspn(str, ","); |
| 75 | while (*str == ',') |
| 76 | str++; |
| 77 | } |
| 78 | |
| 79 | return 0; |
| 80 | } |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 81 | early_param("intremap", setup_irqremap); |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 82 | |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 83 | void set_irq_remapping_broken(void) |
| 84 | { |
| 85 | irq_remap_broken = 1; |
| 86 | } |
| 87 | |
Feng Wu | 959c870 | 2015-06-09 13:20:36 +0800 | [diff] [blame] | 88 | bool irq_remapping_cap(enum irq_remap_cap cap) |
| 89 | { |
| 90 | if (!remap_ops || disable_irq_post) |
Joerg Roedel | 30e9376 | 2015-08-13 11:13:17 +0200 | [diff] [blame] | 91 | return false; |
Feng Wu | 959c870 | 2015-06-09 13:20:36 +0800 | [diff] [blame] | 92 | |
| 93 | return (remap_ops->capability & (1 << cap)); |
| 94 | } |
| 95 | EXPORT_SYMBOL_GPL(irq_remapping_cap); |
| 96 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 97 | int __init irq_remapping_prepare(void) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 98 | { |
Jiang Liu | c392f56 | 2015-01-07 15:31:40 +0800 | [diff] [blame] | 99 | if (disable_irq_remap) |
| 100 | return -ENOSYS; |
| 101 | |
Jiang Liu | 30969e3 | 2015-01-07 15:31:41 +0800 | [diff] [blame] | 102 | if (intel_irq_remap_ops.prepare() == 0) |
| 103 | remap_ops = &intel_irq_remap_ops; |
| 104 | else if (IS_ENABLED(CONFIG_AMD_IOMMU) && |
| 105 | amd_iommu_irq_ops.prepare() == 0) |
Thomas Gleixner | a1dafe8 | 2015-01-07 15:31:28 +0800 | [diff] [blame] | 106 | remap_ops = &amd_iommu_irq_ops; |
Jiang Liu | 30969e3 | 2015-01-07 15:31:41 +0800 | [diff] [blame] | 107 | else |
| 108 | return -ENOSYS; |
| 109 | |
| 110 | return 0; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 113 | int __init irq_remapping_enable(void) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 114 | { |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 115 | int ret; |
| 116 | |
Jiang Liu | e901176 | 2015-01-07 15:31:43 +0800 | [diff] [blame] | 117 | if (!remap_ops->enable) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 118 | return -ENODEV; |
| 119 | |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 120 | ret = remap_ops->enable(); |
| 121 | |
| 122 | if (irq_remapping_enabled) |
| 123 | irq_remapping_modify_x86_ops(); |
| 124 | |
| 125 | return ret; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 126 | } |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 127 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 128 | void irq_remapping_disable(void) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 129 | { |
Jiang Liu | e901176 | 2015-01-07 15:31:43 +0800 | [diff] [blame] | 130 | if (irq_remapping_enabled && remap_ops->disable) |
| 131 | remap_ops->disable(); |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 134 | int irq_remapping_reenable(int mode) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 135 | { |
Jiang Liu | e901176 | 2015-01-07 15:31:43 +0800 | [diff] [blame] | 136 | if (irq_remapping_enabled && remap_ops->reenable) |
| 137 | return remap_ops->reenable(mode); |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 138 | |
Jiang Liu | e901176 | 2015-01-07 15:31:43 +0800 | [diff] [blame] | 139 | return 0; |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 142 | int __init irq_remap_enable_fault_handling(void) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 143 | { |
Joerg Roedel | 70733e0 | 2012-09-26 12:44:33 +0200 | [diff] [blame] | 144 | if (!irq_remapping_enabled) |
| 145 | return 0; |
| 146 | |
Jiang Liu | e901176 | 2015-01-07 15:31:43 +0800 | [diff] [blame] | 147 | if (!remap_ops->enable_faulting) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 148 | return -ENODEV; |
| 149 | |
| 150 | return remap_ops->enable_faulting(); |
| 151 | } |
Joerg Roedel | 0c3f173 | 2012-03-30 11:47:02 -0700 | [diff] [blame] | 152 | |
Joerg Roedel | 6a9f5de | 2012-09-26 12:44:41 +0200 | [diff] [blame] | 153 | void panic_if_irq_remap(const char *msg) |
| 154 | { |
| 155 | if (irq_remapping_enabled) |
| 156 | panic(msg); |
| 157 | } |
Joerg Roedel | 9b1b0e4 | 2012-09-26 12:44:45 +0200 | [diff] [blame] | 158 | |
Jiang Liu | 947045a | 2015-04-13 14:11:30 +0800 | [diff] [blame] | 159 | void ir_ack_apic_edge(struct irq_data *data) |
Joerg Roedel | 9b1b0e4 | 2012-09-26 12:44:45 +0200 | [diff] [blame] | 160 | { |
| 161 | ack_APIC_irq(); |
| 162 | } |
| 163 | |
Jiang Liu | 947045a | 2015-04-13 14:11:30 +0800 | [diff] [blame] | 164 | /** |
| 165 | * irq_remapping_get_ir_irq_domain - Get the irqdomain associated with the IOMMU |
| 166 | * device serving request @info |
| 167 | * @info: interrupt allocation information, used to identify the IOMMU device |
| 168 | * |
| 169 | * It's used to get parent irqdomain for HPET and IOAPIC irqdomains. |
| 170 | * Returns pointer to IRQ domain, or NULL on failure. |
| 171 | */ |
| 172 | struct irq_domain * |
| 173 | irq_remapping_get_ir_irq_domain(struct irq_alloc_info *info) |
| 174 | { |
| 175 | if (!remap_ops || !remap_ops->get_ir_irq_domain) |
| 176 | return NULL; |
| 177 | |
| 178 | return remap_ops->get_ir_irq_domain(info); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * irq_remapping_get_irq_domain - Get the irqdomain serving the request @info |
| 183 | * @info: interrupt allocation information, used to identify the IOMMU device |
| 184 | * |
| 185 | * There will be one PCI MSI/MSIX irqdomain associated with each interrupt |
| 186 | * remapping device, so this interface is used to retrieve the PCI MSI/MSIX |
| 187 | * irqdomain serving request @info. |
| 188 | * Returns pointer to IRQ domain, or NULL on failure. |
| 189 | */ |
| 190 | struct irq_domain * |
| 191 | irq_remapping_get_irq_domain(struct irq_alloc_info *info) |
| 192 | { |
| 193 | if (!remap_ops || !remap_ops->get_irq_domain) |
| 194 | return NULL; |
| 195 | |
| 196 | return remap_ops->get_irq_domain(info); |
| 197 | } |