提交 f37f7f33 编写于 作者: J Joerg Roedel

iommu/amd: Introduce dir2prot() helper

This function converts dma_data_direction to
iommu-protection flags. This will be needed on multiple
places in the code, so this will save some code.
Signed-off-by: NJoerg Roedel <jroedel@suse.de>
上级 bb279475
...@@ -2252,6 +2252,17 @@ static void update_domain(struct protection_domain *domain) ...@@ -2252,6 +2252,17 @@ static void update_domain(struct protection_domain *domain)
domain->updated = false; domain->updated = false;
} }
static int dir2prot(enum dma_data_direction direction)
{
if (direction == DMA_TO_DEVICE)
return IOMMU_PROT_IR;
else if (direction == DMA_FROM_DEVICE)
return IOMMU_PROT_IW;
else if (direction == DMA_BIDIRECTIONAL)
return IOMMU_PROT_IW | IOMMU_PROT_IR;
else
return 0;
}
/* /*
* This function contains common code for mapping of a physically * This function contains common code for mapping of a physically
* contiguous memory region into DMA address space. It is used by all * contiguous memory region into DMA address space. It is used by all
...@@ -2262,7 +2273,7 @@ static dma_addr_t __map_single(struct device *dev, ...@@ -2262,7 +2273,7 @@ static dma_addr_t __map_single(struct device *dev,
struct dma_ops_domain *dma_dom, struct dma_ops_domain *dma_dom,
phys_addr_t paddr, phys_addr_t paddr,
size_t size, size_t size,
int direction, enum dma_data_direction direction,
u64 dma_mask) u64 dma_mask)
{ {
dma_addr_t offset = paddr & ~PAGE_MASK; dma_addr_t offset = paddr & ~PAGE_MASK;
...@@ -2278,12 +2289,7 @@ static dma_addr_t __map_single(struct device *dev, ...@@ -2278,12 +2289,7 @@ static dma_addr_t __map_single(struct device *dev,
if (address == DMA_ERROR_CODE) if (address == DMA_ERROR_CODE)
goto out; goto out;
if (direction == DMA_TO_DEVICE) prot = dir2prot(direction);
prot = IOMMU_PROT_IR;
else if (direction == DMA_FROM_DEVICE)
prot = IOMMU_PROT_IW;
else if (direction == DMA_BIDIRECTIONAL)
prot = IOMMU_PROT_IW | IOMMU_PROT_IR;
start = address; start = address;
for (i = 0; i < pages; ++i) { for (i = 0; i < pages; ++i) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册