Skip to content

Commit 0518a3a

Browse files
committed
x86/amd-iommu: Add function to complete a tlb flush
This patch adds a function to the AMD IOMMU driver which completes all queued commands an all IOMMUs a specific domain has devices attached on. This is required in a later patch when per-domain flushing is implemented. Signed-off-by: Joerg Roedel <[email protected]>
1 parent c459611 commit 0518a3a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

arch/x86/kernel/amd_iommu.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,22 @@ static int iommu_completion_wait(struct amd_iommu *iommu)
376376
return 0;
377377
}
378378

379+
static void iommu_flush_complete(struct protection_domain *domain)
380+
{
381+
int i;
382+
383+
for (i = 0; i < amd_iommus_present; ++i) {
384+
if (!domain->dev_iommu[i])
385+
continue;
386+
387+
/*
388+
* Devices of this domain are behind this IOMMU
389+
* We need to wait for completion of all commands.
390+
*/
391+
iommu_completion_wait(amd_iommus[i]);
392+
}
393+
}
394+
379395
/*
380396
* Command send function for invalidating a device table entry
381397
*/
@@ -1758,7 +1774,7 @@ static dma_addr_t map_page(struct device *dev, struct page *page,
17581774
if (addr == DMA_ERROR_CODE)
17591775
goto out;
17601776

1761-
iommu_completion_wait(iommu);
1777+
iommu_flush_complete(domain);
17621778

17631779
out:
17641780
spin_unlock_irqrestore(&domain->lock, flags);
@@ -1791,7 +1807,7 @@ static void unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
17911807

17921808
__unmap_single(iommu, domain->priv, dma_addr, size, dir);
17931809

1794-
iommu_completion_wait(iommu);
1810+
iommu_flush_complete(domain);
17951811

17961812
spin_unlock_irqrestore(&domain->lock, flags);
17971813
}
@@ -1863,7 +1879,7 @@ static int map_sg(struct device *dev, struct scatterlist *sglist,
18631879
goto unmap;
18641880
}
18651881

1866-
iommu_completion_wait(iommu);
1882+
iommu_flush_complete(domain);
18671883

18681884
out:
18691885
spin_unlock_irqrestore(&domain->lock, flags);
@@ -1914,7 +1930,7 @@ static void unmap_sg(struct device *dev, struct scatterlist *sglist,
19141930
s->dma_address = s->dma_length = 0;
19151931
}
19161932

1917-
iommu_completion_wait(iommu);
1933+
iommu_flush_complete(domain);
19181934

19191935
spin_unlock_irqrestore(&domain->lock, flags);
19201936
}
@@ -1969,7 +1985,7 @@ static void *alloc_coherent(struct device *dev, size_t size,
19691985
goto out_free;
19701986
}
19711987

1972-
iommu_completion_wait(iommu);
1988+
iommu_flush_complete(domain);
19731989

19741990
spin_unlock_irqrestore(&domain->lock, flags);
19751991

@@ -2010,7 +2026,7 @@ static void free_coherent(struct device *dev, size_t size,
20102026

20112027
__unmap_single(iommu, domain->priv, dma_addr, size, DMA_BIDIRECTIONAL);
20122028

2013-
iommu_completion_wait(iommu);
2029+
iommu_flush_complete(domain);
20142030

20152031
spin_unlock_irqrestore(&domain->lock, flags);
20162032

0 commit comments

Comments
 (0)