Skip to content

Commit 211d3e5

Browse files
6by9popcornmix
authored andcommitted
media: videobuf2: Allow exporting of a struct dmabuf
videobuf2 only allowed exporting a dmabuf as a file descriptor, but there are instances where having the struct dma_buf is useful within the kernel. Split the current implementation into two, one step which exports a struct dma_buf, and the second which converts that into an fd. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
1 parent 9dc9a95 commit 211d3e5

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,12 +2073,12 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
20732073
return -EINVAL;
20742074
}
20752075

2076-
int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
2077-
unsigned int index, unsigned int plane, unsigned int flags)
2076+
int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
2077+
unsigned int index, unsigned int plane,
2078+
unsigned int flags, struct dma_buf **dmabuf)
20782079
{
20792080
struct vb2_buffer *vb = NULL;
20802081
struct vb2_plane *vb_plane;
2081-
int ret;
20822082
struct dma_buf *dbuf;
20832083

20842084
if (q->memory != VB2_MEMORY_MMAP) {
@@ -2128,6 +2128,21 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
21282128
return -EINVAL;
21292129
}
21302130

2131+
*dmabuf = dbuf;
2132+
return 0;
2133+
}
2134+
EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
2135+
2136+
int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
2137+
unsigned int index, unsigned int plane, unsigned int flags)
2138+
{
2139+
struct dma_buf *dbuf;
2140+
int ret;
2141+
2142+
ret = vb2_core_expbuf_dmabuf(q, type, index, plane, flags, &dbuf);
2143+
if (ret)
2144+
return ret;
2145+
21312146
ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
21322147
if (ret < 0) {
21332148
dprintk(3, "buffer %d, plane %d failed to export (%d)\n",

‎include/media/videobuf2-core.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,21 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
875875
*/
876876
int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
877877

878+
/**
879+
* vb2_core_expbuf_dmabuf() - Export a buffer as a dma_buf structure
880+
* @q: videobuf2 queue
881+
* @type: buffer type
882+
* @index: id number of the buffer
883+
* @plane: index of the plane to be exported, 0 for single plane queues
884+
* @flags: flags for newly created file, currently only O_CLOEXEC is
885+
* supported, refer to manual of open syscall for more details
886+
* @dmabuf: Returns the dmabuf pointer
887+
*
888+
*/
889+
int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
890+
unsigned int index, unsigned int plane,
891+
unsigned int flags, struct dma_buf **dmabuf);
892+
878893
/**
879894
* vb2_core_expbuf() - Export a buffer as a file descriptor.
880895
* @q: pointer to &struct vb2_queue with videobuf2 queue.

0 commit comments

Comments
 (0)