Skip to content

Commit ebd1072

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 d8addb7 commit ebd1072

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
@@ -1831,12 +1831,12 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
18311831
return -EINVAL;
18321832
}
18331833

1834-
int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
1835-
unsigned int index, unsigned int plane, unsigned int flags)
1834+
int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
1835+
unsigned int index, unsigned int plane,
1836+
unsigned int flags, struct dma_buf **dmabuf)
18361837
{
18371838
struct vb2_buffer *vb = NULL;
18381839
struct vb2_plane *vb_plane;
1839-
int ret;
18401840
struct dma_buf *dbuf;
18411841

18421842
if (q->memory != VB2_MEMORY_MMAP) {
@@ -1886,6 +1886,21 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
18861886
return -EINVAL;
18871887
}
18881888

1889+
*dmabuf = dbuf;
1890+
return 0;
1891+
}
1892+
EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
1893+
1894+
int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
1895+
unsigned int index, unsigned int plane, unsigned int flags)
1896+
{
1897+
struct dma_buf *dbuf;
1898+
int ret;
1899+
1900+
ret = vb2_core_expbuf_dmabuf(q, type, index, plane, flags, &dbuf);
1901+
if (ret)
1902+
return ret;
1903+
18891904
ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
18901905
if (ret < 0) {
18911906
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
@@ -823,6 +823,21 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
823823
*/
824824
int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
825825

826+
/**
827+
* vb2_core_expbuf_dmabuf() - Export a buffer as a dma_buf structure
828+
* @q: videobuf2 queue
829+
* @type: buffer type
830+
* @index: id number of the buffer
831+
* @plane: index of the plane to be exported, 0 for single plane queues
832+
* @flags: flags for newly created file, currently only O_CLOEXEC is
833+
* supported, refer to manual of open syscall for more details
834+
* @dmabuf: Returns the dmabuf pointer
835+
*
836+
*/
837+
int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
838+
unsigned int index, unsigned int plane,
839+
unsigned int flags, struct dma_buf **dmabuf);
840+
826841
/**
827842
* vb2_core_expbuf() - Export a buffer as a file descriptor.
828843
* @q: pointer to &struct vb2_queue with videobuf2 queue.

0 commit comments

Comments
 (0)