From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jai Luthra <jai.luthra@ideasonboard.com>
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
Tomasz Figa <tfiga@chromium.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>,
Kieran Bingham <kieran.bingham@ideasonboard.com>,
Dave Stevenson <dave.stevenson@raspberrypi.com>,
Naushir Patuck <naush@raspberrypi.com>,
Stefan Wahren <wahrenst@gmx.net>,
Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Daniel Scally <dan.scally@ideasonboard.com>,
linux-media@vger.kernel.org,
linux-rpi-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Dave Stevenson <dave.stevenson@raspberrypi.org>,
Hans Verkuil <hans@jjverkuil.nl>
Subject: Re: [PATCH v3 6/9] media: videobuf2: Allow exporting of a struct dmabuf
Date: Thu, 10 Sep 2026 18:04:54 +0300 [thread overview]
Message-ID: <20260910150454.GP1892234@killaraus.ideasonboard.com> (raw)
In-Reply-To: <20260717-b4-vchiq-isp-v3-6-fb8235e15c68@ideasonboard.com>
(CC'ing Hans)
Tomasz, Hans, could you review this patch ? It is the only one in the
series that touches the V4L2 core.
On Fri, Jul 17, 2026 at 04:34:21PM +0530, Jai Luthra wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
>
> 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>
> Signed-off-by: Jai Luthra <jai.luthra@ideasonboard.com>
> ---
> drivers/media/common/videobuf2/videobuf2-core.c | 21 ++++++++++++++++++---
> include/media/videobuf2-core.h | 15 +++++++++++++++
> 2 files changed, 33 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> index b0a6084f1757..0e62f3d97194 100644
> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> @@ -2419,11 +2419,11 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset,
> return 0;
> }
>
> -int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
> - struct vb2_buffer *vb, unsigned int plane, unsigned int flags)
> +int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
> + struct vb2_buffer *vb, unsigned int plane,
> + unsigned int flags, struct dma_buf **dmabuf)
> {
> struct vb2_plane *vb_plane;
> - int ret;
> struct dma_buf *dbuf;
>
> if (q->memory != VB2_MEMORY_MMAP) {
> @@ -2468,6 +2468,21 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
> return -EINVAL;
> }
>
> + *dmabuf = dbuf;
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
> +
> +int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
> + struct vb2_buffer *vb, unsigned int plane, unsigned int flags)
> +{
> + struct dma_buf *dbuf;
> + int ret;
> +
> + ret = vb2_core_expbuf_dmabuf(q, type, vb, plane, flags, &dbuf);
> + if (ret)
> + return ret;
> +
> ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
> if (ret < 0) {
> dprintk(q, 3, "buffer %d, plane %d failed to export (%d)\n",
> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> index 4b4f4c15c53a..15aeaaeaf8ad 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -954,6 +954,21 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
> */
> int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
>
> +/**
> + * vb2_core_expbuf_dmabuf() - Export a buffer as a dma_buf structure
> + * @q: videobuf2 queue
> + * @type: buffer type
The type must be identical to the queue type. I would remove the
argument from the function, and move the type check to
vb2_core_expbuf().
A separate patch could then push the check out of vb2_core_expbuf() as
well, as in most cases the type received from userspace in the
v4l2_exportbuffer structure is used to get the corresponding queue.
> + * @index: id number of the buffer
This isn't correct, the function takes a pointer to a vb2_buffer.
> + * @plane: index of the plane to be exported, 0 for single plane queues
> + * @flags: flags for newly created file, currently only O_CLOEXEC is
> + * supported, refer to manual of open syscall for more details
> + * @dmabuf: Returns the dmabuf pointer
Is there a reason not to return the dmabuf directly from the function,
with an error pointer for errors ?
> + *
> + */
> +int vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
> + struct vb2_buffer *vb, unsigned int plane,
> + unsigned int flags, struct dma_buf **dmabuf);
> +
> /**
> * vb2_core_expbuf() - Export a buffer as a file descriptor.
> * @q: pointer to &struct vb2_queue with videobuf2 queue.
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2026-09-10 15:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 11:04 [PATCH v3 0/9] media: Add support for Broadcom/RPi BCM2835 ISP Jai Luthra
2026-07-17 11:04 ` [PATCH v3 1/9] platform/raspberrypi: vchiq-mmal: Include missing headers Jai Luthra
2026-08-31 5:37 ` Paul Elder
2026-07-17 11:04 ` [PATCH v3 2/9] platform/raspberrypi: vchiq-mmal: Move headers to include/linux Jai Luthra
2026-08-31 5:45 ` Paul Elder
2026-07-17 11:04 ` [PATCH v3 3/9] platform/raspberrypi: vchiq-mmal: Support ISP parameters and stats Jai Luthra
2026-08-31 6:29 ` Paul Elder
2026-07-17 11:04 ` [PATCH v3 4/9] platform/raspberrypi: vchiq-mmal: Support bayer and gray formats Jai Luthra
2026-08-31 6:30 ` Paul Elder
2026-09-10 14:17 ` Jai Luthra
2026-09-10 16:46 ` Dave Stevenson
2026-07-17 11:04 ` [PATCH v3 5/9] platform/raspberrypi: vchiq: Add helpers for vchiq driver data Jai Luthra
2026-08-31 6:40 ` Paul Elder
2026-07-17 11:04 ` [PATCH v3 6/9] media: videobuf2: Allow exporting of a struct dmabuf Jai Luthra
2026-08-31 6:55 ` Paul Elder
2026-09-10 14:29 ` Jai Luthra
2026-09-10 15:04 ` Laurent Pinchart [this message]
2026-07-17 11:04 ` [PATCH v3 7/9] media: platform: broadcom: Move unicam driver to subdir Jai Luthra
2026-07-17 11:36 ` Jai Luthra
2026-08-31 6:27 ` Paul Elder
2026-07-17 11:04 ` [PATCH v3 8/9] media: platform: broadcom: Add bcm2835-isp driver Jai Luthra
2026-09-04 9:17 ` Paul Elder
2026-07-17 11:04 ` [PATCH v3 9/9] platform/raspberrypi: vchiq: Load bcm2835_isp driver from vchiq Jai Luthra
2026-09-04 9:18 ` Paul Elder
2026-08-31 5:42 ` [PATCH v3 0/9] media: Add support for Broadcom/RPi BCM2835 ISP Paul Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260910150454.GP1892234@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=dan.scally@ideasonboard.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dave.stevenson@raspberrypi.org \
--cc=florian.fainelli@broadcom.com \
--cc=hans@jjverkuil.nl \
--cc=jacopo.mondi@ideasonboard.com \
--cc=jai.luthra@ideasonboard.com \
--cc=kernel-list@raspberrypi.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=naush@raspberrypi.com \
--cc=tfiga@chromium.org \
--cc=wahrenst@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®