summaryrefslogtreecommitdiffstats
path: root/drivers/dma-buf/dma-buf.c
diff options
context:
space:
mode:
authorMaarten Lankhorst <maarten.lankhorst@canonical.com>2014-07-01 06:57:26 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-08 16:03:20 -0400
commit3aac4502fd3f80dcf7e65dbf6edd8676893c1f46 (patch)
tree16d7554b57ed1b2a63f7d80d67acee5c8b3ab92c /drivers/dma-buf/dma-buf.c
parent606b23ad609c71cfb37eeb972ea4c901034edd3c (diff)
dma-buf: use reservation objects
This allows reservation objects to be used in dma-buf. it's required for implementing polling support on the fences that belong to a dma-buf. Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com> Acked-by: Mauro Carvalho Chehab <m.chehab@samsung.com> #drivers/media/v4l2-core/ Acked-by: Thomas Hellstrom <thellstrom@vmware.com> #drivers/gpu/drm/ttm Acked-by: Sumit Semwal <sumit.semwal@linaro.org> Acked-by: Daniel Vetter <daniel@ffwll.ch> Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net> #drivers/gpu/drm/armada/ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/dma-buf/dma-buf.c')
-rw-r--r--drivers/dma-buf/dma-buf.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 840c7fa80983..cd40ca22911f 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -25,10 +25,12 @@
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/dma-buf.h> 27#include <linux/dma-buf.h>
28#include <linux/fence.h>
28#include <linux/anon_inodes.h> 29#include <linux/anon_inodes.h>
29#include <linux/export.h> 30#include <linux/export.h>
30#include <linux/debugfs.h> 31#include <linux/debugfs.h>
31#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#include <linux/reservation.h>
32 34
33static inline int is_dma_buf_file(struct file *); 35static inline int is_dma_buf_file(struct file *);
34 36
@@ -56,6 +58,9 @@ static int dma_buf_release(struct inode *inode, struct file *file)
56 list_del(&dmabuf->list_node); 58 list_del(&dmabuf->list_node);
57 mutex_unlock(&db_list.lock); 59 mutex_unlock(&db_list.lock);
58 60
61 if (dmabuf->resv == (struct reservation_object *)&dmabuf[1])
62 reservation_object_fini(dmabuf->resv);
63
59 kfree(dmabuf); 64 kfree(dmabuf);
60 return 0; 65 return 0;
61} 66}
@@ -128,6 +133,7 @@ static inline int is_dma_buf_file(struct file *file)
128 * @size: [in] Size of the buffer 133 * @size: [in] Size of the buffer
129 * @flags: [in] mode flags for the file. 134 * @flags: [in] mode flags for the file.
130 * @exp_name: [in] name of the exporting module - useful for debugging. 135 * @exp_name: [in] name of the exporting module - useful for debugging.
136 * @resv: [in] reservation-object, NULL to allocate default one.
131 * 137 *
132 * Returns, on success, a newly created dma_buf object, which wraps the 138 * Returns, on success, a newly created dma_buf object, which wraps the
133 * supplied private data and operations for dma_buf_ops. On either missing 139 * supplied private data and operations for dma_buf_ops. On either missing
@@ -135,10 +141,17 @@ static inline int is_dma_buf_file(struct file *file)
135 * 141 *
136 */ 142 */
137struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops, 143struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
138 size_t size, int flags, const char *exp_name) 144 size_t size, int flags, const char *exp_name,
145 struct reservation_object *resv)
139{ 146{
140 struct dma_buf *dmabuf; 147 struct dma_buf *dmabuf;
141 struct file *file; 148 struct file *file;
149 size_t alloc_size = sizeof(struct dma_buf);
150 if (!resv)
151 alloc_size += sizeof(struct reservation_object);
152 else
153 /* prevent &dma_buf[1] == dma_buf->resv */
154 alloc_size += 1;
142 155
143 if (WARN_ON(!priv || !ops 156 if (WARN_ON(!priv || !ops
144 || !ops->map_dma_buf 157 || !ops->map_dma_buf
@@ -150,7 +163,7 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
150 return ERR_PTR(-EINVAL); 163 return ERR_PTR(-EINVAL);
151 } 164 }
152 165
153 dmabuf = kzalloc(sizeof(struct dma_buf), GFP_KERNEL); 166 dmabuf = kzalloc(alloc_size, GFP_KERNEL);
154 if (dmabuf == NULL) 167 if (dmabuf == NULL)
155 return ERR_PTR(-ENOMEM); 168 return ERR_PTR(-ENOMEM);
156 169
@@ -158,6 +171,11 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
158 dmabuf->ops = ops; 171 dmabuf->ops = ops;
159 dmabuf->size = size; 172 dmabuf->size = size;
160 dmabuf->exp_name = exp_name; 173 dmabuf->exp_name = exp_name;
174 if (!resv) {
175 resv = (struct reservation_object *)&dmabuf[1];
176 reservation_object_init(resv);
177 }
178 dmabuf->resv = resv;
161 179
162 file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags); 180 file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags);
163 if (IS_ERR(file)) { 181 if (IS_ERR(file)) {