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> |
| 4 | #include <linux/jiffies.h> |
| 5 | #include <linux/pci.h> |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 6 | #include <linux/irq.h> |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 7 | #include <asm/io_apic.h> |
Yinghai Lu | 17483a1 | 2008-12-12 13:14:18 -0800 | [diff] [blame] | 8 | #include <asm/smp.h> |
Jaswinder Singh Rajput | 6d652ea | 2009-01-07 21:38:59 +0530 | [diff] [blame] | 9 | #include <asm/cpu.h> |
Kay, Allen M | 3871794 | 2008-09-09 18:37:29 +0300 | [diff] [blame] | 10 | #include <linux/intel-iommu.h> |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 11 | #include "intr_remapping.h" |
Alexander Beregalov | 46f06b72 | 2009-04-06 16:45:28 +0100 | [diff] [blame] | 12 | #include <acpi/acpi.h> |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 13 | |
| 14 | static struct ioapic_scope ir_ioapic[MAX_IO_APICS]; |
| 15 | static int ir_ioapic_num; |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 16 | int intr_remapping_enabled; |
| 17 | |
Weidong Han | 03ea815 | 2009-04-17 16:42:15 +0800 | [diff] [blame] | 18 | static int disable_intremap; |
| 19 | static __init int setup_nointremap(char *str) |
| 20 | { |
| 21 | disable_intremap = 1; |
| 22 | return 0; |
| 23 | } |
| 24 | early_param("nointremap", setup_nointremap); |
| 25 | |
Yinghai Lu | 5aeecaf | 2008-08-19 20:49:59 -0700 | [diff] [blame] | 26 | struct irq_2_iommu { |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 27 | struct intel_iommu *iommu; |
| 28 | u16 irte_index; |
| 29 | u16 sub_handle; |
| 30 | u8 irte_mask; |
Yinghai Lu | 5aeecaf | 2008-08-19 20:49:59 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
Yinghai Lu | d7e51e6 | 2009-01-07 15:03:13 -0800 | [diff] [blame] | 33 | #ifdef CONFIG_GENERIC_HARDIRQS |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 34 | static struct irq_2_iommu *get_one_free_irq_2_iommu(int node) |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 35 | { |
| 36 | struct irq_2_iommu *iommu; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 37 | |
| 38 | iommu = kzalloc_node(sizeof(*iommu), GFP_ATOMIC, node); |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 39 | printk(KERN_DEBUG "alloc irq_2_iommu on node %d\n", node); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 40 | |
| 41 | return iommu; |
| 42 | } |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 43 | |
| 44 | static struct irq_2_iommu *irq_2_iommu(unsigned int irq) |
| 45 | { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 46 | struct irq_desc *desc; |
| 47 | |
| 48 | desc = irq_to_desc(irq); |
| 49 | |
| 50 | if (WARN_ON_ONCE(!desc)) |
| 51 | return NULL; |
| 52 | |
| 53 | return desc->irq_2_iommu; |
| 54 | } |
| 55 | |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 56 | static struct irq_2_iommu *irq_2_iommu_alloc_node(unsigned int irq, int node) |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 57 | { |
| 58 | struct irq_desc *desc; |
| 59 | struct irq_2_iommu *irq_iommu; |
| 60 | |
| 61 | /* |
| 62 | * alloc irq desc if not allocated already. |
| 63 | */ |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 64 | desc = irq_to_desc_alloc_node(irq, node); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 65 | if (!desc) { |
| 66 | printk(KERN_INFO "can not get irq_desc for %d\n", irq); |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | irq_iommu = desc->irq_2_iommu; |
| 71 | |
| 72 | if (!irq_iommu) |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 73 | desc->irq_2_iommu = get_one_free_irq_2_iommu(node); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 74 | |
| 75 | return desc->irq_2_iommu; |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 76 | } |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 77 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 78 | static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq) |
| 79 | { |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 80 | return irq_2_iommu_alloc_node(irq, cpu_to_node(boot_cpu_id)); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | #else /* !CONFIG_SPARSE_IRQ */ |
| 84 | |
| 85 | static struct irq_2_iommu irq_2_iommuX[NR_IRQS]; |
| 86 | |
| 87 | static struct irq_2_iommu *irq_2_iommu(unsigned int irq) |
| 88 | { |
| 89 | if (irq < nr_irqs) |
| 90 | return &irq_2_iommuX[irq]; |
| 91 | |
| 92 | return NULL; |
| 93 | } |
| 94 | static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq) |
| 95 | { |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 96 | return irq_2_iommu(irq); |
| 97 | } |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 98 | #endif |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 99 | |
| 100 | static DEFINE_SPINLOCK(irq_2_ir_lock); |
| 101 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 102 | static struct irq_2_iommu *valid_irq_2_iommu(unsigned int irq) |
| 103 | { |
| 104 | struct irq_2_iommu *irq_iommu; |
| 105 | |
| 106 | irq_iommu = irq_2_iommu(irq); |
| 107 | |
| 108 | if (!irq_iommu) |
| 109 | return NULL; |
| 110 | |
| 111 | if (!irq_iommu->iommu) |
| 112 | return NULL; |
| 113 | |
| 114 | return irq_iommu; |
| 115 | } |
| 116 | |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 117 | int irq_remapped(int irq) |
| 118 | { |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 119 | return valid_irq_2_iommu(irq) != NULL; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | int get_irte(int irq, struct irte *entry) |
| 123 | { |
| 124 | int index; |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 125 | struct irq_2_iommu *irq_iommu; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 126 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 127 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 128 | if (!entry) |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 129 | return -1; |
| 130 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 131 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 132 | irq_iommu = valid_irq_2_iommu(irq); |
| 133 | if (!irq_iommu) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 134 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 135 | return -1; |
| 136 | } |
| 137 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 138 | index = irq_iommu->irte_index + irq_iommu->sub_handle; |
| 139 | *entry = *(irq_iommu->iommu->ir_table->base + index); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 140 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 141 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | int alloc_irte(struct intel_iommu *iommu, int irq, u16 count) |
| 146 | { |
| 147 | struct ir_table *table = iommu->ir_table; |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 148 | struct irq_2_iommu *irq_iommu; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 149 | u16 index, start_index; |
| 150 | unsigned int mask = 0; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 151 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 152 | int i; |
| 153 | |
| 154 | if (!count) |
| 155 | return -1; |
| 156 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 157 | #ifndef CONFIG_SPARSE_IRQ |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 158 | /* protect irq_2_iommu_alloc later */ |
| 159 | if (irq >= nr_irqs) |
| 160 | return -1; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 161 | #endif |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 162 | |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 163 | /* |
| 164 | * start the IRTE search from index 0. |
| 165 | */ |
| 166 | index = start_index = 0; |
| 167 | |
| 168 | if (count > 1) { |
| 169 | count = __roundup_pow_of_two(count); |
| 170 | mask = ilog2(count); |
| 171 | } |
| 172 | |
| 173 | if (mask > ecap_max_handle_mask(iommu->ecap)) { |
| 174 | printk(KERN_ERR |
| 175 | "Requested mask %x exceeds the max invalidation handle" |
| 176 | " mask value %Lx\n", mask, |
| 177 | ecap_max_handle_mask(iommu->ecap)); |
| 178 | return -1; |
| 179 | } |
| 180 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 181 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 182 | do { |
| 183 | for (i = index; i < index + count; i++) |
| 184 | if (table->base[i].present) |
| 185 | break; |
| 186 | /* empty index found */ |
| 187 | if (i == index + count) |
| 188 | break; |
| 189 | |
| 190 | index = (index + count) % INTR_REMAP_TABLE_ENTRIES; |
| 191 | |
| 192 | if (index == start_index) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 193 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 194 | printk(KERN_ERR "can't allocate an IRTE\n"); |
| 195 | return -1; |
| 196 | } |
| 197 | } while (1); |
| 198 | |
| 199 | for (i = index; i < index + count; i++) |
| 200 | table->base[i].present = 1; |
| 201 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 202 | irq_iommu = irq_2_iommu_alloc(irq); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 203 | if (!irq_iommu) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 204 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 205 | printk(KERN_ERR "can't allocate irq_2_iommu\n"); |
| 206 | return -1; |
| 207 | } |
| 208 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 209 | irq_iommu->iommu = iommu; |
| 210 | irq_iommu->irte_index = index; |
| 211 | irq_iommu->sub_handle = 0; |
| 212 | irq_iommu->irte_mask = mask; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 213 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 214 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 215 | |
| 216 | return index; |
| 217 | } |
| 218 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 219 | 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] | 220 | { |
| 221 | struct qi_desc desc; |
| 222 | |
| 223 | desc.low = QI_IEC_IIDEX(index) | QI_IEC_TYPE | QI_IEC_IM(mask) |
| 224 | | QI_IEC_SELECTIVE; |
| 225 | desc.high = 0; |
| 226 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 227 | return qi_submit_sync(&desc, iommu); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | int map_irq_to_irte_handle(int irq, u16 *sub_handle) |
| 231 | { |
| 232 | int index; |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 233 | struct irq_2_iommu *irq_iommu; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 234 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 235 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 236 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 237 | irq_iommu = valid_irq_2_iommu(irq); |
| 238 | if (!irq_iommu) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 239 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 240 | return -1; |
| 241 | } |
| 242 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 243 | *sub_handle = irq_iommu->sub_handle; |
| 244 | index = irq_iommu->irte_index; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 245 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 246 | return index; |
| 247 | } |
| 248 | |
| 249 | int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle) |
| 250 | { |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 251 | struct irq_2_iommu *irq_iommu; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 252 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 253 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 254 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Suresh Siddha | 7ddfb65 | 2008-08-20 17:22:51 -0700 | [diff] [blame] | 255 | |
| 256 | irq_iommu = irq_2_iommu_alloc(irq); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 257 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 258 | if (!irq_iommu) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 259 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 260 | printk(KERN_ERR "can't allocate irq_2_iommu\n"); |
| 261 | return -1; |
| 262 | } |
| 263 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 264 | irq_iommu->iommu = iommu; |
| 265 | irq_iommu->irte_index = index; |
| 266 | irq_iommu->sub_handle = subhandle; |
| 267 | irq_iommu->irte_mask = 0; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 268 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 269 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 270 | |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | int clear_irte_irq(int irq, struct intel_iommu *iommu, u16 index) |
| 275 | { |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 276 | struct irq_2_iommu *irq_iommu; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 277 | unsigned long flags; |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 278 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 279 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 280 | irq_iommu = valid_irq_2_iommu(irq); |
| 281 | if (!irq_iommu) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 282 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 283 | return -1; |
| 284 | } |
| 285 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 286 | irq_iommu->iommu = NULL; |
| 287 | irq_iommu->irte_index = 0; |
| 288 | irq_iommu->sub_handle = 0; |
| 289 | irq_2_iommu(irq)->irte_mask = 0; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 290 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 291 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | int modify_irte(int irq, struct irte *irte_modified) |
| 297 | { |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 298 | int rc; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 299 | int index; |
| 300 | struct irte *irte; |
| 301 | struct intel_iommu *iommu; |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 302 | struct irq_2_iommu *irq_iommu; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 303 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 304 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 305 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 306 | irq_iommu = valid_irq_2_iommu(irq); |
| 307 | if (!irq_iommu) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 308 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 309 | return -1; |
| 310 | } |
| 311 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 312 | iommu = irq_iommu->iommu; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 313 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 314 | index = irq_iommu->irte_index + irq_iommu->sub_handle; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 315 | irte = &iommu->ir_table->base[index]; |
| 316 | |
Suresh Siddha | 9d783ba | 2009-03-16 17:04:55 -0700 | [diff] [blame] | 317 | set_64bit((unsigned long *)irte, irte_modified->low); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 318 | __iommu_flush_cache(iommu, irte, sizeof(*irte)); |
| 319 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 320 | rc = qi_flush_iec(iommu, index, 0); |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 321 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 322 | |
| 323 | return rc; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | int flush_irte(int irq) |
| 327 | { |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 328 | int rc; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 329 | int index; |
| 330 | struct intel_iommu *iommu; |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 331 | struct irq_2_iommu *irq_iommu; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 332 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 333 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 334 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 335 | irq_iommu = valid_irq_2_iommu(irq); |
| 336 | if (!irq_iommu) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 337 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 338 | return -1; |
| 339 | } |
| 340 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 341 | iommu = irq_iommu->iommu; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 342 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 343 | index = irq_iommu->irte_index + irq_iommu->sub_handle; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 344 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 345 | rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask); |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 346 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 347 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 348 | return rc; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Suresh Siddha | 89027d3 | 2008-07-10 11:16:56 -0700 | [diff] [blame] | 351 | struct intel_iommu *map_ioapic_to_ir(int apic) |
| 352 | { |
| 353 | int i; |
| 354 | |
| 355 | for (i = 0; i < MAX_IO_APICS; i++) |
| 356 | if (ir_ioapic[i].id == apic) |
| 357 | return ir_ioapic[i].iommu; |
| 358 | return NULL; |
| 359 | } |
| 360 | |
Suresh Siddha | 75c46fa | 2008-07-10 11:16:57 -0700 | [diff] [blame] | 361 | struct intel_iommu *map_dev_to_ir(struct pci_dev *dev) |
| 362 | { |
| 363 | struct dmar_drhd_unit *drhd; |
| 364 | |
| 365 | drhd = dmar_find_matched_drhd_unit(dev); |
| 366 | if (!drhd) |
| 367 | return NULL; |
| 368 | |
| 369 | return drhd->iommu; |
| 370 | } |
| 371 | |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 372 | int free_irte(int irq) |
| 373 | { |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 374 | int rc = 0; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 375 | int index, i; |
| 376 | struct irte *irte; |
| 377 | struct intel_iommu *iommu; |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 378 | struct irq_2_iommu *irq_iommu; |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 379 | unsigned long flags; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 380 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 381 | spin_lock_irqsave(&irq_2_ir_lock, flags); |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 382 | irq_iommu = valid_irq_2_iommu(irq); |
| 383 | if (!irq_iommu) { |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 384 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 385 | return -1; |
| 386 | } |
| 387 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 388 | iommu = irq_iommu->iommu; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 389 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 390 | index = irq_iommu->irte_index + irq_iommu->sub_handle; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 391 | irte = &iommu->ir_table->base[index]; |
| 392 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 393 | if (!irq_iommu->sub_handle) { |
| 394 | for (i = 0; i < (1 << irq_iommu->irte_mask); i++) |
Suresh Siddha | 2e93456 | 2009-03-16 17:04:58 -0700 | [diff] [blame] | 395 | set_64bit((unsigned long *)(irte + i), 0); |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 396 | rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Yinghai Lu | e420dfb | 2008-08-19 20:50:21 -0700 | [diff] [blame] | 399 | irq_iommu->iommu = NULL; |
| 400 | irq_iommu->irte_index = 0; |
| 401 | irq_iommu->sub_handle = 0; |
| 402 | irq_iommu->irte_mask = 0; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 403 | |
Suresh Siddha | 4c5502b | 2009-03-16 17:04:53 -0700 | [diff] [blame] | 404 | spin_unlock_irqrestore(&irq_2_ir_lock, flags); |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 405 | |
Yu Zhao | 704126a | 2009-01-04 16:28:52 +0800 | [diff] [blame] | 406 | return rc; |
Suresh Siddha | b6fcb33 | 2008-07-10 11:16:44 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 409 | static void iommu_set_intr_remapping(struct intel_iommu *iommu, int mode) |
| 410 | { |
| 411 | u64 addr; |
| 412 | u32 cmd, sts; |
| 413 | unsigned long flags; |
| 414 | |
| 415 | addr = virt_to_phys((void *)iommu->ir_table->base); |
| 416 | |
| 417 | spin_lock_irqsave(&iommu->register_lock, flags); |
| 418 | |
| 419 | dmar_writeq(iommu->reg + DMAR_IRTA_REG, |
| 420 | (addr) | IR_X2APIC_MODE(mode) | INTR_REMAP_TABLE_REG_SIZE); |
| 421 | |
| 422 | /* Set interrupt-remapping table pointer */ |
| 423 | cmd = iommu->gcmd | DMA_GCMD_SIRTP; |
Han, Weidong | 161fde0 | 2009-04-03 17:15:47 +0800 | [diff] [blame] | 424 | iommu->gcmd |= DMA_GCMD_SIRTP; |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 425 | writel(cmd, iommu->reg + DMAR_GCMD_REG); |
| 426 | |
| 427 | IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, |
| 428 | readl, (sts & DMA_GSTS_IRTPS), sts); |
| 429 | spin_unlock_irqrestore(&iommu->register_lock, flags); |
| 430 | |
| 431 | /* |
| 432 | * global invalidation of interrupt entry cache before enabling |
| 433 | * interrupt-remapping. |
| 434 | */ |
| 435 | qi_global_iec(iommu); |
| 436 | |
| 437 | spin_lock_irqsave(&iommu->register_lock, flags); |
| 438 | |
| 439 | /* Enable interrupt-remapping */ |
| 440 | cmd = iommu->gcmd | DMA_GCMD_IRE; |
| 441 | iommu->gcmd |= DMA_GCMD_IRE; |
| 442 | writel(cmd, iommu->reg + DMAR_GCMD_REG); |
| 443 | |
| 444 | IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, |
| 445 | readl, (sts & DMA_GSTS_IRES), sts); |
| 446 | |
| 447 | spin_unlock_irqrestore(&iommu->register_lock, flags); |
| 448 | } |
| 449 | |
| 450 | |
| 451 | static int setup_intr_remapping(struct intel_iommu *iommu, int mode) |
| 452 | { |
| 453 | struct ir_table *ir_table; |
| 454 | struct page *pages; |
| 455 | |
| 456 | ir_table = iommu->ir_table = kzalloc(sizeof(struct ir_table), |
Suresh Siddha | fa4b57c | 2009-03-16 17:05:05 -0700 | [diff] [blame] | 457 | GFP_ATOMIC); |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 458 | |
| 459 | if (!iommu->ir_table) |
| 460 | return -ENOMEM; |
| 461 | |
Suresh Siddha | fa4b57c | 2009-03-16 17:05:05 -0700 | [diff] [blame] | 462 | pages = alloc_pages(GFP_ATOMIC | __GFP_ZERO, INTR_REMAP_PAGE_ORDER); |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 463 | |
| 464 | if (!pages) { |
| 465 | printk(KERN_ERR "failed to allocate pages of order %d\n", |
| 466 | INTR_REMAP_PAGE_ORDER); |
| 467 | kfree(iommu->ir_table); |
| 468 | return -ENOMEM; |
| 469 | } |
| 470 | |
| 471 | ir_table->base = page_address(pages); |
| 472 | |
| 473 | iommu_set_intr_remapping(iommu, mode); |
| 474 | return 0; |
| 475 | } |
| 476 | |
Suresh Siddha | eba67e5 | 2009-03-16 17:04:56 -0700 | [diff] [blame] | 477 | /* |
| 478 | * Disable Interrupt Remapping. |
| 479 | */ |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 480 | static void iommu_disable_intr_remapping(struct intel_iommu *iommu) |
Suresh Siddha | eba67e5 | 2009-03-16 17:04:56 -0700 | [diff] [blame] | 481 | { |
| 482 | unsigned long flags; |
| 483 | u32 sts; |
| 484 | |
| 485 | if (!ecap_ir_support(iommu->ecap)) |
| 486 | return; |
| 487 | |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 488 | /* |
| 489 | * global invalidation of interrupt entry cache before disabling |
| 490 | * interrupt-remapping. |
| 491 | */ |
| 492 | qi_global_iec(iommu); |
| 493 | |
Suresh Siddha | eba67e5 | 2009-03-16 17:04:56 -0700 | [diff] [blame] | 494 | spin_lock_irqsave(&iommu->register_lock, flags); |
| 495 | |
| 496 | sts = dmar_readq(iommu->reg + DMAR_GSTS_REG); |
| 497 | if (!(sts & DMA_GSTS_IRES)) |
| 498 | goto end; |
| 499 | |
| 500 | iommu->gcmd &= ~DMA_GCMD_IRE; |
| 501 | writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG); |
| 502 | |
| 503 | IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, |
| 504 | readl, !(sts & DMA_GSTS_IRES), sts); |
| 505 | |
| 506 | end: |
| 507 | spin_unlock_irqrestore(&iommu->register_lock, flags); |
| 508 | } |
| 509 | |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 510 | int __init intr_remapping_supported(void) |
| 511 | { |
| 512 | struct dmar_drhd_unit *drhd; |
| 513 | |
Weidong Han | 03ea815 | 2009-04-17 16:42:15 +0800 | [diff] [blame] | 514 | if (disable_intremap) |
| 515 | return 0; |
| 516 | |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 517 | for_each_drhd_unit(drhd) { |
| 518 | struct intel_iommu *iommu = drhd->iommu; |
| 519 | |
| 520 | if (!ecap_ir_support(iommu->ecap)) |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | return 1; |
| 525 | } |
| 526 | |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 527 | int __init enable_intr_remapping(int eim) |
| 528 | { |
| 529 | struct dmar_drhd_unit *drhd; |
| 530 | int setup = 0; |
| 531 | |
Suresh Siddha | 1531a6a | 2009-03-16 17:04:57 -0700 | [diff] [blame] | 532 | for_each_drhd_unit(drhd) { |
| 533 | struct intel_iommu *iommu = drhd->iommu; |
| 534 | |
| 535 | /* |
Han, Weidong | 34aaaa9 | 2009-04-04 17:21:26 +0800 | [diff] [blame] | 536 | * If the queued invalidation is already initialized, |
| 537 | * shouldn't disable it. |
| 538 | */ |
| 539 | if (iommu->qi) |
| 540 | continue; |
| 541 | |
| 542 | /* |
Suresh Siddha | 1531a6a | 2009-03-16 17:04:57 -0700 | [diff] [blame] | 543 | * Clear previous faults. |
| 544 | */ |
| 545 | dmar_fault(-1, iommu); |
| 546 | |
| 547 | /* |
| 548 | * Disable intr remapping and queued invalidation, if already |
| 549 | * enabled prior to OS handover. |
| 550 | */ |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 551 | iommu_disable_intr_remapping(iommu); |
Suresh Siddha | 1531a6a | 2009-03-16 17:04:57 -0700 | [diff] [blame] | 552 | |
| 553 | dmar_disable_qi(iommu); |
| 554 | } |
| 555 | |
Suresh Siddha | 2ae2101 | 2008-07-10 11:16:43 -0700 | [diff] [blame] | 556 | /* |
| 557 | * check for the Interrupt-remapping support |
| 558 | */ |
| 559 | for_each_drhd_unit(drhd) { |
| 560 | struct intel_iommu *iommu = drhd->iommu; |
| 561 | |
| 562 | if (!ecap_ir_support(iommu->ecap)) |
| 563 | continue; |
| 564 | |
| 565 | if (eim && !ecap_eim_support(iommu->ecap)) { |
| 566 | printk(KERN_INFO "DRHD %Lx: EIM not supported by DRHD, " |
| 567 | " ecap %Lx\n", drhd->reg_base_addr, iommu->ecap); |
| 568 | return -1; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * Enable queued invalidation for all the DRHD's. |
| 574 | */ |
| 575 | for_each_drhd_unit(drhd) { |
| 576 | int ret; |
| 577 | struct intel_iommu *iommu = drhd->iommu; |
| 578 | ret = dmar_enable_qi(iommu); |
| 579 | |
| 580 | if (ret) { |
| 581 | printk(KERN_ERR "DRHD %Lx: failed to enable queued, " |
| 582 | " invalidation, ecap %Lx, ret %d\n", |
| 583 | drhd->reg_base_addr, iommu->ecap, ret); |
| 584 | return -1; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | /* |
| 589 | * Setup Interrupt-remapping for all the DRHD's now. |
| 590 | */ |
| 591 | for_each_drhd_unit(drhd) { |
| 592 | struct intel_iommu *iommu = drhd->iommu; |
| 593 | |
| 594 | if (!ecap_ir_support(iommu->ecap)) |
| 595 | continue; |
| 596 | |
| 597 | if (setup_intr_remapping(iommu, eim)) |
| 598 | goto error; |
| 599 | |
| 600 | setup = 1; |
| 601 | } |
| 602 | |
| 603 | if (!setup) |
| 604 | goto error; |
| 605 | |
| 606 | intr_remapping_enabled = 1; |
| 607 | |
| 608 | return 0; |
| 609 | |
| 610 | error: |
| 611 | /* |
| 612 | * handle error condition gracefully here! |
| 613 | */ |
| 614 | return -1; |
| 615 | } |
Suresh Siddha | ad3ad3f | 2008-07-10 11:16:40 -0700 | [diff] [blame] | 616 | |
| 617 | static int ir_parse_ioapic_scope(struct acpi_dmar_header *header, |
| 618 | struct intel_iommu *iommu) |
| 619 | { |
| 620 | struct acpi_dmar_hardware_unit *drhd; |
| 621 | struct acpi_dmar_device_scope *scope; |
| 622 | void *start, *end; |
| 623 | |
| 624 | drhd = (struct acpi_dmar_hardware_unit *)header; |
| 625 | |
| 626 | start = (void *)(drhd + 1); |
| 627 | end = ((void *)drhd) + header->length; |
| 628 | |
| 629 | while (start < end) { |
| 630 | scope = start; |
| 631 | if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_IOAPIC) { |
| 632 | if (ir_ioapic_num == MAX_IO_APICS) { |
| 633 | printk(KERN_WARNING "Exceeded Max IO APICS\n"); |
| 634 | return -1; |
| 635 | } |
| 636 | |
| 637 | printk(KERN_INFO "IOAPIC id %d under DRHD base" |
| 638 | " 0x%Lx\n", scope->enumeration_id, |
| 639 | drhd->address); |
| 640 | |
| 641 | ir_ioapic[ir_ioapic_num].iommu = iommu; |
| 642 | ir_ioapic[ir_ioapic_num].id = scope->enumeration_id; |
| 643 | ir_ioapic_num++; |
| 644 | } |
| 645 | start += scope->length; |
| 646 | } |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | /* |
| 652 | * Finds the assocaition between IOAPIC's and its Interrupt-remapping |
| 653 | * hardware unit. |
| 654 | */ |
| 655 | int __init parse_ioapics_under_ir(void) |
| 656 | { |
| 657 | struct dmar_drhd_unit *drhd; |
| 658 | int ir_supported = 0; |
| 659 | |
| 660 | for_each_drhd_unit(drhd) { |
| 661 | struct intel_iommu *iommu = drhd->iommu; |
| 662 | |
| 663 | if (ecap_ir_support(iommu->ecap)) { |
| 664 | if (ir_parse_ioapic_scope(drhd->hdr, iommu)) |
| 665 | return -1; |
| 666 | |
| 667 | ir_supported = 1; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | if (ir_supported && ir_ioapic_num != nr_ioapics) { |
| 672 | printk(KERN_WARNING |
| 673 | "Not all IO-APIC's listed under remapping hardware\n"); |
| 674 | return -1; |
| 675 | } |
| 676 | |
| 677 | return ir_supported; |
| 678 | } |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 679 | |
| 680 | void disable_intr_remapping(void) |
| 681 | { |
| 682 | struct dmar_drhd_unit *drhd; |
| 683 | struct intel_iommu *iommu = NULL; |
| 684 | |
| 685 | /* |
| 686 | * Disable Interrupt-remapping for all the DRHD's now. |
| 687 | */ |
| 688 | for_each_iommu(iommu, drhd) { |
| 689 | if (!ecap_ir_support(iommu->ecap)) |
| 690 | continue; |
| 691 | |
| 692 | iommu_disable_intr_remapping(iommu); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | int reenable_intr_remapping(int eim) |
| 697 | { |
| 698 | struct dmar_drhd_unit *drhd; |
| 699 | int setup = 0; |
| 700 | struct intel_iommu *iommu = NULL; |
| 701 | |
| 702 | for_each_iommu(iommu, drhd) |
| 703 | if (iommu->qi) |
| 704 | dmar_reenable_qi(iommu); |
| 705 | |
| 706 | /* |
| 707 | * Setup Interrupt-remapping for all the DRHD's now. |
| 708 | */ |
| 709 | for_each_iommu(iommu, drhd) { |
| 710 | if (!ecap_ir_support(iommu->ecap)) |
| 711 | continue; |
| 712 | |
| 713 | /* Set up interrupt remapping for iommu.*/ |
| 714 | iommu_set_intr_remapping(iommu, eim); |
| 715 | setup = 1; |
| 716 | } |
| 717 | |
| 718 | if (!setup) |
| 719 | goto error; |
| 720 | |
| 721 | return 0; |
| 722 | |
| 723 | error: |
| 724 | /* |
| 725 | * handle error condition gracefully here! |
| 726 | */ |
| 727 | return -1; |
| 728 | } |
| 729 | |