aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/base/dma-buf.c34
-rw-r--r--include/linux/dma-buf.h14
2 files changed, 48 insertions, 0 deletions
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c
index 7cfb405b1ad5..d43d80256fda 100644
--- a/drivers/base/dma-buf.c
+++ b/drivers/base/dma-buf.c
@@ -468,3 +468,37 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
468 return dmabuf->ops->mmap(dmabuf, vma); 468 return dmabuf->ops->mmap(dmabuf, vma);
469} 469}
470EXPORT_SYMBOL_GPL(dma_buf_mmap); 470EXPORT_SYMBOL_GPL(dma_buf_mmap);
471
472/**
473 * dma_buf_vmap - Create virtual mapping for the buffer object into kernel address space. Same restrictions as for vmap and friends apply.
474 * @dma_buf: [in] buffer to vmap
475 *
476 * This call may fail due to lack of virtual mapping address space.
477 * These calls are optional in drivers. The intended use for them
478 * is for mapping objects linear in kernel space for high use objects.
479 * Please attempt to use kmap/kunmap before thinking about these interfaces.
480 */
481void *dma_buf_vmap(struct dma_buf *dmabuf)
482{
483 if (WARN_ON(!dmabuf))
484 return NULL;
485
486 if (dmabuf->ops->vmap)
487 return dmabuf->ops->vmap(dmabuf);
488 return NULL;
489}
490EXPORT_SYMBOL_GPL(dma_buf_vmap);
491
492/**
493 * dma_buf_vunmap - Unmap a vmap obtained by dma_buf_vmap.
494 * @dma_buf: [in] buffer to vmap
495 */
496void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr)
497{
498 if (WARN_ON(!dmabuf))
499 return;
500
501 if (dmabuf->ops->vunmap)
502 dmabuf->ops->vunmap(dmabuf, vaddr);
503}
504EXPORT_SYMBOL_GPL(dma_buf_vunmap);
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index 1f78d1594cc7..a02b1ff6488e 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -98,6 +98,9 @@ struct dma_buf_ops {
98 void (*kunmap)(struct dma_buf *, unsigned long, void *); 98 void (*kunmap)(struct dma_buf *, unsigned long, void *);
99 99
100 int (*mmap)(struct dma_buf *, struct vm_area_struct *vma); 100 int (*mmap)(struct dma_buf *, struct vm_area_struct *vma);
101
102 void *(*vmap)(struct dma_buf *);
103 void (*vunmap)(struct dma_buf *, void *vaddr);
101}; 104};
102 105
103/** 106/**
@@ -176,6 +179,8 @@ void dma_buf_kunmap(struct dma_buf *, unsigned long, void *);
176 179
177int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, 180int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *,
178 unsigned long); 181 unsigned long);
182void *dma_buf_vmap(struct dma_buf *);
183void dma_buf_vunmap(struct dma_buf *, void *vaddr);
179#else 184#else
180 185
181static inline struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, 186static inline struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
@@ -264,6 +269,15 @@ static inline int dma_buf_mmap(struct dma_buf *dmabuf,
264{ 269{
265 return -ENODEV; 270 return -ENODEV;
266} 271}
272
273static inline void *dma_buf_vmap(struct dma_buf *dmabuf)
274{
275 return NULL;
276}
277
278static inline void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr)
279{
280}
267#endif /* CONFIG_DMA_SHARED_BUFFER */ 281#endif /* CONFIG_DMA_SHARED_BUFFER */
268 282
269#endif /* __DMA_BUF_H__ */ 283#endif /* __DMA_BUF_H__ */