diff options
| author | Laura Abbott <lauraa@codeaurora.org> | 2014-08-05 19:16:28 -0700 |
|---|---|---|
| committer | David Keitel <dkeitel@codeaurora.org> | 2016-03-22 11:03:15 -0700 |
| commit | 623c8d195310846a7f9cee1b0a54fecf85c1a2d7 (patch) | |
| tree | 0a6dde200ff870ee4ac18bf69691fd852a05aae3 /include | |
| parent | 416cca9db2a961221ce0d8848fad2ab2ddeb6c30 (diff) | |
dma-mapping: Add dma_remap functions
After getting an allocation from dma_alloc_coherent, there
may be cases where it is neccessary to remap the handle
into the CPU's address space (e.g. no CPU side mapping was
requested at allocation time but now one is needed). Add
APIs to bring a handle into the CPU address space again.
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
[imaund@codeaurora.org: resolved context conflicts and added support
for remap 'no_warn' argument]
Signed-off-by: Ian Maund <imaund@codeaurora.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/asm-generic/dma-mapping-common.h | 3 | ||||
| -rw-r--r-- | include/linux/dma-mapping.h | 35 |
2 files changed, 37 insertions, 1 deletions
diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h index b1bc954eccf3..0b1bd1f9f6c7 100644 --- a/include/asm-generic/dma-mapping-common.h +++ b/include/asm-generic/dma-mapping-common.h @@ -192,7 +192,8 @@ void *dma_common_contiguous_remap(struct page *page, size_t size, void *dma_common_pages_remap(struct page **pages, size_t size, unsigned long vm_flags, pgprot_t prot, const void *caller); -void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags); +void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags, + bool no_warn); /** * dma_mmap_attrs - map a coherent DMA allocation into user space diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 2e551e2d2d03..ccd5d9ddcfc9 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -61,6 +61,10 @@ struct dma_map_ops { int (*mapping_error)(struct device *dev, dma_addr_t dma_addr); int (*dma_supported)(struct device *dev, u64 mask); int (*set_dma_mask)(struct device *dev, u64 mask); + void *(*remap)(struct device *dev, void *cpu_addr, dma_addr_t handle, + size_t size, struct dma_attrs *attrs); + void (*unremap)(struct device *dev, void *remapped_address, + size_t size); #ifdef ARCH_HAS_DMA_GET_REQUIRED_MASK u64 (*get_required_mask)(struct device *dev); #endif @@ -88,6 +92,37 @@ static inline int is_device_dma_capable(struct device *dev) #else #include <asm-generic/dma-mapping-broken.h> #endif +static inline void *dma_remap(struct device *dev, void *cpu_addr, + dma_addr_t dma_handle, size_t size, struct dma_attrs *attrs) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + BUG_ON(!ops); + + if (!ops->remap) { + WARN_ONCE(1, "Remap function not implemented for %pS\n", + ops->remap); + return NULL; + } + + return ops->remap(dev, cpu_addr, dma_handle, size, attrs); +} + + +static inline void dma_unremap(struct device *dev, void *remapped_addr, + size_t size) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + BUG_ON(!ops); + + if (!ops->unremap) { + WARN_ONCE(1, "unremap function not implemented for %pS\n", + ops->unremap); + return; + } + + return ops->unremap(dev, remapped_addr, size); +} + static inline u64 dma_get_mask(struct device *dev) { |
