aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/dma-buf-sharing.txt13
-rw-r--r--drivers/base/dma-buf.c11
-rw-r--r--include/linux/dma-buf.h11
3 files changed, 27 insertions, 8 deletions
diff --git a/Documentation/dma-buf-sharing.txt b/Documentation/dma-buf-sharing.txt
index 4966b1be42ac..0b23261561d2 100644
--- a/Documentation/dma-buf-sharing.txt
+++ b/Documentation/dma-buf-sharing.txt
@@ -52,14 +52,23 @@ The dma_buf buffer sharing API usage contains the following steps:
52 associated with this buffer. 52 associated with this buffer.
53 53
54 Interface: 54 Interface:
55 struct dma_buf *dma_buf_export(void *priv, struct dma_buf_ops *ops, 55 struct dma_buf *dma_buf_export_named(void *priv, struct dma_buf_ops *ops,
56 size_t size, int flags) 56 size_t size, int flags,
57 const char *exp_name)
57 58
58 If this succeeds, dma_buf_export allocates a dma_buf structure, and returns a 59 If this succeeds, dma_buf_export allocates a dma_buf structure, and returns a
59 pointer to the same. It also associates an anonymous file with this buffer, 60 pointer to the same. It also associates an anonymous file with this buffer,
60 so it can be exported. On failure to allocate the dma_buf object, it returns 61 so it can be exported. On failure to allocate the dma_buf object, it returns
61 NULL. 62 NULL.
62 63
64 'exp_name' is the name of exporter - to facilitate information while
65 debugging.
66
67 Exporting modules which do not wish to provide any specific name may use the
68 helper define 'dma_buf_export()', with the same arguments as above, but
69 without the last argument; a __FILE__ pre-processor directive will be
70 inserted in place of 'exp_name' instead.
71
632. Userspace gets a handle to pass around to potential buffer-users 722. Userspace gets a handle to pass around to potential buffer-users
64 73
65 Userspace entity requests for a file-descriptor (fd) which is a handle to the 74 Userspace entity requests for a file-descriptor (fd) which is a handle to the
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c
index 2a7cb0df176b..d89102a29f65 100644
--- a/drivers/base/dma-buf.c
+++ b/drivers/base/dma-buf.c
@@ -77,22 +77,24 @@ static inline int is_dma_buf_file(struct file *file)
77} 77}
78 78
79/** 79/**
80 * dma_buf_export - Creates a new dma_buf, and associates an anon file 80 * dma_buf_export_named - Creates a new dma_buf, and associates an anon file
81 * with this buffer, so it can be exported. 81 * with this buffer, so it can be exported.
82 * Also connect the allocator specific data and ops to the buffer. 82 * Also connect the allocator specific data and ops to the buffer.
83 * Additionally, provide a name string for exporter; useful in debugging.
83 * 84 *
84 * @priv: [in] Attach private data of allocator to this buffer 85 * @priv: [in] Attach private data of allocator to this buffer
85 * @ops: [in] Attach allocator-defined dma buf ops to the new buffer. 86 * @ops: [in] Attach allocator-defined dma buf ops to the new buffer.
86 * @size: [in] Size of the buffer 87 * @size: [in] Size of the buffer
87 * @flags: [in] mode flags for the file. 88 * @flags: [in] mode flags for the file.
89 * @exp_name: [in] name of the exporting module - useful for debugging.
88 * 90 *
89 * Returns, on success, a newly created dma_buf object, which wraps the 91 * Returns, on success, a newly created dma_buf object, which wraps the
90 * supplied private data and operations for dma_buf_ops. On either missing 92 * supplied private data and operations for dma_buf_ops. On either missing
91 * ops, or error in allocating struct dma_buf, will return negative error. 93 * ops, or error in allocating struct dma_buf, will return negative error.
92 * 94 *
93 */ 95 */
94struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, 96struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
95 size_t size, int flags) 97 size_t size, int flags, const char *exp_name)
96{ 98{
97 struct dma_buf *dmabuf; 99 struct dma_buf *dmabuf;
98 struct file *file; 100 struct file *file;
@@ -114,6 +116,7 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops,
114 dmabuf->priv = priv; 116 dmabuf->priv = priv;
115 dmabuf->ops = ops; 117 dmabuf->ops = ops;
116 dmabuf->size = size; 118 dmabuf->size = size;
119 dmabuf->exp_name = exp_name;
117 120
118 file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags); 121 file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags);
119 122
@@ -124,7 +127,7 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops,
124 127
125 return dmabuf; 128 return dmabuf;
126} 129}
127EXPORT_SYMBOL_GPL(dma_buf_export); 130EXPORT_SYMBOL_GPL(dma_buf_export_named);
128 131
129 132
130/** 133/**
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index 9978b614a1aa..6f55c0424f12 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -112,6 +112,7 @@ struct dma_buf_ops {
112 * @file: file pointer used for sharing buffers across, and for refcounting. 112 * @file: file pointer used for sharing buffers across, and for refcounting.
113 * @attachments: list of dma_buf_attachment that denotes all devices attached. 113 * @attachments: list of dma_buf_attachment that denotes all devices attached.
114 * @ops: dma_buf_ops associated with this buffer object. 114 * @ops: dma_buf_ops associated with this buffer object.
115 * @exp_name: name of the exporter; useful for debugging.
115 * @priv: exporter specific private data for this buffer object. 116 * @priv: exporter specific private data for this buffer object.
116 */ 117 */
117struct dma_buf { 118struct dma_buf {
@@ -123,6 +124,7 @@ struct dma_buf {
123 struct mutex lock; 124 struct mutex lock;
124 unsigned vmapping_counter; 125 unsigned vmapping_counter;
125 void *vmap_ptr; 126 void *vmap_ptr;
127 const char *exp_name;
126 void *priv; 128 void *priv;
127}; 129};
128 130
@@ -162,8 +164,13 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
162 struct device *dev); 164 struct device *dev);
163void dma_buf_detach(struct dma_buf *dmabuf, 165void dma_buf_detach(struct dma_buf *dmabuf,
164 struct dma_buf_attachment *dmabuf_attach); 166 struct dma_buf_attachment *dmabuf_attach);
165struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, 167
166 size_t size, int flags); 168struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
169 size_t size, int flags, const char *);
170
171#define dma_buf_export(priv, ops, size, flags) \
172 dma_buf_export_named(priv, ops, size, flags, __FILE__)
173
167int dma_buf_fd(struct dma_buf *dmabuf, int flags); 174int dma_buf_fd(struct dma_buf *dmabuf, int flags);
168struct dma_buf *dma_buf_get(int fd); 175struct dma_buf *dma_buf_get(int fd);
169void dma_buf_put(struct dma_buf *dmabuf); 176void dma_buf_put(struct dma_buf *dmabuf);