Skip to content

Commit be6c869

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 b77b683 commit be6c869

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
@@ -2129,12 +2129,12 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
21292129
return -EINVAL;
21302130
}
21312131

2132-
int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
2133-
unsigned int index, unsigned int plane, unsigned int flags)
2132+
int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
2133+
unsigned int index, unsigned int plane,
2134+
unsigned int flags, struct dma_buf **dmabuf)
21342135
{
21352136
struct vb2_buffer *vb = NULL;
21362137
struct vb2_plane *vb_plane;
2137-
int ret;
21382138
struct dma_buf *dbuf;
21392139

21402140
if (q->memory != VB2_MEMORY_MMAP) {
@@ -2184,6 +2184,21 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
21842184
return -EINVAL;
21852185
}
21862186

2187+
*dmabuf = dbuf;
2188+
return 0;
2189+
}
2190+
EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
2191+
2192+
int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
2193+
unsigned int index, unsigned int plane, unsigned int flags)
2194+
{
2195+
struct dma_buf *dbuf;
2196+
int ret;
2197+
2198+
ret = vb2_core_expbuf_dmabuf(q, type, index, plane, flags, &dbuf);
2199+
if (ret)
2200+
return ret;
2201+
21872202
ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
21882203
if (ret < 0) {
21892204
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)