]> www.infradead.org Git - users/hch/misc.git/commitdiff
iommu/dma: implement DMA_ATTR_MMIO for iommu_dma_(un)map_phys()
authorLeon Romanovsky <leonro@nvidia.com>
Tue, 9 Sep 2025 13:27:34 +0000 (16:27 +0300)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 11 Sep 2025 22:18:20 +0000 (00:18 +0200)
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
drivers/iommu/dma-iommu.c

index aea119f32f96531ebeac108caca6b838cea15699..6804aaf034a16fb97feba74a14e46b5d312769f2 100644 (file)
@@ -1211,16 +1211,19 @@ dma_addr_t iommu_dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
         */
        if (dev_use_swiotlb(dev, size, dir) &&
            iova_unaligned(iovad, phys, size)) {
+               if (attrs & DMA_ATTR_MMIO)
+                       return DMA_MAPPING_ERROR;
+
                phys = iommu_dma_map_swiotlb(dev, phys, size, dir, attrs);
                if (phys == (phys_addr_t)DMA_MAPPING_ERROR)
                        return DMA_MAPPING_ERROR;
        }
 
-       if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
+       if (!coherent && !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO)))
                arch_sync_dma_for_device(phys, size, dir);
 
        iova = __iommu_dma_map(dev, phys, size, prot, dma_mask);
-       if (iova == DMA_MAPPING_ERROR)
+       if (iova == DMA_MAPPING_ERROR && !(attrs & DMA_ATTR_MMIO))
                swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs);
        return iova;
 }
@@ -1228,10 +1231,14 @@ dma_addr_t iommu_dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
 void iommu_dma_unmap_phys(struct device *dev, dma_addr_t dma_handle,
                size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
-       struct iommu_domain *domain = iommu_get_dma_domain(dev);
        phys_addr_t phys;
 
-       phys = iommu_iova_to_phys(domain, dma_handle);
+       if (attrs & DMA_ATTR_MMIO) {
+               __iommu_dma_unmap(dev, dma_handle, size);
+               return;
+       }
+
+       phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle);
        if (WARN_ON(!phys))
                return;