Skip to content

Commit 1cea88b

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 106ba3a commit 1cea88b

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
@@ -2118,12 +2118,12 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
21182118
return -EINVAL;
21192119
}
21202120

2121-
int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
2122-
unsigned int index, unsigned int plane, unsigned int flags)
2121+
int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
2122+
unsigned int index, unsigned int plane,
2123+
unsigned int flags, struct dma_buf **dmabuf)
21232124
{
21242125
struct vb2_buffer *vb = NULL;
21252126
struct vb2_plane *vb_plane;
2126-
int ret;
21272127
struct dma_buf *dbuf;
21282128

21292129
if (q->memory != VB2_MEMORY_MMAP) {
@@ -2173,6 +2173,21 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
21732173
return -EINVAL;
21742174
}
21752175

2176+
*dmabuf = dbuf;
2177+
return 0;
2178+
}
2179+
EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
2180+
2181+
int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
2182+
unsigned int index, unsigned int plane, unsigned int flags)
2183+
{
2184+
struct dma_buf *dbuf;
2185+
int ret;
2186+
2187+
ret = vb2_core_expbuf_dmabuf(q, type, index, plane, flags, &dbuf);
2188+
if (ret)
2189+
return ret;
2190+
21762191
ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
21772192
if (ret < 0) {
21782193
dprintk(q, 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
@@ -901,6 +901,21 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
901901
*/
902902
int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
903903

904+
/**
905+
* vb2_core_expbuf_dmabuf() - Export a buffer as a dma_buf structure
906+
* @q: videobuf2 queue
907+
* @type: buffer type
908+
* @index: id number of the buffer
909+
* @plane: index of the plane to be exported, 0 for single plane queues
910+
* @flags: flags for newly created file, currently only O_CLOEXEC is
911+
* supported, refer to manual of open syscall for more details
912+
* @dmabuf: Returns the dmabuf pointer
913+
*
914+
*/
915+
int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
916+
unsigned int index, unsigned int plane,
917+
unsigned int flags, struct dma_buf **dmabuf);
918+
904919
/**
905920
* vb2_core_expbuf() - Export a buffer as a file descriptor.
906921
* @q: pointer to &struct vb2_queue with videobuf2 queue.

0 commit comments

Comments
 (0)