Commit 78df9695 authored by Sumit Semwal's avatar Sumit Semwal

dma-buf: replace dma_buf_export() with dma_buf_export_named()

For debugging purposes, it is useful to have a name-string added
while exporting buffers. Hence, dma_buf_export() is replaced with
dma_buf_export_named(), which additionally takes 'exp_name' as a
parameter.

For backward compatibility, and for lazy exporters who don't wish to
name themselves, a #define dma_buf_export() is also made available,
which adds a __FILE__ instead of 'exp_name'.

Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
  [Thanks for the idea!]
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: default avatarSumit Semwal <sumit.semwal@linaro.org>
parent 5f568865
...@@ -52,14 +52,23 @@ The dma_buf buffer sharing API usage contains the following steps: ...@@ -52,14 +52,23 @@ The dma_buf buffer sharing API usage contains the following steps:
associated with this buffer. associated with this buffer.
Interface: Interface:
struct dma_buf *dma_buf_export(void *priv, struct dma_buf_ops *ops, struct dma_buf *dma_buf_export_named(void *priv, struct dma_buf_ops *ops,
size_t size, int flags) size_t size, int flags,
const char *exp_name)
If this succeeds, dma_buf_export allocates a dma_buf structure, and returns a If this succeeds, dma_buf_export allocates a dma_buf structure, and returns a
pointer to the same. It also associates an anonymous file with this buffer, pointer to the same. It also associates an anonymous file with this buffer,
so it can be exported. On failure to allocate the dma_buf object, it returns so it can be exported. On failure to allocate the dma_buf object, it returns
NULL. NULL.
'exp_name' is the name of exporter - to facilitate information while
debugging.
Exporting modules which do not wish to provide any specific name may use the
helper define 'dma_buf_export()', with the same arguments as above, but
without the last argument; a __FILE__ pre-processor directive will be
inserted in place of 'exp_name' instead.
2. Userspace gets a handle to pass around to potential buffer-users 2. Userspace gets a handle to pass around to potential buffer-users
Userspace entity requests for a file-descriptor (fd) which is a handle to the Userspace entity requests for a file-descriptor (fd) which is a handle to the
......
...@@ -77,22 +77,24 @@ static inline int is_dma_buf_file(struct file *file) ...@@ -77,22 +77,24 @@ static inline int is_dma_buf_file(struct file *file)
} }
/** /**
* dma_buf_export - Creates a new dma_buf, and associates an anon file * dma_buf_export_named - Creates a new dma_buf, and associates an anon file
* with this buffer, so it can be exported. * with this buffer, so it can be exported.
* Also connect the allocator specific data and ops to the buffer. * Also connect the allocator specific data and ops to the buffer.
* Additionally, provide a name string for exporter; useful in debugging.
* *
* @priv: [in] Attach private data of allocator to this buffer * @priv: [in] Attach private data of allocator to this buffer
* @ops: [in] Attach allocator-defined dma buf ops to the new buffer. * @ops: [in] Attach allocator-defined dma buf ops to the new buffer.
* @size: [in] Size of the buffer * @size: [in] Size of the buffer
* @flags: [in] mode flags for the file. * @flags: [in] mode flags for the file.
* @exp_name: [in] name of the exporting module - useful for debugging.
* *
* Returns, on success, a newly created dma_buf object, which wraps the * Returns, on success, a newly created dma_buf object, which wraps the
* supplied private data and operations for dma_buf_ops. On either missing * supplied private data and operations for dma_buf_ops. On either missing
* ops, or error in allocating struct dma_buf, will return negative error. * ops, or error in allocating struct dma_buf, will return negative error.
* *
*/ */
struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
size_t size, int flags) size_t size, int flags, const char *exp_name)
{ {
struct dma_buf *dmabuf; struct dma_buf *dmabuf;
struct file *file; struct file *file;
...@@ -114,6 +116,7 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, ...@@ -114,6 +116,7 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops,
dmabuf->priv = priv; dmabuf->priv = priv;
dmabuf->ops = ops; dmabuf->ops = ops;
dmabuf->size = size; dmabuf->size = size;
dmabuf->exp_name = exp_name;
file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags); file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags);
...@@ -124,7 +127,7 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, ...@@ -124,7 +127,7 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops,
return dmabuf; return dmabuf;
} }
EXPORT_SYMBOL_GPL(dma_buf_export); EXPORT_SYMBOL_GPL(dma_buf_export_named);
/** /**
......
...@@ -112,6 +112,7 @@ struct dma_buf_ops { ...@@ -112,6 +112,7 @@ struct dma_buf_ops {
* @file: file pointer used for sharing buffers across, and for refcounting. * @file: file pointer used for sharing buffers across, and for refcounting.
* @attachments: list of dma_buf_attachment that denotes all devices attached. * @attachments: list of dma_buf_attachment that denotes all devices attached.
* @ops: dma_buf_ops associated with this buffer object. * @ops: dma_buf_ops associated with this buffer object.
* @exp_name: name of the exporter; useful for debugging.
* @priv: exporter specific private data for this buffer object. * @priv: exporter specific private data for this buffer object.
*/ */
struct dma_buf { struct dma_buf {
...@@ -123,6 +124,7 @@ struct dma_buf { ...@@ -123,6 +124,7 @@ struct dma_buf {
struct mutex lock; struct mutex lock;
unsigned vmapping_counter; unsigned vmapping_counter;
void *vmap_ptr; void *vmap_ptr;
const char *exp_name;
void *priv; void *priv;
}; };
...@@ -162,8 +164,13 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, ...@@ -162,8 +164,13 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
struct device *dev); struct device *dev);
void dma_buf_detach(struct dma_buf *dmabuf, void dma_buf_detach(struct dma_buf *dmabuf,
struct dma_buf_attachment *dmabuf_attach); struct dma_buf_attachment *dmabuf_attach);
struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops,
size_t size, int flags); struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
size_t size, int flags, const char *);
#define dma_buf_export(priv, ops, size, flags) \
dma_buf_export_named(priv, ops, size, flags, __FILE__)
int dma_buf_fd(struct dma_buf *dmabuf, int flags); int dma_buf_fd(struct dma_buf *dmabuf, int flags);
struct dma_buf *dma_buf_get(int fd); struct dma_buf *dma_buf_get(int fd);
void dma_buf_put(struct dma_buf *dmabuf); void dma_buf_put(struct dma_buf *dmabuf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment