Skip to content

Commit

Permalink
arch/nios2: add option to skip DMA sync as a part of map and unmap
Browse files Browse the repository at this point in the history
This change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to
avoid invoking cache line invalidation if the driver will just handle it
via a sync_for_cpu or sync_for_device call.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Alexander Duyck <[email protected]>
Reviewed-by: Tobias Klauser <[email protected]>
Cc: Ley Foon Tan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Alexander Duyck authored and torvalds committed Dec 15, 2016
1 parent 9f318d4 commit abdf479
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions arch/nios2/mm/dma-mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ static int nios2_dma_map_sg(struct device *dev, struct scatterlist *sg,
int i;

for_each_sg(sg, sg, nents, i) {
void *addr;
void *addr = sg_virt(sg);

addr = sg_virt(sg);
if (addr) {
__dma_sync_for_device(addr, sg->length, direction);
sg->dma_address = sg_phys(sg);
}
if (!addr)
continue;

sg->dma_address = sg_phys(sg);

if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
continue;

__dma_sync_for_device(addr, sg->length, direction);
}

return nents;
Expand All @@ -117,15 +121,18 @@ static dma_addr_t nios2_dma_map_page(struct device *dev, struct page *page,
{
void *addr = page_address(page) + offset;

__dma_sync_for_device(addr, size, direction);
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
__dma_sync_for_device(addr, size, direction);

return page_to_phys(page) + offset;
}

static void nios2_dma_unmap_page(struct device *dev, dma_addr_t dma_address,
size_t size, enum dma_data_direction direction,
unsigned long attrs)
{
__dma_sync_for_cpu(phys_to_virt(dma_address), size, direction);
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
__dma_sync_for_cpu(phys_to_virt(dma_address), size, direction);
}

static void nios2_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
Expand All @@ -138,6 +145,9 @@ static void nios2_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
if (direction == DMA_TO_DEVICE)
return;

if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
return;

for_each_sg(sg, sg, nhwentries, i) {
addr = sg_virt(sg);
if (addr)
Expand Down

0 comments on commit abdf479

Please sign in to comment.