summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2008-12-02 19:34:11 +0100
committerJoerg Roedel <joerg.roedel@amd.com>2009-01-03 14:11:56 +0100
commit01106066a6900b518debe990ddaadf376d433bd6 (patch)
tree29d3a651a6c0d50fe372df4585e20b6322ffd2e2
parent684f2888847b896faafed87ce4733501d2cc283c (diff)
downloadop-kernel-dev-01106066a6900b518debe990ddaadf376d433bd6.zip
op-kernel-dev-01106066a6900b518debe990ddaadf376d433bd6.tar.gz
AMD IOMMU: add device attach function for IOMMU API
Impact: add a generic function to attach devices to protection domains Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
-rw-r--r--arch/x86/kernel/amd_iommu.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index ef9b309..2f7c0b3 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -1683,4 +1683,39 @@ static void amd_iommu_detach_device(struct iommu_domain *dom,
iommu_completion_wait(iommu);
}
+static int amd_iommu_attach_device(struct iommu_domain *dom,
+ struct device *dev)
+{
+ struct protection_domain *domain = dom->priv;
+ struct protection_domain *old_domain;
+ struct amd_iommu *iommu;
+ struct pci_dev *pdev;
+ u16 devid;
+
+ if (dev->bus != &pci_bus_type)
+ return -EINVAL;
+
+ pdev = to_pci_dev(dev);
+
+ devid = calc_devid(pdev->bus->number, pdev->devfn);
+
+ if (devid >= amd_iommu_last_bdf ||
+ devid != amd_iommu_alias_table[devid])
+ return -EINVAL;
+
+ iommu = amd_iommu_rlookup_table[devid];
+ if (!iommu)
+ return -EINVAL;
+
+ old_domain = domain_for_device(devid);
+ if (old_domain)
+ return -EBUSY;
+
+ attach_device(iommu, domain, devid);
+
+ iommu_completion_wait(iommu);
+
+ return 0;
+}
+
#endif
OpenPOWER on IntegriCloud