Skip to content

Commit 97ef952

Browse files
committed
ARM: dma-mapping: add support for DMA_ATTR_SKIP_CPU_SYNC attribute
This patch adds support for DMA_ATTR_SKIP_CPU_SYNC attribute for dma_(un)map_(single,page,sg) functions family. It lets dma mapping clients to create a mapping for the buffer for the given device without performing a CPU cache synchronization. CPU cache synchronization can be skipped for the buffers which it is known that they are already in 'device' domain (CPU caches have been already synchronized or there are only coherent mappings for the buffer). For advanced users only, please use it with care. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com>
1 parent bdf5e48 commit 97ef952

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎arch/arm/mm/dma-mapping.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static dma_addr_t arm_dma_map_page(struct device *dev, struct page *page,
7373
unsigned long offset, size_t size, enum dma_data_direction dir,
7474
struct dma_attrs *attrs)
7575
{
76-
if (!arch_is_coherent())
76+
if (!arch_is_coherent() && !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
7777
__dma_page_cpu_to_dev(page, offset, size, dir);
7878
return pfn_to_dma(dev, page_to_pfn(page)) + offset;
7979
}
@@ -96,7 +96,7 @@ static void arm_dma_unmap_page(struct device *dev, dma_addr_t handle,
9696
size_t size, enum dma_data_direction dir,
9797
struct dma_attrs *attrs)
9898
{
99-
if (!arch_is_coherent())
99+
if (!arch_is_coherent() && !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
100100
__dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, handle)),
101101
handle & ~PAGE_MASK, size, dir);
102102
}
@@ -1207,7 +1207,7 @@ static int arm_iommu_get_sgtable(struct device *dev, struct sg_table *sgt,
12071207
*/
12081208
static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
12091209
size_t size, dma_addr_t *handle,
1210-
enum dma_data_direction dir)
1210+
enum dma_data_direction dir, struct dma_attrs *attrs)
12111211
{
12121212
struct dma_iommu_mapping *mapping = dev->archdata.mapping;
12131213
dma_addr_t iova, iova_base;
@@ -1226,7 +1226,8 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
12261226
phys_addr_t phys = page_to_phys(sg_page(s));
12271227
unsigned int len = PAGE_ALIGN(s->offset + s->length);
12281228

1229-
if (!arch_is_coherent())
1229+
if (!arch_is_coherent() &&
1230+
!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
12301231
__dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);
12311232

12321233
ret = iommu_map(mapping->domain, iova, phys, len, 0);
@@ -1273,7 +1274,7 @@ int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
12731274

12741275
if (s->offset || (size & ~PAGE_MASK) || size + s->length > max) {
12751276
if (__map_sg_chunk(dev, start, size, &dma->dma_address,
1276-
dir) < 0)
1277+
dir, attrs) < 0)
12771278
goto bad_mapping;
12781279

12791280
dma->dma_address += offset;
@@ -1286,7 +1287,7 @@ int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
12861287
}
12871288
size += s->length;
12881289
}
1289-
if (__map_sg_chunk(dev, start, size, &dma->dma_address, dir) < 0)
1290+
if (__map_sg_chunk(dev, start, size, &dma->dma_address, dir, attrs) < 0)
12901291
goto bad_mapping;
12911292

12921293
dma->dma_address += offset;
@@ -1320,7 +1321,8 @@ void arm_iommu_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
13201321
if (sg_dma_len(s))
13211322
__iommu_remove_mapping(dev, sg_dma_address(s),
13221323
sg_dma_len(s));
1323-
if (!arch_is_coherent())
1324+
if (!arch_is_coherent() &&
1325+
!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
13241326
__dma_page_dev_to_cpu(sg_page(s), s->offset,
13251327
s->length, dir);
13261328
}
@@ -1382,7 +1384,7 @@ static dma_addr_t arm_iommu_map_page(struct device *dev, struct page *page,
13821384
dma_addr_t dma_addr;
13831385
int ret, len = PAGE_ALIGN(size + offset);
13841386

1385-
if (!arch_is_coherent())
1387+
if (!arch_is_coherent() && !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
13861388
__dma_page_cpu_to_dev(page, offset, size, dir);
13871389

13881390
dma_addr = __alloc_iova(mapping, len);
@@ -1421,7 +1423,7 @@ static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle,
14211423
if (!iova)
14221424
return;
14231425

1424-
if (!arch_is_coherent())
1426+
if (!arch_is_coherent() && !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
14251427
__dma_page_dev_to_cpu(page, offset, size, dir);
14261428

14271429
iommu_unmap(mapping->domain, iova, len);

0 commit comments

Comments
 (0)