Skip to content

Commit f9374de

Browse files
rleonmszyprow
authored andcommitted
iommu/dma: implement DMA_ATTR_MMIO for iommu_dma_(un)map_phys()
Make iommu_dma_map_phys() and iommu_dma_unmap_phys() respect DMA_ATTR_MMIO. DMA_ATTR_MMIO makes the functions behave the same as iommu_dma_(un)map_resource(): - No swiotlb is possible - No cache flushing is done (ATTR_MMIO should not be cached memory) - prot for iommu_map() has IOMMU_MMIO not IOMMU_CACHE This is preparation for replacing iommu_dma_map_resource() callers with iommu_dma_map_phys(DMA_ATTR_MMIO) and removing iommu_dma_(un)map_resource(). Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Marek Szyprowski <[email protected]> Link: https://lore.kernel.org/r/acc255bee358fec9c7da6b2a5904ee50abcd09f1.1757423202.git.leonro@nvidia.com
1 parent 513559f commit f9374de

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,27 +1211,34 @@ dma_addr_t iommu_dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
12111211
*/
12121212
if (dev_use_swiotlb(dev, size, dir) &&
12131213
iova_unaligned(iovad, phys, size)) {
1214+
if (attrs & DMA_ATTR_MMIO)
1215+
return DMA_MAPPING_ERROR;
1216+
12141217
phys = iommu_dma_map_swiotlb(dev, phys, size, dir, attrs);
12151218
if (phys == (phys_addr_t)DMA_MAPPING_ERROR)
12161219
return DMA_MAPPING_ERROR;
12171220
}
12181221

1219-
if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
1222+
if (!coherent && !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO)))
12201223
arch_sync_dma_for_device(phys, size, dir);
12211224

12221225
iova = __iommu_dma_map(dev, phys, size, prot, dma_mask);
1223-
if (iova == DMA_MAPPING_ERROR)
1226+
if (iova == DMA_MAPPING_ERROR && !(attrs & DMA_ATTR_MMIO))
12241227
swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs);
12251228
return iova;
12261229
}
12271230

12281231
void iommu_dma_unmap_phys(struct device *dev, dma_addr_t dma_handle,
12291232
size_t size, enum dma_data_direction dir, unsigned long attrs)
12301233
{
1231-
struct iommu_domain *domain = iommu_get_dma_domain(dev);
12321234
phys_addr_t phys;
12331235

1234-
phys = iommu_iova_to_phys(domain, dma_handle);
1236+
if (attrs & DMA_ATTR_MMIO) {
1237+
__iommu_dma_unmap(dev, dma_handle, size);
1238+
return;
1239+
}
1240+
1241+
phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle);
12351242
if (WARN_ON(!phys))
12361243
return;
12371244

0 commit comments

Comments
 (0)