aboutsummaryrefslogtreecommitdiff
path: root/drivers/iommu/amd_iommu.c
diff options
context:
space:
mode:
authorAlex Williamson2012-10-08 22:49:54 -0600
committerJoerg Roedel2012-10-24 17:30:10 +0200
commitce7ac4abf2401dfdcb1ac4c7277dab8ed90c8788 (patch)
treebf3945a5f0d8d0ba311bab4aac0d64b92598aa2f /drivers/iommu/amd_iommu.c
parent2bff6a508eb2ba8b341c20db3099e050e5496e3d (diff)
iommu/amd: Split IOMMU group allocation and attach
Add a WARN_ON to make it clear why we don't add dma_pdev->dev to the group we're allocating. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Diffstat (limited to 'drivers/iommu/amd_iommu.c')
-rw-r--r--drivers/iommu/amd_iommu.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 3a00b5ce73ab..7fa97a5e3eaf 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -325,6 +325,24 @@ static struct pci_dev *get_isolation_root(struct pci_dev *pdev)
return dma_pdev;
}
+static int use_pdev_iommu_group(struct pci_dev *pdev, struct device *dev)
+{
+ struct iommu_group *group = iommu_group_get(&pdev->dev);
+ int ret;
+
+ if (!group) {
+ group = iommu_group_alloc();
+ if (IS_ERR(group))
+ return PTR_ERR(group);
+
+ WARN_ON(&pdev->dev != dev);
+ }
+
+ ret = iommu_group_add_device(group, dev);
+ iommu_group_put(group);
+ return ret;
+}
+
static int init_iommu_group(struct device *dev)
{
struct iommu_dev_data *dev_data;
@@ -353,18 +371,8 @@ static int init_iommu_group(struct device *dev)
dma_pdev = pci_dev_get(to_pci_dev(dev));
dma_pdev = get_isolation_root(dma_pdev);
- group = iommu_group_get(&dma_pdev->dev);
+ ret = use_pdev_iommu_group(dma_pdev, dev);
pci_dev_put(dma_pdev);
- if (!group) {
- group = iommu_group_alloc();
- if (IS_ERR(group))
- return PTR_ERR(group);
- }
-
- ret = iommu_group_add_device(group, dev);
-
- iommu_group_put(group);
-
return ret;
}