From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
To: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Cc: "Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Laurent Pinchart" <laurent.pinchart+renesas@ideasonboard.com>,
"Biju Das" <biju.das.jz@bp.renesas.com>,
"Hans Verkuil" <hverkuil+cisco@kernel.org>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Daniel Scally" <dan.scally@ideasonboard.com>,
"Barnabás Pőcze" <pobrn@protonmail.com>,
"Lad Prabhakar" <prabhakar.mahadev-lad.rj@bp.renesas.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
"Daniel Scally" <dan.scally+renesas@ideasonboard.com>,
"Jacopo Mondi" <jacopo.mondi+renesas@ideasonboard.com>
Subject: Re: [PATCH v2 12/15] media: rzg2l-cru: Rework rzg2l_cru_fill_hw_slot()
Date: Tue, 31 Mar 2026 18:26:05 +0200 [thread overview]
Message-ID: <acv1nVy4wUG5QIa9@tom-desktop> (raw)
In-Reply-To: <20260331-b4-cru-rework-v2-12-f94b238b35d4@ideasonboard.com>
Hi Jacopo,
Thanks for your patch.
On Tue, Mar 31, 2026 at 12:27:42PM +0200, Jacopo Mondi wrote:
> From: Daniel Scally <dan.scally+renesas@ideasonboard.com>
>
> The current implementation of rzg2l_cru_fill_hw_slot() results in the
> artificial loss of frames. At present whenever a frame-complete IRQ
> is received the driver fills the hardware slot that was just written
> to with the address of the next buffer in the driver's queue. If the
> queue is empty, that hardware slot's address is set to the address of
> the scratch buffer to enable the capture loop to keep running. There
> is a minimum of a two-frame delay before that slot will be written to
> however, and in the intervening period userspace may queue more
> buffers which could be used.
>
> To resolve the issue rework rzg2l_cru_fill_hw_slot() so that it
> iteratively fills all slots from the queue which currently do not
> have a buffer assigned, until the queue is empty. The scratch
> buffer is only resorted to in the event that the queue is empty and
> the next slot that will be written to does not already have a buffer
> assigned.
>
Tested on RZ/G3E + OV5645 image sensor.
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Kind Regards,
Tommaso
> Signed-off-by: Daniel Scally <dan.scally+renesas@ideasonboard.com>
> Signed-off-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
> ---
> .../media/platform/renesas/rzg2l-cru/rzg2l-video.c | 64 +++++++++++++---------
> 1 file changed, 37 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> index a5197196a408..f061bee51ea8 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> @@ -214,47 +214,52 @@ static void rzg2l_cru_set_slot_addr(struct rzg2l_cru_dev *cru,
> }
>
> /*
> - * Moves a buffer from the queue to the HW slot. If no buffer is
> - * available use the scratch buffer. The scratch buffer is never
> - * returned to userspace, its only function is to enable the capture
> - * loop to keep running.
> + * Move as many buffers as possible from the queue to HW slots If no buffer is
> + * available use the scratch buffer. The scratch buffer is never returned to
> + * userspace, its only function is to enable the capture loop to keep running.
> + *
> + * @cru: the CRU device
> + * @slot: the slot that has just completed
> */
> static void rzg2l_cru_fill_hw_slot(struct rzg2l_cru_dev *cru, int slot)
> {
> - struct vb2_v4l2_buffer *vbuf;
> struct rzg2l_cru_buffer *buf;
> + struct vb2_v4l2_buffer *vbuf;
> + unsigned int next_slot;
> dma_addr_t phys_addr;
>
> - /* A already populated slot shall never be overwritten. */
> - if (WARN_ON(cru->queue_buf[slot]))
> - return;
> + lockdep_assert_held(&cru->hw_lock);
>
> - dev_dbg(cru->dev, "Filling HW slot: %d\n", slot);
> + /* Find the next slot which hasn't a valid address programmed. */
> + for_each_cru_slot_from(cru, next_slot, slot) {
> + if (cru->queue_buf[next_slot])
> + continue;
>
> - guard(spinlock)(&cru->qlock);
> + scoped_guard(spinlock_irqsave, &cru->qlock) {
> + buf = list_first_entry_or_null(&cru->buf_list,
> + struct rzg2l_cru_buffer, list);
> + if (buf)
> + list_del_init(&buf->list);
> + }
>
> - if (list_empty(&cru->buf_list)) {
> - cru->queue_buf[slot] = NULL;
> - phys_addr = cru->scratch_phys;
> - } else {
> - /* Keep track of buffer we give to HW */
> - buf = list_entry(cru->buf_list.next,
> - struct rzg2l_cru_buffer, list);
> - vbuf = &buf->vb;
> - list_del_init(to_buf_list(vbuf));
> - cru->queue_buf[slot] = vbuf;
> + if (!buf) {
> + /* Direct frames to the scratch buffer. */
> + phys_addr = cru->scratch_phys;
> + cru->queue_buf[next_slot] = NULL;
> + rzg2l_cru_set_slot_addr(cru, next_slot, phys_addr);
> + return;
> + }
>
> - /* Setup DMA */
> + vbuf = &buf->vb;
> + cru->queue_buf[next_slot] = vbuf;
> phys_addr = vb2_dma_contig_plane_dma_addr(&vbuf->vb2_buf, 0);
> + rzg2l_cru_set_slot_addr(cru, next_slot, phys_addr);
> }
> -
> - rzg2l_cru_set_slot_addr(cru, slot, phys_addr);
> }
>
> static void rzg2l_cru_initialize_axi(struct rzg2l_cru_dev *cru)
> {
> const struct rzg2l_cru_info *info = cru->info;
> - unsigned int slot;
> u32 amnaxiattr;
>
> /*
> @@ -263,8 +268,14 @@ static void rzg2l_cru_initialize_axi(struct rzg2l_cru_dev *cru)
> */
> rzg2l_cru_write(cru, AMnMBVALID, AMnMBVALID_MBVALID(cru->num_buf - 1));
>
> - for (slot = 0; slot < cru->num_buf; slot++)
> - rzg2l_cru_fill_hw_slot(cru, slot);
> + /*
> + * Program slot#0 with the first available buffer, if any. Pass to the
> + * function 'num_buf - 1' as rzg2l_cru_fill_hw_slot() calculates which
> + * is the next slot to program.
> + */
> + scoped_guard(spinlock_irq, &cru->hw_lock) {
> + rzg2l_cru_fill_hw_slot(cru, cru->num_buf - 1);
> + }
>
> if (info->has_stride) {
> u32 stride = cru->format.bytesperline;
> @@ -695,7 +706,6 @@ irqreturn_t rzg3e_cru_irq(int irq, void *data)
> cru->active_slot = rzg2l_cru_slot_next(cru, cru->active_slot);
>
> dev_dbg(cru->dev, "Current written slot: %d\n", slot);
> - cru->buf_addr[slot] = 0;
>
> /*
> * To hand buffers back in a known order to userspace start
>
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-03-31 16:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 10:27 [PATCH v2 00/15] media: rzg2l-cru: Rework slot programming for V2H/G3E Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 01/15] media: rzg2l-cru: Skip ICnMC configuration when ICnSVC is used Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 02/15] media: rzg2l-cru: Use only frame end interrupts Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 03/15] media: rzg2l-cru: Modernize locking usage with guards Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 04/15] media: rzg2l-cru: Use proper guard() in irq handler Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 05/15] media: rzg2l-cru: Remove locking from start/stop routines Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 06/15] media: rzg2l-cru: Do not use irqsave when not needed Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 07/15] media: rzg2l-cru: Remove wrong locking comment Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 08/15] media: rz2gl-cru: Introduce a spinlock for hw operations Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 09/15] media: rzg2l-cru: Split hw locking from buffers Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 10/15] media: rzg2l-cru: Manually track active slot number Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 11/15] media: rz2gl-cru: Return pending buffers in order Jacopo Mondi
2026-03-31 10:27 ` [PATCH v2 12/15] media: rzg2l-cru: Rework rzg2l_cru_fill_hw_slot() Jacopo Mondi
2026-03-31 16:26 ` Tommaso Merciai [this message]
2026-03-31 10:27 ` [PATCH v2 13/15] media: rzg2l-cru: Remove the 'state' variable Jacopo Mondi
2026-03-31 16:32 ` Tommaso Merciai
2026-03-31 10:27 ` [PATCH v2 14/15] media: rzg2l-cru: Remove debug printouts from irq Jacopo Mondi
2026-03-31 10:45 ` Dan Scally
2026-03-31 10:27 ` [PATCH v2 15/15] media: rzg2l-cru: Simplify irq return value handling Jacopo Mondi
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=acv1nVy4wUG5QIa9@tom-desktop \
--to=tommaso.merciai.xr@bp.renesas.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=dan.scally+renesas@ideasonboard.com \
--cc=dan.scally@ideasonboard.com \
--cc=hverkuil+cisco@kernel.org \
--cc=jacopo.mondi+renesas@ideasonboard.com \
--cc=jacopo.mondi@ideasonboard.com \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=pobrn@protonmail.com \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=sakari.ailus@linux.intel.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