Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6b610980 authored by Qingqing Zhou's avatar Qingqing Zhou
Browse files

arm: dma-mapping.c: add cpu sync in map_sg and unmap_sg



Currently for 32-bit the dma operations including map_sg
and unmap_sg don't have cpu sync, so after several times'
map and unmap, the data may be not right.

This is caused by 'commit 14072e39 ("arm: dma-mapping:
map sg lists into the SMMU as virtually contiguous")'.

Change-Id: I6b749f5111aa937f7800050ae454fe209b73c5d1
Signed-off-by: default avatarQingqing Zhou <qqzhou@codeaurora.org>
parent c7849b7a
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -130,6 +130,10 @@ static void *arm_dma_remap(struct device *dev, void *cpu_addr,
static void arm_dma_unremap(struct device *dev, void *remapped_addr,
				size_t size);

static void arm_iommu_sync_sg_for_device(struct device *dev,
		struct scatterlist *sg, int nents, enum dma_data_direction dir);
static void arm_iommu_sync_sg_for_cpu(struct device *dev,
		struct scatterlist *sg, int nents, enum dma_data_direction dir);

static pgprot_t __get_dma_pgprot(unsigned long attrs, pgprot_t prot,
				 bool coherent)
@@ -1976,6 +1980,9 @@ int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg,
		current_offset += s->length;
	}

	if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
		arm_iommu_sync_sg_for_device(dev, sg, nents, dir);

	return nents;
}

@@ -2031,6 +2038,9 @@ void arm_iommu_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
	unsigned int total_length = sg_dma_len(sg);
	dma_addr_t iova = sg_dma_address(sg);

	if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
		arm_iommu_sync_sg_for_cpu(dev, sg, nents, dir);

	total_length = PAGE_ALIGN((iova & ~PAGE_MASK) + total_length);
	iova &= PAGE_MASK;

@@ -2045,8 +2055,8 @@ void arm_iommu_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
 * @nents: number of buffers to map (returned from dma_map_sg)
 * @dir: DMA transfer direction (same as was passed to dma_map_sg)
 */
void arm_iommu_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
			int nents, enum dma_data_direction dir)
static void arm_iommu_sync_sg_for_cpu(struct device *dev,
		struct scatterlist *sg, int nents, enum dma_data_direction dir)
{
	struct scatterlist *s;
	int i;
@@ -2069,8 +2079,8 @@ void arm_iommu_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 * @nents: number of buffers to map (returned from dma_map_sg)
 * @dir: DMA transfer direction (same as was passed to dma_map_sg)
 */
void arm_iommu_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
			int nents, enum dma_data_direction dir)
static void arm_iommu_sync_sg_for_device(struct device *dev,
		struct scatterlist *sg, int nents, enum dma_data_direction dir)
{
	struct scatterlist *s;
	int i;