return 0;
}
-struct acpi_drhd_unit * acpi_find_matched_drhd_unit(struct pci_dev *pdev)
+struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *pdev)
{
u8 bus, devfn;
struct acpi_drhd_unit *drhd;
return include_all;
}
-struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u16 seg, u8 bus, u8 devfn)
+struct acpi_atsr_unit *acpi_find_matched_atsr_unit(const struct pci_dev *pdev)
{
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 )
+ if ( atsr->segment != pdev->seg )
continue;
- if ( test_bit(bus, atsr->scope.buses) )
+ if ( test_bit(pdev->bus, atsr->scope.buses) )
return atsr;
if ( atsr->all_ports )
for (idx = 0; (bdf = rmrr->scope.devices[idx]) && \
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(u16 seg, u8 bus, u8 devfn);
+struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *);
+struct acpi_atsr_unit *acpi_find_matched_atsr_unit(const struct pci_dev *);
#define DMAR_TYPE 1
#define RMRR_TYPE 2
struct acpi_drhd_unit * find_ats_dev_drhd(struct iommu *iommu);
-int ats_device(int seg, int bus, int devfn);
+int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *);
int enable_ats_device(int seg, int bus, int devfn);
void disable_ats_device(int seg, int bus, int devfn);
-int invalidate_ats_tcs(struct iommu *iommu);
int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
u64 addr, unsigned int size_order, u64 type);
return NULL;
}
-static inline int ats_device(int seg, int bus, int devfn)
+static inline int ats_device(const struct pci_dev *pdev,
+ const struct acpi_drhd_unit *drhd)
{
return 0;
}
domain->domain_id, seg, bus,
PCI_SLOT(devfn), PCI_FUNC(devfn));
ret = domain_context_mapping_one(domain, drhd->iommu, bus, devfn);
- if ( !ret && ats_device(seg, bus, devfn) )
+ if ( !ret && ats_device(pdev, drhd) > 0 )
enable_ats_device(seg, bus, devfn);
break;
domain->domain_id, seg, bus,
PCI_SLOT(devfn), PCI_FUNC(devfn));
ret = domain_context_unmap_one(domain, iommu, bus, devfn);
- if ( !ret && ats_device(seg, bus, devfn) )
+ if ( !ret && ats_device(pdev, drhd) > 0 )
disable_ats_device(seg, bus, devfn);
break;
return NULL;
}
-int ats_device(int seg, int bus, int devfn)
+int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd)
{
- struct acpi_drhd_unit *drhd, *ats_drhd, *new_drhd;
- struct pci_dev *pdev;
- int pos = 0;
+ struct acpi_drhd_unit *ats_drhd;
+ int pos;
if ( !ats_enabled || !iommu_qinval )
return 0;
- pdev = pci_get_pdev(seg, bus, devfn);
- if ( !pdev )
- return 0;
-
- drhd = acpi_find_matched_drhd_unit(pdev);
- if ( !drhd )
- return 0;
-
if ( !ecap_queued_inval(drhd->iommu->ecap) ||
!ecap_dev_iotlb(drhd->iommu->ecap) )
return 0;
- if ( !acpi_find_matched_atsr_unit(seg, bus, devfn) )
+ if ( !acpi_find_matched_atsr_unit(pdev) )
return 0;
ats_drhd = find_ats_dev_drhd(drhd->iommu);
- pos = pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS);
+ pos = pci_find_ext_capability(pdev->seg, pdev->bus, pdev->devfn,
+ PCI_EXT_CAP_ID_ATS);
if ( pos && (ats_drhd == NULL) )
{
- new_drhd = xmalloc(struct acpi_drhd_unit);
- if ( !new_drhd )
- return 0;
- memcpy(new_drhd, drhd, sizeof(struct acpi_drhd_unit));
- list_add_tail(&new_drhd->list, &ats_dev_drhd_units);
+ ats_drhd = xmalloc(struct acpi_drhd_unit);
+ if ( !ats_drhd )
+ return -ENOMEM;
+ *ats_drhd = *drhd;
+ list_add_tail(&ats_drhd->list, &ats_dev_drhd_units);
}
return pos;
}