Skip to content

Commit f37f7f3

Browse files
committed
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: Joerg Roedel <jroedel@suse.de>
1 parent bb27947 commit f37f7f3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

drivers/iommu/amd_iommu.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,17 @@ static void update_domain(struct protection_domain *domain)
22522252
domain->updated = false;
22532253
}
22542254

2255+
static int dir2prot(enum dma_data_direction direction)
2256+
{
2257+
if (direction == DMA_TO_DEVICE)
2258+
return IOMMU_PROT_IR;
2259+
else if (direction == DMA_FROM_DEVICE)
2260+
return IOMMU_PROT_IW;
2261+
else if (direction == DMA_BIDIRECTIONAL)
2262+
return IOMMU_PROT_IW | IOMMU_PROT_IR;
2263+
else
2264+
return 0;
2265+
}
22552266
/*
22562267
* This function contains common code for mapping of a physically
22572268
* 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,
22622273
struct dma_ops_domain *dma_dom,
22632274
phys_addr_t paddr,
22642275
size_t size,
2265-
int direction,
2276+
enum dma_data_direction direction,
22662277
u64 dma_mask)
22672278
{
22682279
dma_addr_t offset = paddr & ~PAGE_MASK;
@@ -2278,12 +2289,7 @@ static dma_addr_t __map_single(struct device *dev,
22782289
if (address == DMA_ERROR_CODE)
22792290
goto out;
22802291

2281-
if (direction == DMA_TO_DEVICE)
2282-
prot = IOMMU_PROT_IR;
2283-
else if (direction == DMA_FROM_DEVICE)
2284-
prot = IOMMU_PROT_IW;
2285-
else if (direction == DMA_BIDIRECTIONAL)
2286-
prot = IOMMU_PROT_IW | IOMMU_PROT_IR;
2292+
prot = dir2prot(direction);
22872293

22882294
start = address;
22892295
for (i = 0; i < pages; ++i) {

0 commit comments

Comments
 (0)