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