From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Umang Jain <umang.jain@ideasonboard.com>
Cc: linux-media@vger.kernel.org, kernel-list@raspberrypi.com,
linux-kernel@vger.kernel.org,
linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-staging@lists.linux.dev,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Dave Stevenson <dave.stevenson@raspberrypi.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Naushir Patuck <naush@raspberrypi.com>,
David Plowman <david.plowman@raspberrypi.com>,
Kieran Bingham <kieran.bingham@ideasonboard.com>,
Dave Stevenson <dave.stevenson@raspberrypi.org>
Subject: Re: [PATCH 03/14] media: videobuf2: Allow exporting of a struct dmabuf
Date: Tue, 22 Nov 2022 01:18:01 +0200 [thread overview]
Message-ID: <Y3wHKfeNB6Fv9Xpo@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20221121214722.22563-4-umang.jain@ideasonboard.com>
Hi Umang and Dave,
Thank you for the patch.
On Tue, Nov 22, 2022 at 03:17:11AM +0530, Umang Jain 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: Umang Jain <umang.jain@ideasonboard.com>
> ---
> .../media/common/videobuf2/videobuf2-core.c | 36 +++++++++++++------
> include/media/videobuf2-core.h | 15 ++++++++
> 2 files changed, 40 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> index ab9697f3b5f1..32b26737cac4 100644
> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> @@ -2184,49 +2184,49 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
> return -EINVAL;
> }
>
> -int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
> - unsigned int index, unsigned int plane, unsigned int flags)
> +struct dma_buf *vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
> + unsigned int index, unsigned int plane,
> + unsigned int flags)
This function is used in the ISP driver, in bcm2835_isp_buf_prepare(),
for MMAP buffers, and as far as I can tell, its only purpose is to
create a dma_buf instance to then be imported in
vchiq_mmal_submit_buffer() with a call to vc_sm_cma_import_dmabuf().
That sounds like a very complicated set of operations, and quite
inefficient :-(
> {
> struct vb2_buffer *vb = NULL;
> struct vb2_plane *vb_plane;
> - int ret;
> struct dma_buf *dbuf;
>
> if (q->memory != VB2_MEMORY_MMAP) {
> dprintk(q, 1, "queue is not currently set up for mmap\n");
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> }
>
> if (!q->mem_ops->get_dmabuf) {
> dprintk(q, 1, "queue does not support DMA buffer exporting\n");
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> }
>
> if (flags & ~(O_CLOEXEC | O_ACCMODE)) {
> dprintk(q, 1, "queue does support only O_CLOEXEC and access mode flags\n");
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> }
>
> if (type != q->type) {
> dprintk(q, 1, "invalid buffer type\n");
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> }
>
> if (index >= q->num_buffers) {
> dprintk(q, 1, "buffer index out of range\n");
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> }
>
> vb = q->bufs[index];
>
> if (plane >= vb->num_planes) {
> dprintk(q, 1, "buffer plane out of range\n");
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> }
>
> if (vb2_fileio_is_active(q)) {
> dprintk(q, 1, "expbuf: file io in progress\n");
> - return -EBUSY;
> + return ERR_PTR(-EBUSY);
> }
>
> vb_plane = &vb->planes[plane];
> @@ -2238,9 +2238,23 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
> if (IS_ERR_OR_NULL(dbuf)) {
> dprintk(q, 1, "failed to export buffer %d, plane %d\n",
> index, plane);
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> }
>
> + return dbuf;
> +}
> +EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
> +
> +int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
> + unsigned int index, unsigned int plane, unsigned int flags)
> +{
> + struct dma_buf *dbuf;
> + int ret;
> +
> + dbuf = vb2_core_expbuf_dmabuf(q, type, index, plane, flags);
> + if (IS_ERR(dbuf))
> + return PTR_ERR(dbuf);
> +
> 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 3253bd2f6fee..33629ed2b64f 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -911,6 +911,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
> + * @index: id number of the 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
> + *
> + * Return: Returns the dmabuf pointer
> + */
> +struct dma_buf *vb2_core_expbuf_dmabuf(struct vb2_queue *q, unsigned int type,
> + unsigned int index, unsigned int plane,
> + unsigned int flags);
> +
> /**
> * 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:[~2022-11-21 23:18 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 21:47 [PATCH 00/14] staging: vc04_services: bcm2835-isp support Umang Jain
2022-11-21 21:47 ` [PATCH 01/14] staging: vc04_services: Add new vc-sm-cma driver Umang Jain
2022-11-21 23:04 ` Laurent Pinchart
2022-11-21 21:47 ` [PATCH 02/14] staging: vchiq_arm: Register vcsm-cma as a platform driver Umang Jain
2022-11-21 23:07 ` Laurent Pinchart
2022-11-21 21:47 ` [PATCH 03/14] media: videobuf2: Allow exporting of a struct dmabuf Umang Jain
2022-11-21 23:18 ` Laurent Pinchart [this message]
2022-11-22 11:35 ` Dave Stevenson
2022-11-25 1:49 ` Laurent Pinchart
2022-11-21 21:47 ` [PATCH 04/14] staging: mmal-vchiq: Add support for event callbacks Umang Jain
2022-11-21 21:47 ` [PATCH 05/14] staging: mmal-vchiq: Use vc-sm-cma to support zero copy Umang Jain
2022-11-21 21:47 ` [PATCH 06/14] staging: mmal_vchiq: Add image formats to be used by bcm2835-isp Umang Jain
2022-11-21 23:21 ` Laurent Pinchart
2022-11-21 21:47 ` [PATCH 07/14] media: uapi: v4l2-core: Add ISP statistics output V4L2 fourcc type Umang Jain
2022-11-21 23:25 ` Laurent Pinchart
2022-11-21 21:47 ` [PATCH 08/14] uapi: bcm2835-isp: Add bcm2835-isp uapi header file Umang Jain
2022-11-21 23:28 ` Laurent Pinchart
2022-11-21 21:47 ` [PATCH 09/14] staging: vc04_services: bcm2835-isp: Add a more complex ISP processing component Umang Jain
2022-11-21 21:47 ` [PATCH 10/14] WIP: vc04_services: bcm2835-isp: Allow formats with different colour spaces Umang Jain
2022-11-21 21:47 ` [PATCH 11/14] WIP: vc04_services: bcm2835-isp: Permit all sRGB colour spaces on ISP outputs Umang Jain
2022-11-21 21:47 ` [PATCH 12/14] staging: vc04_services: bcm2835_isp: Allow multiple users Umang Jain
2022-11-21 23:29 ` Laurent Pinchart
2022-11-21 23:35 ` Laurent Pinchart
2022-11-21 21:47 ` [PATCH 13/14] docs: admin-guide: media: bcm2835-isp: Add documentation for bcm2835-isp Umang Jain
2022-11-21 23:41 ` Laurent Pinchart
2022-11-21 21:47 ` [PATCH 14/14] staging: vc04_services: vchiq: Load bcm2835_isp driver from vchiq Umang Jain
2022-11-21 23:10 ` Laurent Pinchart
2022-11-21 22:16 ` [PATCH 00/14] staging: vc04_services: bcm2835-isp support Laurent Pinchart
2022-11-22 11:42 ` Dave Stevenson
2022-11-22 12:34 ` Umang Jain
2022-11-26 14:42 ` Stefan Wahren
2022-11-26 16:26 ` Umang Jain
2022-11-26 22:56 ` Stefan Wahren
2022-11-30 10:58 ` Umang Jain
2022-12-01 22:45 ` Stefan Wahren
2022-12-02 3:57 ` Umang Jain
2022-12-02 9:17 ` Laurent Pinchart
2022-12-02 11:23 ` Dave Stevenson
2022-12-02 12:10 ` Laurent Pinchart
2022-12-02 12:35 ` Stefan Wahren
2022-12-02 13:25 ` Peter Robinson
2022-12-02 12:38 ` Dave Stevenson
2022-12-02 13:29 ` Laurent Pinchart
2022-12-02 12:41 ` Stefan Wahren
2022-12-02 13:32 ` Laurent Pinchart
2022-12-02 13:42 ` Dave Stevenson
2022-12-03 13:41 ` Stefan Wahren
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=Y3wHKfeNB6Fv9Xpo@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dave.stevenson@raspberrypi.org \
--cc=david.plowman@raspberrypi.com \
--cc=f.fainelli@gmail.com \
--cc=kernel-list@raspberrypi.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=linux-staging@lists.linux.dev \
--cc=naush@raspberrypi.com \
--cc=umang.jain@ideasonboard.com \
/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