diff options
author | Joerg Roedel <jroedel@suse.de> | 2016-07-08 05:47:22 -0400 |
---|---|---|
committer | Joerg Roedel <jroedel@suse.de> | 2016-07-13 06:48:35 -0400 |
commit | f37f7f33d561901d599e98a72bbf44af1f162732 (patch) | |
tree | 2e6a3a9faf832931f46cc353fabe84cc46c9bb04 /drivers/iommu/amd_iommu.c | |
parent | bb279475db4d0bb07e4dbc99e060362b9f3b5093 (diff) |
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>
Diffstat (limited to 'drivers/iommu/amd_iommu.c')
-rw-r--r-- | drivers/iommu/amd_iommu.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index c0b2f4fc6bfc..281cacbd5816 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c | |||
@@ -2252,6 +2252,17 @@ static void update_domain(struct protection_domain *domain) | |||
2252 | domain->updated = false; | 2252 | domain->updated = false; |
2253 | } | 2253 | } |
2254 | 2254 | ||
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 | } | ||
2255 | /* | 2266 | /* |
2256 | * This function contains common code for mapping of a physically | 2267 | * This function contains common code for mapping of a physically |
2257 | * contiguous memory region into DMA address space. It is used by all | 2268 | * 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 | struct dma_ops_domain *dma_dom, | 2273 | struct dma_ops_domain *dma_dom, |
2263 | phys_addr_t paddr, | 2274 | phys_addr_t paddr, |
2264 | size_t size, | 2275 | size_t size, |
2265 | int direction, | 2276 | enum dma_data_direction direction, |
2266 | u64 dma_mask) | 2277 | u64 dma_mask) |
2267 | { | 2278 | { |
2268 | dma_addr_t offset = paddr & ~PAGE_MASK; | 2279 | dma_addr_t offset = paddr & ~PAGE_MASK; |
@@ -2278,12 +2289,7 @@ static dma_addr_t __map_single(struct device *dev, | |||
2278 | if (address == DMA_ERROR_CODE) | 2289 | if (address == DMA_ERROR_CODE) |
2279 | goto out; | 2290 | goto out; |
2280 | 2291 | ||
2281 | if (direction == DMA_TO_DEVICE) | 2292 | prot = dir2prot(direction); |
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; | ||
2287 | 2293 | ||
2288 | start = address; | 2294 | start = address; |
2289 | for (i = 0; i < pages; ++i) { | 2295 | for (i = 0; i < pages; ++i) { |