Skip to content

Commit ba0a062

Browse files
committed
Merge branch 'fixes-for-v3.12' of git://git.linaro.org/people/mszyprowski/linux-dma-mapping
Pull DMA-mapping fix from Marek Szyprowski: "A bugfix for the IOMMU-based implementation of dma-mapping subsystem for ARM architecture" * 'fixes-for-v3.12' of git://git.linaro.org/people/mszyprowski/linux-dma-mapping: ARM: dma-mapping: Always pass proper prot flags to iommu_map()
2 parents b83aea8 + c9b2499 commit ba0a062

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,8 @@ __iommu_create_mapping(struct device *dev, struct page **pages, size_t size)
12321232
break;
12331233

12341234
len = (j - i) << PAGE_SHIFT;
1235-
ret = iommu_map(mapping->domain, iova, phys, len, 0);
1235+
ret = iommu_map(mapping->domain, iova, phys, len,
1236+
IOMMU_READ|IOMMU_WRITE);
12361237
if (ret < 0)
12371238
goto fail;
12381239
iova += len;
@@ -1431,6 +1432,27 @@ static int arm_iommu_get_sgtable(struct device *dev, struct sg_table *sgt,
14311432
GFP_KERNEL);
14321433
}
14331434

1435+
static int __dma_direction_to_prot(enum dma_data_direction dir)
1436+
{
1437+
int prot;
1438+
1439+
switch (dir) {
1440+
case DMA_BIDIRECTIONAL:
1441+
prot = IOMMU_READ | IOMMU_WRITE;
1442+
break;
1443+
case DMA_TO_DEVICE:
1444+
prot = IOMMU_READ;
1445+
break;
1446+
case DMA_FROM_DEVICE:
1447+
prot = IOMMU_WRITE;
1448+
break;
1449+
default:
1450+
prot = 0;
1451+
}
1452+
1453+
return prot;
1454+
}
1455+
14341456
/*
14351457
* Map a part of the scatter-gather list into contiguous io address space
14361458
*/
@@ -1444,6 +1466,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
14441466
int ret = 0;
14451467
unsigned int count;
14461468
struct scatterlist *s;
1469+
int prot;
14471470

14481471
size = PAGE_ALIGN(size);
14491472
*handle = DMA_ERROR_CODE;
@@ -1460,7 +1483,9 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
14601483
!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
14611484
__dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);
14621485

1463-
ret = iommu_map(mapping->domain, iova, phys, len, 0);
1486+
prot = __dma_direction_to_prot(dir);
1487+
1488+
ret = iommu_map(mapping->domain, iova, phys, len, prot);
14641489
if (ret < 0)
14651490
goto fail;
14661491
count += len >> PAGE_SHIFT;
@@ -1665,19 +1690,7 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *p
16651690
if (dma_addr == DMA_ERROR_CODE)
16661691
return dma_addr;
16671692

1668-
switch (dir) {
1669-
case DMA_BIDIRECTIONAL:
1670-
prot = IOMMU_READ | IOMMU_WRITE;
1671-
break;
1672-
case DMA_TO_DEVICE:
1673-
prot = IOMMU_READ;
1674-
break;
1675-
case DMA_FROM_DEVICE:
1676-
prot = IOMMU_WRITE;
1677-
break;
1678-
default:
1679-
prot = 0;
1680-
}
1693+
prot = __dma_direction_to_prot(dir);
16811694

16821695
ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len, prot);
16831696
if (ret < 0)

0 commit comments

Comments
 (0)