diff options
author | Alex Williamson <alex.williamson@redhat.com> | 2012-10-09 00:49:54 -0400 |
---|---|---|
committer | Joerg Roedel <joerg.roedel@amd.com> | 2012-10-24 11:30:10 -0400 |
commit | ce7ac4abf2401dfdcb1ac4c7277dab8ed90c8788 (patch) | |
tree | bf3945a5f0d8d0ba311bab4aac0d64b92598aa2f /drivers/iommu | |
parent | 2bff6a508eb2ba8b341c20db3099e050e5496e3d (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')
-rw-r--r-- | drivers/iommu/amd_iommu.c | 30 |
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) | |||
325 | return dma_pdev; | 325 | return dma_pdev; |
326 | } | 326 | } |
327 | 327 | ||
328 | static int use_pdev_iommu_group(struct pci_dev *pdev, struct device *dev) | ||
329 | { | ||
330 | struct iommu_group *group = iommu_group_get(&pdev->dev); | ||
331 | int ret; | ||
332 | |||
333 | if (!group) { | ||
334 | group = iommu_group_alloc(); | ||
335 | if (IS_ERR(group)) | ||
336 | return PTR_ERR(group); | ||
337 | |||
338 | WARN_ON(&pdev->dev != dev); | ||
339 | } | ||
340 | |||
341 | ret = iommu_group_add_device(group, dev); | ||
342 | iommu_group_put(group); | ||
343 | return ret; | ||
344 | } | ||
345 | |||
328 | static int init_iommu_group(struct device *dev) | 346 | static int init_iommu_group(struct device *dev) |
329 | { | 347 | { |
330 | struct iommu_dev_data *dev_data; | 348 | struct iommu_dev_data *dev_data; |
@@ -353,18 +371,8 @@ static int init_iommu_group(struct device *dev) | |||
353 | dma_pdev = pci_dev_get(to_pci_dev(dev)); | 371 | dma_pdev = pci_dev_get(to_pci_dev(dev)); |
354 | 372 | ||
355 | dma_pdev = get_isolation_root(dma_pdev); | 373 | dma_pdev = get_isolation_root(dma_pdev); |
356 | group = iommu_group_get(&dma_pdev->dev); | 374 | ret = use_pdev_iommu_group(dma_pdev, dev); |
357 | pci_dev_put(dma_pdev); | 375 | pci_dev_put(dma_pdev); |
358 | if (!group) { | ||
359 | group = iommu_group_alloc(); | ||
360 | if (IS_ERR(group)) | ||
361 | return PTR_ERR(group); | ||
362 | } | ||
363 | |||
364 | ret = iommu_group_add_device(group, dev); | ||
365 | |||
366 | iommu_group_put(group); | ||
367 | |||
368 | return ret; | 376 | return ret; |
369 | } | 377 | } |
370 | 378 | ||