Skip to contentSkip to conversation

PCI multi-seg: VT-d specific adjustments

RFC PATCH In review Jan Beulich 1 participant 1 message Aug 25, 2011

lore
Share & tools
lore
#0 lore raw

RFC PATCH 4/7 PCI multi-seg: VT-d specific adjustments

xen/drivers/passthrough/vtd/dmar.c +25 -15
@@ -188,6 +188,9 @@ struct acpi_drhd_unit * acpi_find_matche
 
     list_for_each_entry ( drhd, &acpi_drhd_units, list )
     {
+        if ( drhd->segment != pdev->seg )
+            continue;
+
         for (i = 0; i < drhd->scope.devices_cnt; i++)
             if ( drhd->scope.devices[i] == PCI_BDF2(bus, devfn) )
                 return drhd;
@@ -201,13 +204,16 @@ struct acpi_drhd_unit * acpi_find_matche
     return include_all;
 }
 
-struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u8 bus, u8 devfn)
+struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u16 seg, u8 bus, u8 devfn)
 {
     struct acpi_atsr_unit *atsr;
     struct acpi_atsr_unit *all_ports = NULL;
 
     list_for_each_entry ( atsr, &acpi_atsr_units, list )
     {
+        if ( atsr->segment != seg )
+            continue;
+
         if ( test_bit(bus, atsr->scope.buses) )
             return atsr;
 
@@ -269,8 +275,8 @@ static int scope_device_count(void *star
 }
 
 
-static int __init acpi_parse_dev_scope(void *start, void *end,
-                                       void *acpi_entry, int type)
+static int __init acpi_parse_dev_scope(
+    void *start, void *end, void *acpi_entry, int type, u16 seg)
 {
     struct dmar_scope *scope = acpi_entry;
     struct acpi_ioapic_unit *acpi_ioapic_unit;
@@ -314,8 +320,8 @@ static int __init acpi_parse_dev_scope(v
                 bus, path->dev, path->fn, PCI_SUBORDINATE_BUS);
             if ( iommu_verbose )
                 dprintk(VTDPREFIX,
-                        "  bridge: %x:%x.%x  start = %x sec = %x  sub = %x\n",
-                        bus, path->dev, path->fn,
+                        " bridge: %04x:%02x:%02x.%u start=%x sec=%x sub=%x\n",
+                        seg, bus, path->dev, path->fn,
                         acpi_scope->start_bus, sec_bus, sub_bus);
 
             dmar_scope_add_buses(scope, sec_bus, sub_bus);
@@ -323,20 +329,21 @@ static int __init acpi_parse_dev_scope(v
 
         case ACPI_DEV_MSI_HPET:
             if ( iommu_verbose )
-                dprintk(VTDPREFIX, "  MSI HPET: %x:%x.%x\n",
-                        bus, path->dev, path->fn);
+                dprintk(VTDPREFIX, " MSI HPET: %04x:%02x:%02x.%u\n",
+                        seg, bus, path->dev, path->fn);
             break;
 
         case ACPI_DEV_ENDPOINT:
             if ( iommu_verbose )
-                dprintk(VTDPREFIX, "  endpoint: %x:%x.%x\n",
-                        bus, path->dev, path->fn);
+                dprintk(VTDPREFIX, " endpoint: %04x:%02x:%02x.%u\n",
+                        seg, bus, path->dev, path->fn);
 
             if ( type == DMAR_TYPE )
             {
                 struct acpi_drhd_unit *drhd = acpi_entry;
 
-                if ( (bus == 0) && (path->dev == 2) && (path->fn == 0) )
+                if ( (seg == 0) && (bus == 0) && (path->dev == 2) &&
+                     (path->fn == 0) )
                     igd_drhd_address = drhd->address;
             }
 
@@ -344,8 +351,8 @@ static int __init acpi_parse_dev_scope(v
 
         case ACPI_DEV_IOAPIC:
             if ( iommu_verbose )
-                dprintk(VTDPREFIX, "  IOAPIC: %x:%x.%x\n",
-                        bus, path->dev, path->fn);
+                dprintk(VTDPREFIX, " IOAPIC: %04x:%02x:%02x.%u\n",
+                        seg, bus, path->dev, path->fn);
 
             if ( type == DMAR_TYPE )
             {
@@ -398,6 +405,7 @@ acpi_parse_one_drhd(struct acpi_dmar_ent
     memset(dmaru, 0, sizeof(struct acpi_drhd_unit));
 
     dmaru->address = drhd->address;
+    dmaru->segment = drhd->segment;
     dmaru->include_all = drhd->flags & 1; /* BIT0: INCLUDE_ALL */
     INIT_LIST_HEAD(&dmaru->ioapic_list);
     if ( iommu_verbose )
@@ -411,7 +419,7 @@ acpi_parse_one_drhd(struct acpi_dmar_ent
     dev_scope_start = (void *)(drhd + 1);
     dev_scope_end = ((void *)drhd) + header->length;
     ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
-                               dmaru, DMAR_TYPE);
+                               dmaru, DMAR_TYPE, drhd->segment);
 
     if ( dmaru->include_all )
     {
@@ -528,11 +536,12 @@ acpi_parse_one_rmrr(struct acpi_dmar_ent
 
     rmrru->base_address = base_addr;
     rmrru->end_address = end_addr;
+    rmrru->segment = rmrr->segment;
 
     dev_scope_start = (void *)(rmrr + 1);
     dev_scope_end   = ((void *)rmrr) + header->length;
     ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
-                               rmrru, RMRR_TYPE);
+                               rmrru, RMRR_TYPE, rmrr->segment);
 
     if ( ret || (rmrru->scope.devices_cnt == 0) )
         xfree(rmrru);
@@ -609,6 +618,7 @@ acpi_parse_one_atsr(struct acpi_dmar_ent
         return -ENOMEM;
     memset(atsru, 0, sizeof(struct acpi_atsr_unit));
 
+    atsru->segment = atsr->segment;
     atsru->all_ports = atsr->flags & 1; /* BIT0: ALL_PORTS */
     if ( iommu_verbose )
         dprintk(VTDPREFIX,
@@ -618,7 +628,7 @@ acpi_parse_one_atsr(struct acpi_dmar_ent
         dev_scope_start = (void *)(atsr + 1);
         dev_scope_end   = ((void *)atsr) + header->length;
         ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
-                                   atsru, ATSR_TYPE);
+                                   atsru, ATSR_TYPE, atsr->segment);
     }
     else
     {
xen/drivers/passthrough/vtd/dmar.h +5 -2
@@ -49,6 +49,7 @@ struct acpi_drhd_unit {
     struct dmar_scope scope;            /* must be first member of struct */
     struct list_head list;
     u64    address;                     /* register base address of the unit */
+    u16    segment;
     u8     include_all:1;
     struct iommu *iommu;
     struct list_head ioapic_list;
@@ -59,12 +60,14 @@ struct acpi_rmrr_unit {
     struct list_head list;
     u64    base_address;
     u64    end_address;
+    u16    segment;
     u8     allow_all:1;
 };
 
 struct acpi_atsr_unit {
     struct dmar_scope scope;            /* must be first member of struct */
     struct list_head list;
+    u16    segment;
     u8     all_ports:1;
 };
 
@@ -84,7 +87,7 @@ struct acpi_rhsa_unit {
                  idx < rmrr->scope.devices_cnt; idx++)
 
 struct acpi_drhd_unit * acpi_find_matched_drhd_unit(struct pci_dev *pdev);
-struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u8 bus, u8 devfn);
+struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u16 seg, u8 bus, u8 devfn);
 
 #define DMAR_TYPE 1
 #define RMRR_TYPE 2
@@ -114,7 +117,7 @@ void *map_to_nocache_virt(int nr_iommus,
 
 int vtd_hw_check(void);
 void disable_pmr(struct iommu *iommu);
-int is_usb_device(u8 bus, u8 devfn);
+int is_usb_device(u16 seg, u8 bus, u8 devfn);
 int is_igd_drhd(struct acpi_drhd_unit *drhd);
 
 #endif /* _DMAR_H_ */
xen/drivers/passthrough/vtd/iommu.c +53 -37

249 lines not on this page · raw message

xen/drivers/passthrough/vtd/utils.c +4 -3
@@ -32,7 +32,7 @@
 #include <asm/io_apic.h>
 #endif
 
-int is_usb_device(u8 bus, u8 devfn)
+int is_usb_device(u16 seg, u8 bus, u8 devfn)
 {
     u16 class = pci_conf_read16(bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
                                 PCI_CLASS_DEVICE);
@@ -106,8 +106,9 @@ void print_vtd_entries(struct iommu *iom
     u64 *l, val;
     u32 l_index, level;
 
-    printk("print_vtd_entries: iommu = %p bdf = %x:%x.%x gmfn = %"PRIx64"\n",
-           iommu, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), gmfn);
+    printk("print_vtd_entries: iommu %p dev %04x:%02x:%02x.%u gmfn %"PRIx64"\n",
+           iommu, iommu->intel->drhd->segment, bus,
+           PCI_SLOT(devfn), PCI_FUNC(devfn), gmfn);
 
     if ( iommu->root_maddr == 0 )
     {
xen/drivers/passthrough/vtd/x86/ats.c +1 -1
@@ -104,7 +104,7 @@ int ats_device(int seg, int bus, int dev
          !ecap_dev_iotlb(drhd->iommu->ecap) )
         return 0;
 
-    if ( !acpi_find_matched_atsr_unit(bus, devfn) )
+    if ( !acpi_find_matched_atsr_unit(seg, bus, devfn) )
         return 0;
 
     ats_drhd = find_ats_dev_drhd(drhd->iommu);
xen/drivers/passthrough/vtd/dmar.c +25 -15
@@ -188,6 +188,9 @@ struct acpi_drhd_unit * acpi_find_matche
 
     list_for_each_entry ( drhd, &acpi_drhd_units, list )
     {
+        if ( drhd->segment != pdev->seg )
+            continue;
+
         for (i = 0; i < drhd->scope.devices_cnt; i++)
             if ( drhd->scope.devices[i] == PCI_BDF2(bus, devfn) )
                 return drhd;
@@ -201,13 +204,16 @@ struct acpi_drhd_unit * acpi_find_matche
     return include_all;
 }
 
-struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u8 bus, u8 devfn)
+struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u16 seg, u8 bus, u8 devfn)
 {
     struct acpi_atsr_unit *atsr;
     struct acpi_atsr_unit *all_ports = NULL;
 
     list_for_each_entry ( atsr, &acpi_atsr_units, list )
     {
+        if ( atsr->segment != seg )
+            continue;
+
         if ( test_bit(bus, atsr->scope.buses) )
             return atsr;
 
@@ -269,8 +275,8 @@ static int scope_device_count(void *star
 }
 
 
-static int __init acpi_parse_dev_scope(void *start, void *end,
-                                       void *acpi_entry, int type)
+static int __init acpi_parse_dev_scope(
+    void *start, void *end, void *acpi_entry, int type, u16 seg)
 {
     struct dmar_scope *scope = acpi_entry;
     struct acpi_ioapic_unit *acpi_ioapic_unit;
@@ -314,8 +320,8 @@ static int __init acpi_parse_dev_scope(v
                 bus, path->dev, path->fn, PCI_SUBORDINATE_BUS);
             if ( iommu_verbose )
                 dprintk(VTDPREFIX,
-                        "  bridge: %x:%x.%x  start = %x sec = %x  sub = %x\n",
-                        bus, path->dev, path->fn,
+                        " bridge: %04x:%02x:%02x.%u start=%x sec=%x sub=%x\n",
+                        seg, bus, path->dev, path->fn,
                         acpi_scope->start_bus, sec_bus, sub_bus);
 
             dmar_scope_add_buses(scope, sec_bus, sub_bus);
@@ -323,20 +329,21 @@ static int __init acpi_parse_dev_scope(v
 
         case ACPI_DEV_MSI_HPET:
             if ( iommu_verbose )
-                dprintk(VTDPREFIX, "  MSI HPET: %x:%x.%x\n",
-                        bus, path->dev, path->fn);
+                dprintk(VTDPREFIX, " MSI HPET: %04x:%02x:%02x.%u\n",
+                        seg, bus, path->dev, path->fn);
             break;
 
         case ACPI_DEV_ENDPOINT:
             if ( iommu_verbose )
-                dprintk(VTDPREFIX, "  endpoint: %x:%x.%x\n",
-                        bus, path->dev, path->fn);
+                dprintk(VTDPREFIX, " endpoint: %04x:%02x:%02x.%u\n",
+                        seg, bus, path->dev, path->fn);
 
             if ( type == DMAR_TYPE )
             {
                 struct acpi_drhd_unit *drhd = acpi_entry;
 
-                if ( (bus == 0) && (path->dev == 2) && (path->fn == 0) )
+                if ( (seg == 0) && (bus == 0) && (path->dev == 2) &&
+                     (path->fn == 0) )
                     igd_drhd_address = drhd->address;
             }
 
@@ -344,8 +351,8 @@ static int __init acpi_parse_dev_scope(v
 
         case ACPI_DEV_IOAPIC:
             if ( iommu_verbose )
-                dprintk(VTDPREFIX, "  IOAPIC: %x:%x.%x\n",
-                        bus, path->dev, path->fn);
+                dprintk(VTDPREFIX, " IOAPIC: %04x:%02x:%02x.%u\n",
+                        seg, bus, path->dev, path->fn);
 
             if ( type == DMAR_TYPE )
             {
@@ -398,6 +405,7 @@ acpi_parse_one_drhd(struct acpi_dmar_ent
     memset(dmaru, 0, sizeof(struct acpi_drhd_unit));
 
     dmaru->address = drhd->address;
+    dmaru->segment = drhd->segment;
     dmaru->include_all = drhd->flags & 1; /* BIT0: INCLUDE_ALL */
     INIT_LIST_HEAD(&dmaru->ioapic_list);
     if ( iommu_verbose )
@@ -411,7 +419,7 @@ acpi_parse_one_drhd(struct acpi_dmar_ent
     dev_scope_start = (void *)(drhd + 1);
     dev_scope_end = ((void *)drhd) + header->length;
     ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
-                               dmaru, DMAR_TYPE);
+                               dmaru, DMAR_TYPE, drhd->segment);
 
     if ( dmaru->include_all )
     {
@@ -528,11 +536,12 @@ acpi_parse_one_rmrr(struct acpi_dmar_ent
 
     rmrru->base_address = base_addr;
     rmrru->end_address = end_addr;
+    rmrru->segment = rmrr->segment;
 
     dev_scope_start = (void *)(rmrr + 1);
     dev_scope_end   = ((void *)rmrr) + header->length;
     ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
-                               rmrru, RMRR_TYPE);
+                               rmrru, RMRR_TYPE, rmrr->segment);
 
     if ( ret || (rmrru->scope.devices_cnt == 0) )
         xfree(rmrru);
@@ -609,6 +618,7 @@ acpi_parse_one_atsr(struct acpi_dmar_ent
         return -ENOMEM;
     memset(atsru, 0, sizeof(struct acpi_atsr_unit));
 
+    atsru->segment = atsr->segment;
     atsru->all_ports = atsr->flags & 1; /* BIT0: ALL_PORTS */
     if ( iommu_verbose )
         dprintk(VTDPREFIX,
@@ -618,7 +628,7 @@ acpi_parse_one_atsr(struct acpi_dmar_ent
         dev_scope_start = (void *)(atsr + 1);
         dev_scope_end   = ((void *)atsr) + header->length;
         ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
-                                   atsru, ATSR_TYPE);
+                                   atsru, ATSR_TYPE, atsr->segment);
     }
     else
     {
xen/drivers/passthrough/vtd/dmar.h +5 -2
@@ -49,6 +49,7 @@ struct acpi_drhd_unit {
     struct dmar_scope scope;            /* must be first member of struct */
     struct list_head list;
     u64    address;                     /* register base address of the unit */
+    u16    segment;
     u8     include_all:1;
     struct iommu *iommu;
     struct list_head ioapic_list;
@@ -59,12 +60,14 @@ struct acpi_rmrr_unit {
     struct list_head list;
     u64    base_address;
     u64    end_address;
+    u16    segment;
     u8     allow_all:1;
 };
 
 struct acpi_atsr_unit {
     struct dmar_scope scope;            /* must be first member of struct */
     struct list_head list;
+    u16    segment;
     u8     all_ports:1;
 };
 
@@ -84,7 +87,7 @@ struct acpi_rhsa_unit {
                  idx < rmrr->scope.devices_cnt; idx++)
 
 struct acpi_drhd_unit * acpi_find_matched_drhd_unit(struct pci_dev *pdev);
-struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u8 bus, u8 devfn);
+struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u16 seg, u8 bus, u8 devfn);
 
 #define DMAR_TYPE 1
 #define RMRR_TYPE 2
@@ -114,7 +117,7 @@ void *map_to_nocache_virt(int nr_iommus,
 
 int vtd_hw_check(void);
 void disable_pmr(struct iommu *iommu);
-int is_usb_device(u8 bus, u8 devfn);
+int is_usb_device(u16 seg, u8 bus, u8 devfn);
 int is_igd_drhd(struct acpi_drhd_unit *drhd);
 
 #endif /* _DMAR_H_ */
xen/drivers/passthrough/vtd/iommu.c +53 -37

249 lines not on this page · raw message

xen/drivers/passthrough/vtd/utils.c +4 -3
@@ -32,7 +32,7 @@
 #include <asm/io_apic.h>
 #endif
 
-int is_usb_device(u8 bus, u8 devfn)
+int is_usb_device(u16 seg, u8 bus, u8 devfn)
 {
     u16 class = pci_conf_read16(bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
                                 PCI_CLASS_DEVICE);
@@ -106,8 +106,9 @@ void print_vtd_entries(struct iommu *iom
     u64 *l, val;
     u32 l_index, level;
 
-    printk("print_vtd_entries: iommu = %p bdf = %x:%x.%x gmfn = %"PRIx64"\n",
-           iommu, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), gmfn);
+    printk("print_vtd_entries: iommu %p dev %04x:%02x:%02x.%u gmfn %"PRIx64"\n",
+           iommu, iommu->intel->drhd->segment, bus,
+           PCI_SLOT(devfn), PCI_FUNC(devfn), gmfn);
 
     if ( iommu->root_maddr == 0 )
     {
xen/drivers/passthrough/vtd/x86/ats.c +1 -1
@@ -104,7 +104,7 @@ int ats_device(int seg, int bus, int dev
          !ecap_dev_iotlb(drhd->iommu->ecap) )
         return 0;
 
-    if ( !acpi_find_matched_atsr_unit(bus, devfn) )
+    if ( !acpi_find_matched_atsr_unit(seg, bus, devfn) )
         return 0;
 
     ats_drhd = find_ats_dev_drhd(drhd->iommu);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel