Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <jgg@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/acc255bee358fec9c7da6b2a5904ee50abcd09f1.1757423202.git.leonro@nvidia.com

authored by

Leon Romanovsky and committed by
Marek Szyprowski
f9374de1 513559f7

+11 -4
+11 -4
drivers/iommu/dma-iommu.c
··· 1211 1211 */ 1212 1212 if (dev_use_swiotlb(dev, size, dir) && 1213 1213 iova_unaligned(iovad, phys, size)) { 1214 + if (attrs & DMA_ATTR_MMIO) 1215 + return DMA_MAPPING_ERROR; 1216 + 1214 1217 phys = iommu_dma_map_swiotlb(dev, phys, size, dir, attrs); 1215 1218 if (phys == (phys_addr_t)DMA_MAPPING_ERROR) 1216 1219 return DMA_MAPPING_ERROR; 1217 1220 } 1218 1221 1219 - if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 1222 + if (!coherent && !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO))) 1220 1223 arch_sync_dma_for_device(phys, size, dir); 1221 1224 1222 1225 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)) 1224 1227 swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); 1225 1228 return iova; 1226 1229 } ··· 1231 1228 void iommu_dma_unmap_phys(struct device *dev, dma_addr_t dma_handle, 1232 1229 size_t size, enum dma_data_direction dir, unsigned long attrs) 1233 1230 { 1234 - struct iommu_domain *domain = iommu_get_dma_domain(dev); 1235 1231 phys_addr_t phys; 1236 1232 1237 - phys = iommu_iova_to_phys(domain, dma_handle); 1233 + if (attrs & DMA_ATTR_MMIO) { 1234 + __iommu_dma_unmap(dev, dma_handle, size); 1235 + return; 1236 + } 1237 + 1238 + phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle); 1238 1239 if (WARN_ON(!phys)) 1239 1240 return; 1240 1241