653504abf55ed69a7e030650c28eb4830e7b3b72
[openwrt/staging/rmilecki.git] /
1 From 9e7ee8b9957c9ca8b2e2d2fd5e19c12039688ccd 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 275/782] media: videobuf2: Allow exporting of a struct dmabuf
5
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.
9
10 Split the current implementation into two, one step which
11 exports a struct dma_buf, and the second which converts that
12 into an fd.
13
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
15 ---
16 .../media/common/videobuf2/videobuf2-core.c | 21 ++++++++++++++++---
17 include/media/videobuf2-core.h | 15 +++++++++++++
18 2 files changed, 33 insertions(+), 3 deletions(-)
19
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
23 return -EINVAL;
24 }
25
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)
31 {
32 struct vb2_buffer *vb = NULL;
33 struct vb2_plane *vb_plane;
34 - int ret;
35 struct dma_buf *dbuf;
36
37 if (q->memory != VB2_MEMORY_MMAP) {
38 @@ -1906,6 +1906,21 @@ int vb2_core_expbuf(struct vb2_queue *q,
39 return -EINVAL;
40 }
41
42 + *dmabuf = dbuf;
43 + return 0;
44 +}
45 +EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
46 +
47 +int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
48 + unsigned int index, unsigned int plane, unsigned int flags)
49 +{
50 + struct dma_buf *dbuf;
51 + int ret;
52 +
53 + ret = vb2_core_expbuf_dmabuf(q, type, index, plane, flags, &dbuf);
54 + if (ret)
55 + return ret;
56 +
57 ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
58 if (ret < 0) {
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);
64
65 /**
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
74 + *
75 + */
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);
79 +
80 +/**
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