x64, x2apic/intr-remap: parse ioapic scope under vt-d structures
[safe/jmp/linux-2.6] / drivers / pci / intr_remapping.c
1 #include <linux/dmar.h>
2 #include <asm/io_apic.h>
3 #include "intel-iommu.h"
4 #include "intr_remapping.h"
5
6 static struct ioapic_scope ir_ioapic[MAX_IO_APICS];
7 static int ir_ioapic_num;
8
9 static int ir_parse_ioapic_scope(struct acpi_dmar_header *header,
10                                  struct intel_iommu *iommu)
11 {
12         struct acpi_dmar_hardware_unit *drhd;
13         struct acpi_dmar_device_scope *scope;
14         void *start, *end;
15
16         drhd = (struct acpi_dmar_hardware_unit *)header;
17
18         start = (void *)(drhd + 1);
19         end = ((void *)drhd) + header->length;
20
21         while (start < end) {
22                 scope = start;
23                 if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_IOAPIC) {
24                         if (ir_ioapic_num == MAX_IO_APICS) {
25                                 printk(KERN_WARNING "Exceeded Max IO APICS\n");
26                                 return -1;
27                         }
28
29                         printk(KERN_INFO "IOAPIC id %d under DRHD base"
30                                " 0x%Lx\n", scope->enumeration_id,
31                                drhd->address);
32
33                         ir_ioapic[ir_ioapic_num].iommu = iommu;
34                         ir_ioapic[ir_ioapic_num].id = scope->enumeration_id;
35                         ir_ioapic_num++;
36                 }
37                 start += scope->length;
38         }
39
40         return 0;
41 }
42
43 /*
44  * Finds the assocaition between IOAPIC's and its Interrupt-remapping
45  * hardware unit.
46  */
47 int __init parse_ioapics_under_ir(void)
48 {
49         struct dmar_drhd_unit *drhd;
50         int ir_supported = 0;
51
52         for_each_drhd_unit(drhd) {
53                 struct intel_iommu *iommu = drhd->iommu;
54
55                 if (ecap_ir_support(iommu->ecap)) {
56                         if (ir_parse_ioapic_scope(drhd->hdr, iommu))
57                                 return -1;
58
59                         ir_supported = 1;
60                 }
61         }
62
63         if (ir_supported && ir_ioapic_num != nr_ioapics) {
64                 printk(KERN_WARNING
65                        "Not all IO-APIC's listed under remapping hardware\n");
66                 return -1;
67         }
68
69         return ir_supported;
70 }