Skip to content

Commit ea3aba8

Browse files
pH5mchehab
authored andcommitted
[media] videobuf2: Add support for file access mode flags for DMABUF exporting
Currently it is not possible for userspace to map a DMABUF exported buffer with write permissions. This patch allows to also pass O_RDONLY/O_RDWR when exporting the buffer, so that userspace may map it with write permissions. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
1 parent d8eec74 commit ea3aba8

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎Documentation/DocBook/media/v4l/vidioc-expbuf.xml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ range from zero to the maximal number of valid planes for the currently active
7373
format. For the single-planar API, applications must set <structfield> plane
7474
</structfield> to zero. Additional flags may be posted in the <structfield>
7575
flags </structfield> field. Refer to a manual for open() for details.
76-
Currently only O_CLOEXEC is supported. All other fields must be set to zero.
76+
Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, and O_RDWR are supported. All
77+
other fields must be set to zero.
7778
In the case of multi-planar API, every plane is exported separately using
7879
multiple <constant> VIDIOC_EXPBUF </constant> calls. </para>
7980

@@ -170,8 +171,9 @@ multi-planar API. Otherwise this value must be set to zero. </entry>
170171
<entry>__u32</entry>
171172
<entry><structfield>flags</structfield></entry>
172173
<entry>Flags for the newly created file, currently only <constant>
173-
O_CLOEXEC </constant> is supported, refer to the manual of open() for more
174-
details.</entry>
174+
O_CLOEXEC </constant>, <constant>O_RDONLY</constant>, <constant>O_WRONLY
175+
</constant>, and <constant>O_RDWR</constant> are supported, refer to the manual
176+
of open() for more details.</entry>
175177
</row>
176178
<row>
177179
<entry>__s32</entry>

‎drivers/media/v4l2-core/videobuf2-core.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,8 +1824,8 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
18241824
return -EINVAL;
18251825
}
18261826

1827-
if (eb->flags & ~O_CLOEXEC) {
1828-
dprintk(1, "Queue does support only O_CLOEXEC flag\n");
1827+
if (eb->flags & ~(O_CLOEXEC | O_ACCMODE)) {
1828+
dprintk(1, "Queue does support only O_CLOEXEC and access mode flags\n");
18291829
return -EINVAL;
18301830
}
18311831

@@ -1848,14 +1848,14 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
18481848

18491849
vb_plane = &vb->planes[eb->plane];
18501850

1851-
dbuf = call_memop(q, get_dmabuf, vb_plane->mem_priv);
1851+
dbuf = call_memop(q, get_dmabuf, vb_plane->mem_priv, eb->flags & O_ACCMODE);
18521852
if (IS_ERR_OR_NULL(dbuf)) {
18531853
dprintk(1, "Failed to export buffer %d, plane %d\n",
18541854
eb->index, eb->plane);
18551855
return -EINVAL;
18561856
}
18571857

1858-
ret = dma_buf_fd(dbuf, eb->flags);
1858+
ret = dma_buf_fd(dbuf, eb->flags & ~O_ACCMODE);
18591859
if (ret < 0) {
18601860
dprintk(3, "buffer %d, plane %d failed to export (%d)\n",
18611861
eb->index, eb->plane, ret);

‎drivers/media/v4l2-core/videobuf2-dma-contig.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static struct sg_table *vb2_dc_get_base_sgt(struct vb2_dc_buf *buf)
393393
return sgt;
394394
}
395395

396-
static struct dma_buf *vb2_dc_get_dmabuf(void *buf_priv)
396+
static struct dma_buf *vb2_dc_get_dmabuf(void *buf_priv, unsigned long flags)
397397
{
398398
struct vb2_dc_buf *buf = buf_priv;
399399
struct dma_buf *dbuf;
@@ -404,7 +404,7 @@ static struct dma_buf *vb2_dc_get_dmabuf(void *buf_priv)
404404
if (WARN_ON(!buf->sgt_base))
405405
return NULL;
406406

407-
dbuf = dma_buf_export(buf, &vb2_dc_dmabuf_ops, buf->size, 0);
407+
dbuf = dma_buf_export(buf, &vb2_dc_dmabuf_ops, buf->size, flags);
408408
if (IS_ERR(dbuf))
409409
return NULL;
410410

‎include/media/videobuf2-core.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct vb2_fileio_data;
8383
struct vb2_mem_ops {
8484
void *(*alloc)(void *alloc_ctx, unsigned long size, gfp_t gfp_flags);
8585
void (*put)(void *buf_priv);
86-
struct dma_buf *(*get_dmabuf)(void *buf_priv);
86+
struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags);
8787

8888
void *(*get_userptr)(void *alloc_ctx, unsigned long vaddr,
8989
unsigned long size, int write);

0 commit comments

Comments
 (0)