Staging: netwave: delete the driver
[linux/fpc-iii.git] / drivers / pci / intr_remapping.c
blob6ee98a56946fff4a887b80f39c281ac495eb479b
1 #include <linux/interrupt.h>
2 #include <linux/dmar.h>
3 #include <linux/spinlock.h>
4 #include <linux/slab.h>
5 #include <linux/jiffies.h>
6 #include <linux/hpet.h>
7 #include <linux/pci.h>
8 #include <linux/irq.h>
9 #include <asm/io_apic.h>
10 #include <asm/smp.h>
11 #include <asm/cpu.h>
12 #include <linux/intel-iommu.h>
13 #include "intr_remapping.h"
14 #include <acpi/acpi.h>
15 #include <asm/pci-direct.h>
16 #include "pci.h"
18 static struct ioapic_scope ir_ioapic[MAX_IO_APICS];
19 static struct hpet_scope ir_hpet[MAX_HPET_TBS];
20 static int ir_ioapic_num, ir_hpet_num;
21 int intr_remapping_enabled;
23 static int disable_intremap;
24 static __init int setup_nointremap(char *str)
26 disable_intremap = 1;
27 return 0;
29 early_param("nointremap", setup_nointremap);
31 struct irq_2_iommu {
32 struct intel_iommu *iommu;
33 u16 irte_index;
34 u16 sub_handle;
35 u8 irte_mask;
38 #ifdef CONFIG_GENERIC_HARDIRQS
39 static struct irq_2_iommu *get_one_free_irq_2_iommu(int node)
41 struct irq_2_iommu *iommu;
43 iommu = kzalloc_node(sizeof(*iommu), GFP_ATOMIC, node);
44 printk(KERN_DEBUG "alloc irq_2_iommu on node %d\n", node);
46 return iommu;
49 static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
51 struct irq_desc *desc;
53 desc = irq_to_desc(irq);
55 if (WARN_ON_ONCE(!desc))
56 return NULL;
58 return desc->irq_2_iommu;
61 static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq)
63 struct irq_desc *desc;
64 struct irq_2_iommu *irq_iommu;
66 desc = irq_to_desc(irq);
67 if (!desc) {
68 printk(KERN_INFO "can not get irq_desc for %d\n", irq);
69 return NULL;
72 irq_iommu = desc->irq_2_iommu;
74 if (!irq_iommu)
75 desc->irq_2_iommu = get_one_free_irq_2_iommu(irq_node(irq));
77 return desc->irq_2_iommu;
80 #else /* !CONFIG_SPARSE_IRQ */
82 static struct irq_2_iommu irq_2_iommuX[NR_IRQS];
84 static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
86 if (irq < nr_irqs)
87 return &irq_2_iommuX[irq];
89 return NULL;
91 static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq)
93 return irq_2_iommu(irq);
95 #endif
97 static DEFINE_SPINLOCK(irq_2_ir_lock);
99 static struct irq_2_iommu *valid_irq_2_iommu(unsigned int irq)
101 struct irq_2_iommu *irq_iommu;
103 irq_iommu = irq_2_iommu(irq);
105 if (!irq_iommu)
106 return NULL;
108 if (!irq_iommu->iommu)
109 return NULL;
111 return irq_iommu;
114 int irq_remapped(int irq)
116 return valid_irq_2_iommu(irq) != NULL;
119 int get_irte(int irq, struct irte *entry)
121 int index;
122 struct irq_2_iommu *irq_iommu;
123 unsigned long flags;
125 if (!entry)
126 return -1;
128 spin_lock_irqsave(&irq_2_ir_lock, flags);
129 irq_iommu = valid_irq_2_iommu(irq);
130 if (!irq_iommu) {
131 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
132 return -1;
135 index = irq_iommu->irte_index + irq_iommu->sub_handle;
136 *entry = *(irq_iommu->iommu->ir_table->base + index);
138 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
139 return 0;
142 int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
144 struct ir_table *table = iommu->ir_table;
145 struct irq_2_iommu *irq_iommu;
146 u16 index, start_index;
147 unsigned int mask = 0;
148 unsigned long flags;
149 int i;
151 if (!count)
152 return -1;
154 #ifndef CONFIG_SPARSE_IRQ
155 /* protect irq_2_iommu_alloc later */
156 if (irq >= nr_irqs)
157 return -1;
158 #endif
161 * start the IRTE search from index 0.
163 index = start_index = 0;
165 if (count > 1) {
166 count = __roundup_pow_of_two(count);
167 mask = ilog2(count);
170 if (mask > ecap_max_handle_mask(iommu->ecap)) {
171 printk(KERN_ERR
172 "Requested mask %x exceeds the max invalidation handle"
173 " mask value %Lx\n", mask,
174 ecap_max_handle_mask(iommu->ecap));
175 return -1;
178 spin_lock_irqsave(&irq_2_ir_lock, flags);
179 do {
180 for (i = index; i < index + count; i++)
181 if (table->base[i].present)
182 break;
183 /* empty index found */
184 if (i == index + count)
185 break;
187 index = (index + count) % INTR_REMAP_TABLE_ENTRIES;
189 if (index == start_index) {
190 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
191 printk(KERN_ERR "can't allocate an IRTE\n");
192 return -1;
194 } while (1);
196 for (i = index; i < index + count; i++)
197 table->base[i].present = 1;
199 irq_iommu = irq_2_iommu_alloc(irq);
200 if (!irq_iommu) {
201 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
202 printk(KERN_ERR "can't allocate irq_2_iommu\n");
203 return -1;
206 irq_iommu->iommu = iommu;
207 irq_iommu->irte_index = index;
208 irq_iommu->sub_handle = 0;
209 irq_iommu->irte_mask = mask;
211 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
213 return index;
216 static int qi_flush_iec(struct intel_iommu *iommu, int index, int mask)
218 struct qi_desc desc;
220 desc.low = QI_IEC_IIDEX(index) | QI_IEC_TYPE | QI_IEC_IM(mask)
221 | QI_IEC_SELECTIVE;
222 desc.high = 0;
224 return qi_submit_sync(&desc, iommu);
227 int map_irq_to_irte_handle(int irq, u16 *sub_handle)
229 int index;
230 struct irq_2_iommu *irq_iommu;
231 unsigned long flags;
233 spin_lock_irqsave(&irq_2_ir_lock, flags);
234 irq_iommu = valid_irq_2_iommu(irq);
235 if (!irq_iommu) {
236 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
237 return -1;
240 *sub_handle = irq_iommu->sub_handle;
241 index = irq_iommu->irte_index;
242 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
243 return index;
246 int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)
248 struct irq_2_iommu *irq_iommu;
249 unsigned long flags;
251 spin_lock_irqsave(&irq_2_ir_lock, flags);
253 irq_iommu = irq_2_iommu_alloc(irq);
255 if (!irq_iommu) {
256 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
257 printk(KERN_ERR "can't allocate irq_2_iommu\n");
258 return -1;
261 irq_iommu->iommu = iommu;
262 irq_iommu->irte_index = index;
263 irq_iommu->sub_handle = subhandle;
264 irq_iommu->irte_mask = 0;
266 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
268 return 0;
271 int clear_irte_irq(int irq, struct intel_iommu *iommu, u16 index)
273 struct irq_2_iommu *irq_iommu;
274 unsigned long flags;
276 spin_lock_irqsave(&irq_2_ir_lock, flags);
277 irq_iommu = valid_irq_2_iommu(irq);
278 if (!irq_iommu) {
279 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
280 return -1;
283 irq_iommu->iommu = NULL;
284 irq_iommu->irte_index = 0;
285 irq_iommu->sub_handle = 0;
286 irq_2_iommu(irq)->irte_mask = 0;
288 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
290 return 0;
293 int modify_irte(int irq, struct irte *irte_modified)
295 int rc;
296 int index;
297 struct irte *irte;
298 struct intel_iommu *iommu;
299 struct irq_2_iommu *irq_iommu;
300 unsigned long flags;
302 spin_lock_irqsave(&irq_2_ir_lock, flags);
303 irq_iommu = valid_irq_2_iommu(irq);
304 if (!irq_iommu) {
305 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
306 return -1;
309 iommu = irq_iommu->iommu;
311 index = irq_iommu->irte_index + irq_iommu->sub_handle;
312 irte = &iommu->ir_table->base[index];
314 set_64bit((unsigned long *)&irte->low, irte_modified->low);
315 set_64bit((unsigned long *)&irte->high, irte_modified->high);
316 __iommu_flush_cache(iommu, irte, sizeof(*irte));
318 rc = qi_flush_iec(iommu, index, 0);
319 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
321 return rc;
324 int flush_irte(int irq)
326 int rc;
327 int index;
328 struct intel_iommu *iommu;
329 struct irq_2_iommu *irq_iommu;
330 unsigned long flags;
332 spin_lock_irqsave(&irq_2_ir_lock, flags);
333 irq_iommu = valid_irq_2_iommu(irq);
334 if (!irq_iommu) {
335 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
336 return -1;
339 iommu = irq_iommu->iommu;
341 index = irq_iommu->irte_index + irq_iommu->sub_handle;
343 rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask);
344 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
346 return rc;
349 struct intel_iommu *map_hpet_to_ir(u8 hpet_id)
351 int i;
353 for (i = 0; i < MAX_HPET_TBS; i++)
354 if (ir_hpet[i].id == hpet_id)
355 return ir_hpet[i].iommu;
356 return NULL;
359 struct intel_iommu *map_ioapic_to_ir(int apic)
361 int i;
363 for (i = 0; i < MAX_IO_APICS; i++)
364 if (ir_ioapic[i].id == apic)
365 return ir_ioapic[i].iommu;
366 return NULL;
369 struct intel_iommu *map_dev_to_ir(struct pci_dev *dev)
371 struct dmar_drhd_unit *drhd;
373 drhd = dmar_find_matched_drhd_unit(dev);
374 if (!drhd)
375 return NULL;
377 return drhd->iommu;
380 static int clear_entries(struct irq_2_iommu *irq_iommu)
382 struct irte *start, *entry, *end;
383 struct intel_iommu *iommu;
384 int index;
386 if (irq_iommu->sub_handle)
387 return 0;
389 iommu = irq_iommu->iommu;
390 index = irq_iommu->irte_index + irq_iommu->sub_handle;
392 start = iommu->ir_table->base + index;
393 end = start + (1 << irq_iommu->irte_mask);
395 for (entry = start; entry < end; entry++) {
396 set_64bit((unsigned long *)&entry->low, 0);
397 set_64bit((unsigned long *)&entry->high, 0);
400 return qi_flush_iec(iommu, index, irq_iommu->irte_mask);
403 int free_irte(int irq)
405 int rc = 0;
406 struct irq_2_iommu *irq_iommu;
407 unsigned long flags;
409 spin_lock_irqsave(&irq_2_ir_lock, flags);
410 irq_iommu = valid_irq_2_iommu(irq);
411 if (!irq_iommu) {
412 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
413 return -1;
416 rc = clear_entries(irq_iommu);
418 irq_iommu->iommu = NULL;
419 irq_iommu->irte_index = 0;
420 irq_iommu->sub_handle = 0;
421 irq_iommu->irte_mask = 0;
423 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
425 return rc;
429 * source validation type
431 #define SVT_NO_VERIFY 0x0 /* no verification is required */
432 #define SVT_VERIFY_SID_SQ 0x1 /* verify using SID and SQ fiels */
433 #define SVT_VERIFY_BUS 0x2 /* verify bus of request-id */
436 * source-id qualifier
438 #define SQ_ALL_16 0x0 /* verify all 16 bits of request-id */
439 #define SQ_13_IGNORE_1 0x1 /* verify most significant 13 bits, ignore
440 * the third least significant bit
442 #define SQ_13_IGNORE_2 0x2 /* verify most significant 13 bits, ignore
443 * the second and third least significant bits
445 #define SQ_13_IGNORE_3 0x3 /* verify most significant 13 bits, ignore
446 * the least three significant bits
450 * set SVT, SQ and SID fields of irte to verify
451 * source ids of interrupt requests
453 static void set_irte_sid(struct irte *irte, unsigned int svt,
454 unsigned int sq, unsigned int sid)
456 irte->svt = svt;
457 irte->sq = sq;
458 irte->sid = sid;
461 int set_ioapic_sid(struct irte *irte, int apic)
463 int i;
464 u16 sid = 0;
466 if (!irte)
467 return -1;
469 for (i = 0; i < MAX_IO_APICS; i++) {
470 if (ir_ioapic[i].id == apic) {
471 sid = (ir_ioapic[i].bus << 8) | ir_ioapic[i].devfn;
472 break;
476 if (sid == 0) {
477 pr_warning("Failed to set source-id of IOAPIC (%d)\n", apic);
478 return -1;
481 set_irte_sid(irte, 1, 0, sid);
483 return 0;
486 int set_hpet_sid(struct irte *irte, u8 id)
488 int i;
489 u16 sid = 0;
491 if (!irte)
492 return -1;
494 for (i = 0; i < MAX_HPET_TBS; i++) {
495 if (ir_hpet[i].id == id) {
496 sid = (ir_hpet[i].bus << 8) | ir_hpet[i].devfn;
497 break;
501 if (sid == 0) {
502 pr_warning("Failed to set source-id of HPET block (%d)\n", id);
503 return -1;
507 * Should really use SQ_ALL_16. Some platforms are broken.
508 * While we figure out the right quirks for these broken platforms, use
509 * SQ_13_IGNORE_3 for now.
511 set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_13_IGNORE_3, sid);
513 return 0;
516 int set_msi_sid(struct irte *irte, struct pci_dev *dev)
518 struct pci_dev *bridge;
520 if (!irte || !dev)
521 return -1;
523 /* PCIe device or Root Complex integrated PCI device */
524 if (pci_is_pcie(dev) || !dev->bus->parent) {
525 set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_ALL_16,
526 (dev->bus->number << 8) | dev->devfn);
527 return 0;
530 bridge = pci_find_upstream_pcie_bridge(dev);
531 if (bridge) {
532 if (pci_is_pcie(bridge))/* this is a PCIe-to-PCI/PCIX bridge */
533 set_irte_sid(irte, SVT_VERIFY_BUS, SQ_ALL_16,
534 (bridge->bus->number << 8) | dev->bus->number);
535 else /* this is a legacy PCI bridge */
536 set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_ALL_16,
537 (bridge->bus->number << 8) | bridge->devfn);
540 return 0;
543 static void iommu_set_intr_remapping(struct intel_iommu *iommu, int mode)
545 u64 addr;
546 u32 sts;
547 unsigned long flags;
549 addr = virt_to_phys((void *)iommu->ir_table->base);
551 spin_lock_irqsave(&iommu->register_lock, flags);
553 dmar_writeq(iommu->reg + DMAR_IRTA_REG,
554 (addr) | IR_X2APIC_MODE(mode) | INTR_REMAP_TABLE_REG_SIZE);
556 /* Set interrupt-remapping table pointer */
557 iommu->gcmd |= DMA_GCMD_SIRTP;
558 writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
560 IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
561 readl, (sts & DMA_GSTS_IRTPS), sts);
562 spin_unlock_irqrestore(&iommu->register_lock, flags);
565 * global invalidation of interrupt entry cache before enabling
566 * interrupt-remapping.
568 qi_global_iec(iommu);
570 spin_lock_irqsave(&iommu->register_lock, flags);
572 /* Enable interrupt-remapping */
573 iommu->gcmd |= DMA_GCMD_IRE;
574 writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
576 IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
577 readl, (sts & DMA_GSTS_IRES), sts);
579 spin_unlock_irqrestore(&iommu->register_lock, flags);
583 static int setup_intr_remapping(struct intel_iommu *iommu, int mode)
585 struct ir_table *ir_table;
586 struct page *pages;
588 ir_table = iommu->ir_table = kzalloc(sizeof(struct ir_table),
589 GFP_ATOMIC);
591 if (!iommu->ir_table)
592 return -ENOMEM;
594 pages = alloc_pages_node(iommu->node, GFP_ATOMIC | __GFP_ZERO,
595 INTR_REMAP_PAGE_ORDER);
597 if (!pages) {
598 printk(KERN_ERR "failed to allocate pages of order %d\n",
599 INTR_REMAP_PAGE_ORDER);
600 kfree(iommu->ir_table);
601 return -ENOMEM;
604 ir_table->base = page_address(pages);
606 iommu_set_intr_remapping(iommu, mode);
607 return 0;
611 * Disable Interrupt Remapping.
613 static void iommu_disable_intr_remapping(struct intel_iommu *iommu)
615 unsigned long flags;
616 u32 sts;
618 if (!ecap_ir_support(iommu->ecap))
619 return;
622 * global invalidation of interrupt entry cache before disabling
623 * interrupt-remapping.
625 qi_global_iec(iommu);
627 spin_lock_irqsave(&iommu->register_lock, flags);
629 sts = dmar_readq(iommu->reg + DMAR_GSTS_REG);
630 if (!(sts & DMA_GSTS_IRES))
631 goto end;
633 iommu->gcmd &= ~DMA_GCMD_IRE;
634 writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
636 IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
637 readl, !(sts & DMA_GSTS_IRES), sts);
639 end:
640 spin_unlock_irqrestore(&iommu->register_lock, flags);
643 int __init intr_remapping_supported(void)
645 struct dmar_drhd_unit *drhd;
647 if (disable_intremap)
648 return 0;
650 if (!dmar_ir_support())
651 return 0;
653 for_each_drhd_unit(drhd) {
654 struct intel_iommu *iommu = drhd->iommu;
656 if (!ecap_ir_support(iommu->ecap))
657 return 0;
660 return 1;
663 int __init enable_intr_remapping(int eim)
665 struct dmar_drhd_unit *drhd;
666 int setup = 0;
668 if (parse_ioapics_under_ir() != 1) {
669 printk(KERN_INFO "Not enable interrupt remapping\n");
670 return -1;
673 for_each_drhd_unit(drhd) {
674 struct intel_iommu *iommu = drhd->iommu;
677 * If the queued invalidation is already initialized,
678 * shouldn't disable it.
680 if (iommu->qi)
681 continue;
684 * Clear previous faults.
686 dmar_fault(-1, iommu);
689 * Disable intr remapping and queued invalidation, if already
690 * enabled prior to OS handover.
692 iommu_disable_intr_remapping(iommu);
694 dmar_disable_qi(iommu);
698 * check for the Interrupt-remapping support
700 for_each_drhd_unit(drhd) {
701 struct intel_iommu *iommu = drhd->iommu;
703 if (!ecap_ir_support(iommu->ecap))
704 continue;
706 if (eim && !ecap_eim_support(iommu->ecap)) {
707 printk(KERN_INFO "DRHD %Lx: EIM not supported by DRHD, "
708 " ecap %Lx\n", drhd->reg_base_addr, iommu->ecap);
709 return -1;
714 * Enable queued invalidation for all the DRHD's.
716 for_each_drhd_unit(drhd) {
717 int ret;
718 struct intel_iommu *iommu = drhd->iommu;
719 ret = dmar_enable_qi(iommu);
721 if (ret) {
722 printk(KERN_ERR "DRHD %Lx: failed to enable queued, "
723 " invalidation, ecap %Lx, ret %d\n",
724 drhd->reg_base_addr, iommu->ecap, ret);
725 return -1;
730 * Setup Interrupt-remapping for all the DRHD's now.
732 for_each_drhd_unit(drhd) {
733 struct intel_iommu *iommu = drhd->iommu;
735 if (!ecap_ir_support(iommu->ecap))
736 continue;
738 if (setup_intr_remapping(iommu, eim))
739 goto error;
741 setup = 1;
744 if (!setup)
745 goto error;
747 intr_remapping_enabled = 1;
749 return 0;
751 error:
753 * handle error condition gracefully here!
755 return -1;
758 static void ir_parse_one_hpet_scope(struct acpi_dmar_device_scope *scope,
759 struct intel_iommu *iommu)
761 struct acpi_dmar_pci_path *path;
762 u8 bus;
763 int count;
765 bus = scope->bus;
766 path = (struct acpi_dmar_pci_path *)(scope + 1);
767 count = (scope->length - sizeof(struct acpi_dmar_device_scope))
768 / sizeof(struct acpi_dmar_pci_path);
770 while (--count > 0) {
772 * Access PCI directly due to the PCI
773 * subsystem isn't initialized yet.
775 bus = read_pci_config_byte(bus, path->dev, path->fn,
776 PCI_SECONDARY_BUS);
777 path++;
779 ir_hpet[ir_hpet_num].bus = bus;
780 ir_hpet[ir_hpet_num].devfn = PCI_DEVFN(path->dev, path->fn);
781 ir_hpet[ir_hpet_num].iommu = iommu;
782 ir_hpet[ir_hpet_num].id = scope->enumeration_id;
783 ir_hpet_num++;
786 static void ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope,
787 struct intel_iommu *iommu)
789 struct acpi_dmar_pci_path *path;
790 u8 bus;
791 int count;
793 bus = scope->bus;
794 path = (struct acpi_dmar_pci_path *)(scope + 1);
795 count = (scope->length - sizeof(struct acpi_dmar_device_scope))
796 / sizeof(struct acpi_dmar_pci_path);
798 while (--count > 0) {
800 * Access PCI directly due to the PCI
801 * subsystem isn't initialized yet.
803 bus = read_pci_config_byte(bus, path->dev, path->fn,
804 PCI_SECONDARY_BUS);
805 path++;
808 ir_ioapic[ir_ioapic_num].bus = bus;
809 ir_ioapic[ir_ioapic_num].devfn = PCI_DEVFN(path->dev, path->fn);
810 ir_ioapic[ir_ioapic_num].iommu = iommu;
811 ir_ioapic[ir_ioapic_num].id = scope->enumeration_id;
812 ir_ioapic_num++;
815 static int ir_parse_ioapic_hpet_scope(struct acpi_dmar_header *header,
816 struct intel_iommu *iommu)
818 struct acpi_dmar_hardware_unit *drhd;
819 struct acpi_dmar_device_scope *scope;
820 void *start, *end;
822 drhd = (struct acpi_dmar_hardware_unit *)header;
824 start = (void *)(drhd + 1);
825 end = ((void *)drhd) + header->length;
827 while (start < end) {
828 scope = start;
829 if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_IOAPIC) {
830 if (ir_ioapic_num == MAX_IO_APICS) {
831 printk(KERN_WARNING "Exceeded Max IO APICS\n");
832 return -1;
835 printk(KERN_INFO "IOAPIC id %d under DRHD base"
836 " 0x%Lx\n", scope->enumeration_id,
837 drhd->address);
839 ir_parse_one_ioapic_scope(scope, iommu);
840 } else if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_HPET) {
841 if (ir_hpet_num == MAX_HPET_TBS) {
842 printk(KERN_WARNING "Exceeded Max HPET blocks\n");
843 return -1;
846 printk(KERN_INFO "HPET id %d under DRHD base"
847 " 0x%Lx\n", scope->enumeration_id,
848 drhd->address);
850 ir_parse_one_hpet_scope(scope, iommu);
852 start += scope->length;
855 return 0;
859 * Finds the assocaition between IOAPIC's and its Interrupt-remapping
860 * hardware unit.
862 int __init parse_ioapics_under_ir(void)
864 struct dmar_drhd_unit *drhd;
865 int ir_supported = 0;
867 for_each_drhd_unit(drhd) {
868 struct intel_iommu *iommu = drhd->iommu;
870 if (ecap_ir_support(iommu->ecap)) {
871 if (ir_parse_ioapic_hpet_scope(drhd->hdr, iommu))
872 return -1;
874 ir_supported = 1;
878 if (ir_supported && ir_ioapic_num != nr_ioapics) {
879 printk(KERN_WARNING
880 "Not all IO-APIC's listed under remapping hardware\n");
881 return -1;
884 return ir_supported;
887 void disable_intr_remapping(void)
889 struct dmar_drhd_unit *drhd;
890 struct intel_iommu *iommu = NULL;
893 * Disable Interrupt-remapping for all the DRHD's now.
895 for_each_iommu(iommu, drhd) {
896 if (!ecap_ir_support(iommu->ecap))
897 continue;
899 iommu_disable_intr_remapping(iommu);
903 int reenable_intr_remapping(int eim)
905 struct dmar_drhd_unit *drhd;
906 int setup = 0;
907 struct intel_iommu *iommu = NULL;
909 for_each_iommu(iommu, drhd)
910 if (iommu->qi)
911 dmar_reenable_qi(iommu);
914 * Setup Interrupt-remapping for all the DRHD's now.
916 for_each_iommu(iommu, drhd) {
917 if (!ecap_ir_support(iommu->ecap))
918 continue;
920 /* Set up interrupt remapping for iommu.*/
921 iommu_set_intr_remapping(iommu, eim);
922 setup = 1;
925 if (!setup)
926 goto error;
928 return 0;
930 error:
932 * handle error condition gracefully here!
934 return -1;