Yinghai Lu | 5aeecaf | 2008-08-19 20:49:59 -0700 | [diff] [blame] | 1 | #include <linux/interrupt.h> |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 2 | #include <linux/dmar.h> |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 3 | #include <linux/spinlock.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 4 | #include <linux/slab.h> |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 5 | #include <linux/jiffies.h> |
Suresh Siddha | 20f3097 | 2009-08-04 12:07:08 -0700 | [diff] [blame] | 6 | #include <linux/hpet.h> |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 7 | #include <linux/pci.h> |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 8 | #include <linux/irq.h> |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 9 | #include <asm/io_apic.h> |
Yinghai Lu | 17483a1 | 2008-12-12 13:14:18 -0800 | [diff] [blame] | 10 | #include <asm/smp.h> |
Jaswinder Singh Rajput | 6d652ea | 2009-01-07 21:38:59 +0530 | [diff] [blame] | 11 | #include <asm/cpu.h> |
Kay, Allen M | 3871794 | 2008-09-09 18:37:29 +0300 | [diff] [blame] | 12 | #include <linux/intel-iommu.h> |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 13 | #include "intr_remapping.h" |
Alexander Beregalov | 46f06b7 | 2009-04-06 16:45:28 +0100 | [diff] [blame] | 14 | #include <acpi/acpi.h> |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 15 | #include <asm/pci-direct.h> |
| 16 | #include "pci.h" |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 17 | |
| 18 | static struct ioapic_scope ir_ioapic[MAX_IO_APICS]; |
Suresh Siddha | 20f3097 | 2009-08-04 12:07:08 -0700 | [diff] [blame] | 19 | static struct hpet_scope ir_hpet[MAX_HPET_TBS]; |
| 20 | static int ir_ioapic_num, ir_hpet_num; |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 21 | int intr_remapping_enabled; |
| 22 | |
Weidong Han | 03ea815 | 2009-04-17 16:42:15 +0800 | [diff] [blame] | 23 | static int disable_intremap; |
Chris Wright | d1423d5 | 2010-07-20 11:06:49 -0700 | [diff] [blame] | 24 | static int disable_sourceid_checking; |
| 25 | |
Weidong Han | 03ea815 | 2009-04-17 16:42:15 +0800 | [diff] [blame] | 26 | static __init int setup_nointremap(char *str) |
| 27 | { |
| 28 | disable_intremap = 1; |
| 29 | return 0; |
| 30 | } |
| 31 | early_param("nointremap", setup_nointremap); |
| 32 | |
Chris Wright | d1423d5 | 2010-07-20 11:06:49 -0700 | [diff] [blame] | 33 | static __init int setup_intremap(char *str) |
| 34 | { |
| 35 | if (!str) |
| 36 | return -EINVAL; |
| 37 | |
| 38 | if (!strncmp(str, "on", 2)) |
| 39 | disable_intremap = 0; |
| 40 | else if (!strncmp(str, "off", 3)) |
| 41 | disable_intremap = 1; |
| 42 | else if (!strncmp(str, "nosid", 5)) |
| 43 | disable_sourceid_checking = 1; |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | early_param("intremap", setup_intremap); |
| 48 | |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 49 | static DEFINE_SPINLOCK(irq_2_ir_lock); |
| 50 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 51 | static struct irq_2_iommu *irq_2_iommu(unsigned int irq) |
| 52 | { |
Thomas Gleixner | dced35a | 2011-03-28 17:49:12 +0200 | [diff] [blame] | 53 | struct irq_cfg *cfg = irq_get_chip_data(irq); |
Thomas Gleixner | 349d676 | 2010-10-10 12:29:27 +0200 | [diff] [blame] | 54 | return cfg ? &cfg->irq_2_iommu : NULL; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 57 | int get_irte(int irq, struct irte *entry) |
| 58 | { |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 59 | struct irq_2_iommu *irq_iommu = irq_2_iommu(irq); |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 60 | unsigned long flags; |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 61 | int index; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 62 | |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 63 | if (!entry || !irq_iommu) |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 64 | return -1; |
| 65 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 66 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 67 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 68 | index = irq_iommu->irte_index + irq_iommu->sub_handle; |
| 69 | *entry = *(irq_iommu->iommu->ir_table->base + index); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 70 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 71 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | int alloc_irte(struct intel_iommu *iommu, int irq, u16 count) |
| 76 | { |
| 77 | struct ir_table *table = iommu->ir_table; |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 78 | struct irq_2_iommu *irq_iommu = irq_2_iommu(irq); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 79 | u16 index, start_index; |
| 80 | unsigned int mask = 0; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 81 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 82 | int i; |
| 83 | |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 84 | if (!count || !irq_iommu) |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 85 | return -1; |
| 86 | |
| 87 | /* |
| 88 | * start the IRTE search from index 0. |
| 89 | */ |
| 90 | index = start_index = 0; |
| 91 | |
| 92 | if (count > 1) { |
| 93 | count = __roundup_pow_of_two(count); |
| 94 | mask = ilog2(count); |
| 95 | } |
| 96 | |
| 97 | if (mask > ecap_max_handle_mask(iommu->ecap)) { |
| 98 | printk(KERN_ERR |
| 99 | "Requested mask %x exceeds the max invalidation handle" |
| 100 | " mask value %Lx\n", mask, |
| 101 | ecap_max_handle_mask(iommu->ecap)); |
| 102 | return -1; |
| 103 | } |
| 104 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 105 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 106 | do { |
| 107 | for (i = index; i < index + count; i++) |
| 108 | if (table->base[i].present) |
| 109 | break; |
| 110 | /* empty index found */ |
| 111 | if (i == index + count) |
| 112 | break; |
| 113 | |
| 114 | index = (index + count) % INTR_REMAP_TABLE_ENTRIES; |
| 115 | |
| 116 | if (index == start_index) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 117 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 118 | printk(KERN_ERR "can't allocate an IRTE\n"); |
| 119 | return -1; |
| 120 | } |
| 121 | } while (1); |
| 122 | |
| 123 | for (i = index; i < index + count; i++) |
| 124 | table->base[i].present = 1; |
| 125 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 126 | irq_iommu->iommu = iommu; |
| 127 | irq_iommu->irte_index = index; |
| 128 | irq_iommu->sub_handle = 0; |
| 129 | irq_iommu->irte_mask = mask; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 130 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 131 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 132 | |
| 133 | return index; |
| 134 | } |
| 135 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 136 | static int qi_flush_iec(struct intel_iommu *iommu, int index, int mask) |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 137 | { |
| 138 | struct qi_desc desc; |
| 139 | |
| 140 | desc.low = QI_IEC_IIDEX(index) | QI_IEC_TYPE | QI_IEC_IM(mask) |
| 141 | | QI_IEC_SELECTIVE; |
| 142 | desc.high = 0; |
| 143 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 144 | return qi_submit_sync(&desc, iommu); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | int map_irq_to_irte_handle(int irq, u16 *sub_handle) |
| 148 | { |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 149 | struct irq_2_iommu *irq_iommu = irq_2_iommu(irq); |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 150 | unsigned long flags; |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 151 | int index; |
| 152 | |
| 153 | if (!irq_iommu) |
| 154 | return -1; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 155 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 156 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 157 | *sub_handle = irq_iommu->sub_handle; |
| 158 | index = irq_iommu->irte_index; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 159 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 160 | return index; |
| 161 | } |
| 162 | |
| 163 | int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle) |
| 164 | { |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 165 | struct irq_2_iommu *irq_iommu = irq_2_iommu(irq); |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 166 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 167 | |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 168 | if (!irq_iommu) |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 169 | return -1; |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 170 | |
| 171 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 172 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 173 | irq_iommu->iommu = iommu; |
| 174 | irq_iommu->irte_index = index; |
| 175 | irq_iommu->sub_handle = subhandle; |
| 176 | irq_iommu->irte_mask = 0; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 177 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 178 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 183 | int modify_irte(int irq, struct irte *irte_modified) |
| 184 | { |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 185 | struct irq_2_iommu *irq_iommu = irq_2_iommu(irq); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 186 | struct intel_iommu *iommu; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 187 | unsigned long flags; |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 188 | struct irte *irte; |
| 189 | int rc, index; |
| 190 | |
| 191 | if (!irq_iommu) |
| 192 | return -1; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 193 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 194 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 195 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 196 | iommu = irq_iommu->iommu; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 197 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 198 | index = irq_iommu->irte_index + irq_iommu->sub_handle; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 199 | irte = &iommu->ir_table->base[index]; |
| 200 | |
Linus Torvalds | c513b67 | 2010-08-06 11:02:31 -0700 | [diff] [blame] | 201 | set_64bit(&irte->low, irte_modified->low); |
| 202 | set_64bit(&irte->high, irte_modified->high); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 203 | __iommu_flush_cache(iommu, irte, sizeof(*irte)); |
| 204 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 205 | rc = qi_flush_iec(iommu, index, 0); |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 206 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 207 | |
| 208 | return rc; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Suresh Siddha | 20f3097 | 2009-08-04 12:07:08 -0700 | [diff] [blame] | 211 | struct intel_iommu *map_hpet_to_ir(u8 hpet_id) |
| 212 | { |
| 213 | int i; |
| 214 | |
| 215 | for (i = 0; i < MAX_HPET_TBS; i++) |
| 216 | if (ir_hpet[i].id == hpet_id) |
| 217 | return ir_hpet[i].iommu; |
| 218 | return NULL; |
| 219 | } |
| 220 | |
Suresh Siddha | 89027d3 | 2008-07-10 11:16:56 -0700 | [diff] [blame] | 221 | struct intel_iommu *map_ioapic_to_ir(int apic) |
| 222 | { |
| 223 | int i; |
| 224 | |
| 225 | for (i = 0; i < MAX_IO_APICS; i++) |
| 226 | if (ir_ioapic[i].id == apic) |
| 227 | return ir_ioapic[i].iommu; |
| 228 | return NULL; |
| 229 | } |
| 230 | |
Suresh Siddha | 75c46fa | 2008-07-10 11:16:57 -0700 | [diff] [blame] | 231 | struct intel_iommu *map_dev_to_ir(struct pci_dev *dev) |
| 232 | { |
| 233 | struct dmar_drhd_unit *drhd; |
| 234 | |
| 235 | drhd = dmar_find_matched_drhd_unit(dev); |
| 236 | if (!drhd) |
| 237 | return NULL; |
| 238 | |
| 239 | return drhd->iommu; |
| 240 | } |
| 241 | |
Weidong Han | c4658b4 | 2009-05-23 00:41:14 +0800 | [diff] [blame] | 242 | static int clear_entries(struct irq_2_iommu *irq_iommu) |
| 243 | { |
| 244 | struct irte *start, *entry, *end; |
| 245 | struct intel_iommu *iommu; |
| 246 | int index; |
| 247 | |
| 248 | if (irq_iommu->sub_handle) |
| 249 | return 0; |
| 250 | |
| 251 | iommu = irq_iommu->iommu; |
| 252 | index = irq_iommu->irte_index + irq_iommu->sub_handle; |
| 253 | |
| 254 | start = iommu->ir_table->base + index; |
| 255 | end = start + (1 << irq_iommu->irte_mask); |
| 256 | |
| 257 | for (entry = start; entry < end; entry++) { |
Linus Torvalds | c513b67 | 2010-08-06 11:02:31 -0700 | [diff] [blame] | 258 | set_64bit(&entry->low, 0); |
| 259 | set_64bit(&entry->high, 0); |
Weidong Han | c4658b4 | 2009-05-23 00:41:14 +0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | return qi_flush_iec(iommu, index, irq_iommu->irte_mask); |
| 263 | } |
| 264 | |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 265 | int free_irte(int irq) |
| 266 | { |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 267 | struct irq_2_iommu *irq_iommu = irq_2_iommu(irq); |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 268 | unsigned long flags; |
Thomas Gleixner | d585d06 | 2010-10-10 12:34:27 +0200 | [diff] [blame] | 269 | int rc; |
| 270 | |
| 271 | if (!irq_iommu) |
| 272 | return -1; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 273 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 274 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 275 | |
Weidong Han | c4658b4 | 2009-05-23 00:41:14 +0800 | [diff] [blame] | 276 | rc = clear_entries(irq_iommu); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 277 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 278 | irq_iommu->iommu = NULL; |
| 279 | irq_iommu->irte_index = 0; |
| 280 | irq_iommu->sub_handle = 0; |
| 281 | irq_iommu->irte_mask = 0; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 282 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 283 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 284 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 285 | return rc; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 288 | /* |
| 289 | * source validation type |
| 290 | */ |
| 291 | #define SVT_NO_VERIFY 0x0 /* no verification is required */ |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 292 | #define SVT_VERIFY_SID_SQ 0x1 /* verify using SID and SQ fields */ |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 293 | #define SVT_VERIFY_BUS 0x2 /* verify bus of request-id */ |
| 294 | |
| 295 | /* |
| 296 | * source-id qualifier |
| 297 | */ |
| 298 | #define SQ_ALL_16 0x0 /* verify all 16 bits of request-id */ |
| 299 | #define SQ_13_IGNORE_1 0x1 /* verify most significant 13 bits, ignore |
| 300 | * the third least significant bit |
| 301 | */ |
| 302 | #define SQ_13_IGNORE_2 0x2 /* verify most significant 13 bits, ignore |
| 303 | * the second and third least significant bits |
| 304 | */ |
| 305 | #define SQ_13_IGNORE_3 0x3 /* verify most significant 13 bits, ignore |
| 306 | * the least three significant bits |
| 307 | */ |
| 308 | |
| 309 | /* |
| 310 | * set SVT, SQ and SID fields of irte to verify |
| 311 | * source ids of interrupt requests |
| 312 | */ |
| 313 | static void set_irte_sid(struct irte *irte, unsigned int svt, |
| 314 | unsigned int sq, unsigned int sid) |
| 315 | { |
Chris Wright | d1423d5 | 2010-07-20 11:06:49 -0700 | [diff] [blame] | 316 | if (disable_sourceid_checking) |
| 317 | svt = SVT_NO_VERIFY; |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 318 | irte->svt = svt; |
| 319 | irte->sq = sq; |
| 320 | irte->sid = sid; |
| 321 | } |
| 322 | |
| 323 | int set_ioapic_sid(struct irte *irte, int apic) |
| 324 | { |
| 325 | int i; |
| 326 | u16 sid = 0; |
| 327 | |
| 328 | if (!irte) |
| 329 | return -1; |
| 330 | |
| 331 | for (i = 0; i < MAX_IO_APICS; i++) { |
| 332 | if (ir_ioapic[i].id == apic) { |
| 333 | sid = (ir_ioapic[i].bus << 8) | ir_ioapic[i].devfn; |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if (sid == 0) { |
| 339 | pr_warning("Failed to set source-id of IOAPIC (%d)\n", apic); |
| 340 | return -1; |
| 341 | } |
| 342 | |
| 343 | set_irte_sid(irte, 1, 0, sid); |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
Suresh Siddha | 20f3097 | 2009-08-04 12:07:08 -0700 | [diff] [blame] | 348 | int set_hpet_sid(struct irte *irte, u8 id) |
| 349 | { |
| 350 | int i; |
| 351 | u16 sid = 0; |
| 352 | |
| 353 | if (!irte) |
| 354 | return -1; |
| 355 | |
| 356 | for (i = 0; i < MAX_HPET_TBS; i++) { |
| 357 | if (ir_hpet[i].id == id) { |
| 358 | sid = (ir_hpet[i].bus << 8) | ir_hpet[i].devfn; |
| 359 | break; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if (sid == 0) { |
| 364 | pr_warning("Failed to set source-id of HPET block (%d)\n", id); |
| 365 | return -1; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Should really use SQ_ALL_16. Some platforms are broken. |
| 370 | * While we figure out the right quirks for these broken platforms, use |
| 371 | * SQ_13_IGNORE_3 for now. |
| 372 | */ |
| 373 | set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_13_IGNORE_3, sid); |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 378 | int set_msi_sid(struct irte *irte, struct pci_dev *dev) |
| 379 | { |
| 380 | struct pci_dev *bridge; |
| 381 | |
| 382 | if (!irte || !dev) |
| 383 | return -1; |
| 384 | |
| 385 | /* PCIe device or Root Complex integrated PCI device */ |
Kenji Kaneshige | 5f4d91a | 2009-11-11 14:36:17 +0900 | [diff] [blame] | 386 | if (pci_is_pcie(dev) || !dev->bus->parent) { |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 387 | set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_ALL_16, |
| 388 | (dev->bus->number << 8) | dev->devfn); |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | bridge = pci_find_upstream_pcie_bridge(dev); |
| 393 | if (bridge) { |
Stefan Assmann | 45e829e | 2009-12-03 06:49:24 -0500 | [diff] [blame] | 394 | if (pci_is_pcie(bridge))/* this is a PCIe-to-PCI/PCIX bridge */ |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 395 | set_irte_sid(irte, SVT_VERIFY_BUS, SQ_ALL_16, |
| 396 | (bridge->bus->number << 8) | dev->bus->number); |
| 397 | else /* this is a legacy PCI bridge */ |
| 398 | set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_ALL_16, |
| 399 | (bridge->bus->number << 8) | bridge->devfn); |
| 400 | } |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 405 | static void iommu_set_intr_remapping(struct intel_iommu *iommu, int mode) |
| 406 | { |
| 407 | u64 addr; |
David Woodhouse | c416daa | 2009-05-10 20:30:58 +0100 | [diff] [blame] | 408 | u32 sts; |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 409 | unsigned long flags; |
| 410 | |
| 411 | addr = virt_to_phys((void *)iommu->ir_table->base); |
| 412 | |
| 413 | spin_lock_irqsave(&iommu->register_lock, flags); |
| 414 | |
| 415 | dmar_writeq(iommu->reg + DMAR_IRTA_REG, |
| 416 | (addr) | IR_X2APIC_MODE(mode) | INTR_REMAP_TABLE_REG_SIZE); |
| 417 | |
| 418 | /* Set interrupt-remapping table pointer */ |
Han, Weidong | 161fde0 | 2009-04-03 17:15:47 +0800 | [diff] [blame] | 419 | iommu->gcmd |= DMA_GCMD_SIRTP; |
David Woodhouse | c416daa | 2009-05-10 20:30:58 +0100 | [diff] [blame] | 420 | writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG); |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 421 | |
| 422 | IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, |
| 423 | readl, (sts & DMA_GSTS_IRTPS), sts); |
| 424 | spin_unlock_irqrestore(&iommu->register_lock, flags); |
| 425 | |
| 426 | /* |
| 427 | * global invalidation of interrupt entry cache before enabling |
| 428 | * interrupt-remapping. |
| 429 | */ |
| 430 | qi_global_iec(iommu); |
| 431 | |
| 432 | spin_lock_irqsave(&iommu->register_lock, flags); |
| 433 | |
| 434 | /* Enable interrupt-remapping */ |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 435 | iommu->gcmd |= DMA_GCMD_IRE; |
David Woodhouse | c416daa | 2009-05-10 20:30:58 +0100 | [diff] [blame] | 436 | writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG); |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 437 | |
| 438 | IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, |
| 439 | readl, (sts & DMA_GSTS_IRES), sts); |
| 440 | |
| 441 | spin_unlock_irqrestore(&iommu->register_lock, flags); |
| 442 | } |
| 443 | |
| 444 | |
| 445 | static int setup_intr_remapping(struct intel_iommu *iommu, int mode) |
| 446 | { |
| 447 | struct ir_table *ir_table; |
| 448 | struct page *pages; |
| 449 | |
| 450 | ir_table = iommu->ir_table = kzalloc(sizeof(struct ir_table), |
Suresh Siddha | fa4b57c | 2009-03-16 17:05:05 -0700 | [diff] [blame] | 451 | GFP_ATOMIC); |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 452 | |
| 453 | if (!iommu->ir_table) |
| 454 | return -ENOMEM; |
| 455 | |
Suresh Siddha | 824cd75 | 2009-10-02 11:01:23 -0700 | [diff] [blame] | 456 | pages = alloc_pages_node(iommu->node, GFP_ATOMIC | __GFP_ZERO, |
| 457 | INTR_REMAP_PAGE_ORDER); |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 458 | |
| 459 | if (!pages) { |
| 460 | printk(KERN_ERR "failed to allocate pages of order %d\n", |
| 461 | INTR_REMAP_PAGE_ORDER); |
| 462 | kfree(iommu->ir_table); |
| 463 | return -ENOMEM; |
| 464 | } |
| 465 | |
| 466 | ir_table->base = page_address(pages); |
| 467 | |
| 468 | iommu_set_intr_remapping(iommu, mode); |
| 469 | return 0; |
| 470 | } |
| 471 | |
Suresh Siddha | eba67e5 | 2009-03-16 17:04:56 -0700 | [diff] [blame] | 472 | /* |
| 473 | * Disable Interrupt Remapping. |
| 474 | */ |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 475 | static void iommu_disable_intr_remapping(struct intel_iommu *iommu) |
Suresh Siddha | eba67e5 | 2009-03-16 17:04:56 -0700 | [diff] [blame] | 476 | { |
| 477 | unsigned long flags; |
| 478 | u32 sts; |
| 479 | |
| 480 | if (!ecap_ir_support(iommu->ecap)) |
| 481 | return; |
| 482 | |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 483 | /* |
| 484 | * global invalidation of interrupt entry cache before disabling |
| 485 | * interrupt-remapping. |
| 486 | */ |
| 487 | qi_global_iec(iommu); |
| 488 | |
Suresh Siddha | eba67e5 | 2009-03-16 17:04:56 -0700 | [diff] [blame] | 489 | spin_lock_irqsave(&iommu->register_lock, flags); |
| 490 | |
| 491 | sts = dmar_readq(iommu->reg + DMAR_GSTS_REG); |
| 492 | if (!(sts & DMA_GSTS_IRES)) |
| 493 | goto end; |
| 494 | |
| 495 | iommu->gcmd &= ~DMA_GCMD_IRE; |
| 496 | writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG); |
| 497 | |
| 498 | IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, |
| 499 | readl, !(sts & DMA_GSTS_IRES), sts); |
| 500 | |
| 501 | end: |
| 502 | spin_unlock_irqrestore(&iommu->register_lock, flags); |
| 503 | } |
| 504 | |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 505 | int __init intr_remapping_supported(void) |
| 506 | { |
| 507 | struct dmar_drhd_unit *drhd; |
| 508 | |
Weidong Han | 03ea815 | 2009-04-17 16:42:15 +0800 | [diff] [blame] | 509 | if (disable_intremap) |
| 510 | return 0; |
| 511 | |
Youquan Song | 074835f | 2009-09-09 12:05:39 -0400 | [diff] [blame] | 512 | if (!dmar_ir_support()) |
| 513 | return 0; |
| 514 | |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 515 | for_each_drhd_unit(drhd) { |
| 516 | struct intel_iommu *iommu = drhd->iommu; |
| 517 | |
| 518 | if (!ecap_ir_support(iommu->ecap)) |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | return 1; |
| 523 | } |
| 524 | |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 525 | int __init enable_intr_remapping(int eim) |
| 526 | { |
| 527 | struct dmar_drhd_unit *drhd; |
| 528 | int setup = 0; |
| 529 | |
Youquan Song | e936d07 | 2009-09-07 10:58:07 -0400 | [diff] [blame] | 530 | if (parse_ioapics_under_ir() != 1) { |
| 531 | printk(KERN_INFO "Not enable interrupt remapping\n"); |
| 532 | return -1; |
| 533 | } |
| 534 | |
Suresh Siddha | 1531a6a | 2009-03-16 17:04:57 -0700 | [diff] [blame] | 535 | for_each_drhd_unit(drhd) { |
| 536 | struct intel_iommu *iommu = drhd->iommu; |
| 537 | |
| 538 | /* |
Han, Weidong | 34aaaa9 | 2009-04-04 17:21:26 +0800 | [diff] [blame] | 539 | * If the queued invalidation is already initialized, |
| 540 | * shouldn't disable it. |
| 541 | */ |
| 542 | if (iommu->qi) |
| 543 | continue; |
| 544 | |
| 545 | /* |
Suresh Siddha | 1531a6a | 2009-03-16 17:04:57 -0700 | [diff] [blame] | 546 | * Clear previous faults. |
| 547 | */ |
| 548 | dmar_fault(-1, iommu); |
| 549 | |
| 550 | /* |
| 551 | * Disable intr remapping and queued invalidation, if already |
| 552 | * enabled prior to OS handover. |
| 553 | */ |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 554 | iommu_disable_intr_remapping(iommu); |
Suresh Siddha | 1531a6a | 2009-03-16 17:04:57 -0700 | [diff] [blame] | 555 | |
| 556 | dmar_disable_qi(iommu); |
| 557 | } |
| 558 | |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 559 | /* |
| 560 | * check for the Interrupt-remapping support |
| 561 | */ |
| 562 | for_each_drhd_unit(drhd) { |
| 563 | struct intel_iommu *iommu = drhd->iommu; |
| 564 | |
| 565 | if (!ecap_ir_support(iommu->ecap)) |
| 566 | continue; |
| 567 | |
| 568 | if (eim && !ecap_eim_support(iommu->ecap)) { |
| 569 | printk(KERN_INFO "DRHD %Lx: EIM not supported by DRHD, " |
| 570 | " ecap %Lx\n", drhd->reg_base_addr, iommu->ecap); |
| 571 | return -1; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | /* |
| 576 | * Enable queued invalidation for all the DRHD's. |
| 577 | */ |
| 578 | for_each_drhd_unit(drhd) { |
| 579 | int ret; |
| 580 | struct intel_iommu *iommu = drhd->iommu; |
| 581 | ret = dmar_enable_qi(iommu); |
| 582 | |
| 583 | if (ret) { |
| 584 | printk(KERN_ERR "DRHD %Lx: failed to enable queued, " |
| 585 | " invalidation, ecap %Lx, ret %d\n", |
| 586 | drhd->reg_base_addr, iommu->ecap, ret); |
| 587 | return -1; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * Setup Interrupt-remapping for all the DRHD's now. |
| 593 | */ |
| 594 | for_each_drhd_unit(drhd) { |
| 595 | struct intel_iommu *iommu = drhd->iommu; |
| 596 | |
| 597 | if (!ecap_ir_support(iommu->ecap)) |
| 598 | continue; |
| 599 | |
| 600 | if (setup_intr_remapping(iommu, eim)) |
| 601 | goto error; |
| 602 | |
| 603 | setup = 1; |
| 604 | } |
| 605 | |
| 606 | if (!setup) |
| 607 | goto error; |
| 608 | |
| 609 | intr_remapping_enabled = 1; |
| 610 | |
| 611 | return 0; |
| 612 | |
| 613 | error: |
| 614 | /* |
| 615 | * handle error condition gracefully here! |
| 616 | */ |
| 617 | return -1; |
| 618 | } |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 619 | |
Suresh Siddha | 20f3097 | 2009-08-04 12:07:08 -0700 | [diff] [blame] | 620 | static void ir_parse_one_hpet_scope(struct acpi_dmar_device_scope *scope, |
| 621 | struct intel_iommu *iommu) |
| 622 | { |
| 623 | struct acpi_dmar_pci_path *path; |
| 624 | u8 bus; |
| 625 | int count; |
| 626 | |
| 627 | bus = scope->bus; |
| 628 | path = (struct acpi_dmar_pci_path *)(scope + 1); |
| 629 | count = (scope->length - sizeof(struct acpi_dmar_device_scope)) |
| 630 | / sizeof(struct acpi_dmar_pci_path); |
| 631 | |
| 632 | while (--count > 0) { |
| 633 | /* |
| 634 | * Access PCI directly due to the PCI |
| 635 | * subsystem isn't initialized yet. |
| 636 | */ |
| 637 | bus = read_pci_config_byte(bus, path->dev, path->fn, |
| 638 | PCI_SECONDARY_BUS); |
| 639 | path++; |
| 640 | } |
| 641 | ir_hpet[ir_hpet_num].bus = bus; |
| 642 | ir_hpet[ir_hpet_num].devfn = PCI_DEVFN(path->dev, path->fn); |
| 643 | ir_hpet[ir_hpet_num].iommu = iommu; |
| 644 | ir_hpet[ir_hpet_num].id = scope->enumeration_id; |
| 645 | ir_hpet_num++; |
| 646 | } |
| 647 | |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 648 | static void ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope, |
| 649 | struct intel_iommu *iommu) |
| 650 | { |
| 651 | struct acpi_dmar_pci_path *path; |
| 652 | u8 bus; |
| 653 | int count; |
| 654 | |
| 655 | bus = scope->bus; |
| 656 | path = (struct acpi_dmar_pci_path *)(scope + 1); |
| 657 | count = (scope->length - sizeof(struct acpi_dmar_device_scope)) |
| 658 | / sizeof(struct acpi_dmar_pci_path); |
| 659 | |
| 660 | while (--count > 0) { |
| 661 | /* |
| 662 | * Access PCI directly due to the PCI |
| 663 | * subsystem isn't initialized yet. |
| 664 | */ |
| 665 | bus = read_pci_config_byte(bus, path->dev, path->fn, |
| 666 | PCI_SECONDARY_BUS); |
| 667 | path++; |
| 668 | } |
| 669 | |
| 670 | ir_ioapic[ir_ioapic_num].bus = bus; |
| 671 | ir_ioapic[ir_ioapic_num].devfn = PCI_DEVFN(path->dev, path->fn); |
| 672 | ir_ioapic[ir_ioapic_num].iommu = iommu; |
| 673 | ir_ioapic[ir_ioapic_num].id = scope->enumeration_id; |
| 674 | ir_ioapic_num++; |
| 675 | } |
| 676 | |
Suresh Siddha | 20f3097 | 2009-08-04 12:07:08 -0700 | [diff] [blame] | 677 | static int ir_parse_ioapic_hpet_scope(struct acpi_dmar_header *header, |
| 678 | struct intel_iommu *iommu) |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 679 | { |
| 680 | struct acpi_dmar_hardware_unit *drhd; |
| 681 | struct acpi_dmar_device_scope *scope; |
| 682 | void *start, *end; |
| 683 | |
| 684 | drhd = (struct acpi_dmar_hardware_unit *)header; |
| 685 | |
| 686 | start = (void *)(drhd + 1); |
| 687 | end = ((void *)drhd) + header->length; |
| 688 | |
| 689 | while (start < end) { |
| 690 | scope = start; |
| 691 | if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_IOAPIC) { |
| 692 | if (ir_ioapic_num == MAX_IO_APICS) { |
| 693 | printk(KERN_WARNING "Exceeded Max IO APICS\n"); |
| 694 | return -1; |
| 695 | } |
| 696 | |
Yinghai Lu | 680a752 | 2010-04-08 19:58:23 +0100 | [diff] [blame] | 697 | printk(KERN_INFO "IOAPIC id %d under DRHD base " |
| 698 | " 0x%Lx IOMMU %d\n", scope->enumeration_id, |
| 699 | drhd->address, iommu->seq_id); |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 700 | |
Weidong Han | f007e99 | 2009-05-23 00:41:15 +0800 | [diff] [blame] | 701 | ir_parse_one_ioapic_scope(scope, iommu); |
Suresh Siddha | 20f3097 | 2009-08-04 12:07:08 -0700 | [diff] [blame] | 702 | } else if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_HPET) { |
| 703 | if (ir_hpet_num == MAX_HPET_TBS) { |
| 704 | printk(KERN_WARNING "Exceeded Max HPET blocks\n"); |
| 705 | return -1; |
| 706 | } |
| 707 | |
| 708 | printk(KERN_INFO "HPET id %d under DRHD base" |
| 709 | " 0x%Lx\n", scope->enumeration_id, |
| 710 | drhd->address); |
| 711 | |
| 712 | ir_parse_one_hpet_scope(scope, iommu); |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 713 | } |
| 714 | start += scope->length; |
| 715 | } |
| 716 | |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | /* |
| 721 | * Finds the assocaition between IOAPIC's and its Interrupt-remapping |
| 722 | * hardware unit. |
| 723 | */ |
| 724 | int __init parse_ioapics_under_ir(void) |
| 725 | { |
| 726 | struct dmar_drhd_unit *drhd; |
| 727 | int ir_supported = 0; |
| 728 | |
| 729 | for_each_drhd_unit(drhd) { |
| 730 | struct intel_iommu *iommu = drhd->iommu; |
| 731 | |
| 732 | if (ecap_ir_support(iommu->ecap)) { |
Suresh Siddha | 20f3097 | 2009-08-04 12:07:08 -0700 | [diff] [blame] | 733 | if (ir_parse_ioapic_hpet_scope(drhd->hdr, iommu)) |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 734 | return -1; |
| 735 | |
| 736 | ir_supported = 1; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | if (ir_supported && ir_ioapic_num != nr_ioapics) { |
| 741 | printk(KERN_WARNING |
| 742 | "Not all IO-APIC's listed under remapping hardware\n"); |
| 743 | return -1; |
| 744 | } |
| 745 | |
| 746 | return ir_supported; |
| 747 | } |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 748 | |
| 749 | void disable_intr_remapping(void) |
| 750 | { |
| 751 | struct dmar_drhd_unit *drhd; |
| 752 | struct intel_iommu *iommu = NULL; |
| 753 | |
| 754 | /* |
| 755 | * Disable Interrupt-remapping for all the DRHD's now. |
| 756 | */ |
| 757 | for_each_iommu(iommu, drhd) { |
| 758 | if (!ecap_ir_support(iommu->ecap)) |
| 759 | continue; |
| 760 | |
| 761 | iommu_disable_intr_remapping(iommu); |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | int reenable_intr_remapping(int eim) |
| 766 | { |
| 767 | struct dmar_drhd_unit *drhd; |
| 768 | int setup = 0; |
| 769 | struct intel_iommu *iommu = NULL; |
| 770 | |
| 771 | for_each_iommu(iommu, drhd) |
| 772 | if (iommu->qi) |
| 773 | dmar_reenable_qi(iommu); |
| 774 | |
| 775 | /* |
| 776 | * Setup Interrupt-remapping for all the DRHD's now. |
| 777 | */ |
| 778 | for_each_iommu(iommu, drhd) { |
| 779 | if (!ecap_ir_support(iommu->ecap)) |
| 780 | continue; |
| 781 | |
| 782 | /* Set up interrupt remapping for iommu.*/ |
| 783 | iommu_set_intr_remapping(iommu, eim); |
| 784 | setup = 1; |
| 785 | } |
| 786 | |
| 787 | if (!setup) |
| 788 | goto error; |
| 789 | |
| 790 | return 0; |
| 791 | |
| 792 | error: |
| 793 | /* |
| 794 | * handle error condition gracefully here! |
| 795 | */ |
| 796 | return -1; |
| 797 | } |
| 798 | |