Skip to content

Commit

Permalink
dma-buf: add vmap interface
Browse files Browse the repository at this point in the history
  • Loading branch information
airlied committed Apr 17, 2012
1 parent e816b57 commit 4d33ccb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
29 changes: 29 additions & 0 deletions drivers/base/dma-buf.c
Expand Up @@ -406,3 +406,32 @@ void dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long page_num,
dmabuf->ops->kunmap(dmabuf, page_num, vaddr);
}
EXPORT_SYMBOL_GPL(dma_buf_kunmap);

/**
* dma_buf_vmap - Create virtual mapping for the buffer object into kernel address space. The same restrictions as for vmap and friends apply.
* @dma_buf: [in] buffer to vmap
*
* This call may fail due to lack of virtual mapping address space.
*/
void *dma_buf_vmap(struct dma_buf *dmabuf)
{
WARN_ON(!dmabuf);

if (dmabuf->ops->vmap)
return dmabuf->ops->vmap(dmabuf);
return NULL;
}
EXPORT_SYMBOL(dma_buf_vmap);

/**
* dma_buf_vunmap - Unmap a page obtained by dma_buf_vmap.
* @dma_buf: [in] buffer to vmap
*/
void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr)
{
WARN_ON(!dmabuf);

if (dmabuf->ops->vunmap)
dmabuf->ops->vunmap(dmabuf, vaddr);
}
EXPORT_SYMBOL(dma_buf_vunmap);
14 changes: 14 additions & 0 deletions include/linux/dma-buf.h
Expand Up @@ -92,6 +92,9 @@ struct dma_buf_ops {
void (*kunmap_atomic)(struct dma_buf *, unsigned long, void *);
void *(*kmap)(struct dma_buf *, unsigned long);
void (*kunmap)(struct dma_buf *, unsigned long, void *);

void *(*vmap)(struct dma_buf *);
void (*vunmap)(struct dma_buf *, void *vaddr);
};

/**
Expand Down Expand Up @@ -167,6 +170,9 @@ void *dma_buf_kmap_atomic(struct dma_buf *, unsigned long);
void dma_buf_kunmap_atomic(struct dma_buf *, unsigned long, void *);
void *dma_buf_kmap(struct dma_buf *, unsigned long);
void dma_buf_kunmap(struct dma_buf *, unsigned long, void *);

void *dma_buf_vmap(struct dma_buf *);
void dma_buf_vunmap(struct dma_buf *, void *vaddr);
#else

static inline struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
Expand Down Expand Up @@ -248,6 +254,14 @@ static inline void dma_buf_kunmap(struct dma_buf *dmabuf,
unsigned long pnum, void *vaddr)
{
}

static inline void *dma_buf_vmap(struct dma_buf *)
{
}

static inline void dma_buf_vunmap(struct dma_buf *, void *vaddr);
{
}
#endif /* CONFIG_DMA_SHARED_BUFFER */

#endif /* __DMA_BUF_H__ */

0 comments on commit 4d33ccb

Please sign in to comment.