From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Naushir Patuck <naush@raspberrypi.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Kieran Bingham <kieran.bingham@ideasonboard.com>
Subject: Re: [PATCH v6 3/4] media: raspberrypi: Add support for RP1-CFE
Date: Thu, 24 Oct 2024 15:05:07 +0300 [thread overview]
Message-ID: <20241024120507.GA6081@pendragon.ideasonboard.com> (raw)
In-Reply-To: <af1456a3-3de8-4b11-9606-79b260bda47e@xs4all.nl>
On Thu, Oct 24, 2024 at 01:21:43PM +0200, Hans Verkuil wrote:
> On 24/10/2024 13:08, Tomi Valkeinen wrote:
> > On 24/10/2024 11:20, Hans Verkuil wrote:
> >> Hi Tomi,
> >>
> >> I know this driver is already merged, but while checking for drivers that use
> >> q->max_num_buffers I stumbled on this cfe code:
> >>
> >> <snip>
> >>
> >>> +/*
> >>> + * vb2 ops
> >>> + */
> >>> +
> >>> +static int cfe_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
> >>> + unsigned int *nplanes, unsigned int sizes[],
> >>> + struct device *alloc_devs[])
> >>> +{
> >>> + struct cfe_node *node = vb2_get_drv_priv(vq);
> >>> + struct cfe_device *cfe = node->cfe;
> >>> + unsigned int size = is_image_node(node) ?
> >>> + node->vid_fmt.fmt.pix.sizeimage :
> >>> + node->meta_fmt.fmt.meta.buffersize;
> >>> +
> >>> + cfe_dbg(cfe, "%s: [%s] type:%u\n", __func__, node_desc[node->id].name,
> >>> + node->buffer_queue.type);
> >>> +
> >>> + if (vq->max_num_buffers + *nbuffers < 3)
> >>> + *nbuffers = 3 - vq->max_num_buffers;
> >>
> >> This makes no sense: max_num_buffers is 32, unless explicitly set when vb2_queue_init
> >> is called. So 32 + *nbuffers is never < 3.
> >>
> >> If the idea is that at least 3 buffers should be allocated by REQBUFS, then set
> >> q->min_reqbufs_allocation = 3; before calling vb2_queue_init and vb2 will handle this
> >> for you.
> >>
> >> Drivers shouldn't modify *nbuffers, except in very rare circumstances, especially
> >> since the code is almost always wrong.
> >
> > Indeed, the code doesn't make sense. I have to say I don't know what
> > was the intent here, but I think "at least 3 buffers should be
> > allocated by REQBUFS" is the likely explanation.
> >
> > I think the hardware should work with even just a single buffer, so
> > is it then fine to not set either q->min_queued_buffers nor
> > q->min_reqbufs_allocation before calling vb2_queue_init()? This
> > seems to result in REQBUFS giving at least two buffers.
>
> min_queued_buffers is really HW dependent. If not set, then
> start_streaming can be called even if there are no buffers queued.
Having min_queued_buffers > 1 is bad for userspace, and it's much nicer
to have it set to 0. The main issue with a value of 1 is that validation
of the pipeline ends up being deferred to the first QBUF if it occurs
after STREAMON, and error handling is then complicated.
It's not just a property of the hardware, kernel drivers can decide to
work with scratch buffers if needed. In many cases, a scratch buffer
allocated by the kernel could be very small, either relying on the same
physical page being mapped through the IOMMU to a larger DMA space, or
using a 0 stride value to write all lines to the same location.
For drivers supported by libcamera, we will require min_queued_buffers
<= 1 and may tighten that to == 0. Tomi, if you submit a patch, please
try to target 0, and if that's too much work for now, set it to 1 at
most.
> If your hardware can handle that, then it's fine to not set it.
>
> >>> +
> >>> + if (*nplanes) {
> >>> + if (sizes[0] < size) {
> >>> + cfe_err(cfe, "sizes[0] %i < size %u\n", sizes[0], size);
> >>> + return -EINVAL;
> >>> + }
> >>> + size = sizes[0];
> >>> + }
> >>> +
> >>> + *nplanes = 1;
> >>> + sizes[0] = size;
> >>> +
> >>> + return 0;
> >>> +}
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2024-10-24 12:07 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-03 10:31 [PATCH v6 0/4] media: raspberrypi: Support RPi5's CFE Tomi Valkeinen
2024-10-03 10:31 ` [PATCH v6 1/4] media: uapi: Add meta formats for PiSP FE config and stats Tomi Valkeinen
2024-10-03 10:31 ` [PATCH v6 2/4] dt-bindings: media: Add bindings for raspberrypi,rp1-cfe Tomi Valkeinen
2024-10-03 10:31 ` [PATCH v6 4/4] media: admin-guide: Document the Raspberry Pi CFE (rp1-cfe) Tomi Valkeinen
[not found] ` <20241003-rp1-cfe-v6-3-d6762edd98a8@ideasonboard.com>
2024-10-24 8:20 ` [PATCH v6 3/4] media: raspberrypi: Add support for RP1-CFE Hans Verkuil
2024-10-24 11:08 ` Tomi Valkeinen
2024-10-24 11:21 ` Hans Verkuil
2024-10-24 12:05 ` Laurent Pinchart [this message]
2024-10-24 12:13 ` Hans Verkuil
2024-10-24 12:26 ` Laurent Pinchart
2024-10-28 9:21 ` Tomi Valkeinen
2024-10-28 10:11 ` Hans Verkuil
2024-10-28 11:05 ` Tomi Valkeinen
2024-10-28 11:13 ` Hans Verkuil
2024-10-28 11:25 ` Tomi Valkeinen
2024-10-28 11:30 ` Hans Verkuil
2024-10-28 15:17 ` Laurent Pinchart
2024-10-28 15:32 ` Tomi Valkeinen
2024-10-28 16:32 ` Laurent Pinchart
2024-10-29 8:23 ` Hans Verkuil
2024-10-29 9:53 ` Laurent Pinchart
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=20241024120507.GA6081@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=hverkuil@xs4all.nl \
--cc=jacopo.mondi@ideasonboard.com \
--cc=kernel-list@raspberrypi.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=krzk+dt@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--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=mchehab@kernel.org \
--cc=naush@raspberrypi.com \
--cc=robh+dt@kernel.org \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen@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