1 From 2fada970d893db4a8800bae31d6ed8c01b4c4173 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Mon, 29 Oct 2018 17:57:45 +0000
4 Subject: [PATCH 278/703] media: videobuf2: Allow exporting of a struct dmabuf
6 videobuf2 only allowed exporting a dmabuf as a file descriptor,
7 but there are instances where having the struct dma_buf is
8 useful within the kernel.
10 Split the current implementation into two, one step which
11 exports a struct dma_buf, and the second which converts that
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
16 .../media/common/videobuf2/videobuf2-core.c | 21 ++++++++++++++++---
17 include/media/videobuf2-core.h | 15 +++++++++++++
18 2 files changed, 33 insertions(+), 3 deletions(-)
20 --- a/drivers/media/common/videobuf2/videobuf2-core.c
21 +++ b/drivers/media/common/videobuf2/videobuf2-core.c
22 @@ -1851,12 +1851,12 @@ static int __find_plane_by_offset(struct
26 -int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
27 - unsigned int index, unsigned int plane, unsigned int flags)
28 +int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
29 + unsigned int index, unsigned int plane,
30 + unsigned int flags, struct dma_buf **dmabuf)
32 struct vb2_buffer *vb = NULL;
33 struct vb2_plane *vb_plane;
37 if (q->memory != VB2_MEMORY_MMAP) {
38 @@ -1906,6 +1906,21 @@ int vb2_core_expbuf(struct vb2_queue *q,
45 +EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
47 +int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
48 + unsigned int index, unsigned int plane, unsigned int flags)
50 + struct dma_buf *dbuf;
53 + ret = vb2_core_expbuf_dmabuf(q, type, index, plane, flags, &dbuf);
57 ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
59 dprintk(3, "buffer %d, plane %d failed to export (%d)\n",
60 --- a/include/media/videobuf2-core.h
61 +++ b/include/media/videobuf2-core.h
62 @@ -825,6 +825,21 @@ int vb2_core_streamon(struct vb2_queue *
63 int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
66 + * vb2_core_expbuf_dmabuf() - Export a buffer as a dma_buf structure
67 + * @q: videobuf2 queue
68 + * @type: buffer type
69 + * @index: id number of the buffer
70 + * @plane: index of the plane to be exported, 0 for single plane queues
71 + * @flags: flags for newly created file, currently only O_CLOEXEC is
72 + * supported, refer to manual of open syscall for more details
73 + * @dmabuf: Returns the dmabuf pointer
76 +int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
77 + unsigned int index, unsigned int plane,
78 + unsigned int flags, struct dma_buf **dmabuf);
81 * vb2_core_expbuf() - Export a buffer as a file descriptor.
82 * @q: pointer to &struct vb2_queue with videobuf2 queue.
83 * @fd: pointer to the file descriptor associated with DMABUF