mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>
Cc: "Jacopo Mondi" <jacopo.mondi+renesas@ideasonboard.com>,
	"Jai Luthra" <jai.luthra+renesas@ideasonboard.com>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Magnus Damm" <magnus.damm@gmail.com>,
	"Barnabás Pőcze" <barnabas.pocze+renesas@ideasonboard.com>,
	"Yusuke Goda" <yusuke.goda.sx@renesas.com>,
	"Yuya Hamamachi" <yuya.hamamachi.sx@renesas.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input
Date: Mon, 16 Nov 2026 12:21:17 +0100	[thread overview]
Message-ID: <avrjjCYcqsQOzhvf@zed> (raw)
In-Reply-To: <20261114-v4l2-add-nv12-v2-1-a3f5ecfd48d6@ragnatech.se>

Hi Niklas,

On Sat, Nov 14, 2026 at 08:55:16PM +0100, Niklas Söderlund wrote:
> From: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
>
> The RAW input video device always overwrote the bytesperline requested
> by userspace with width * bpp. The input buffers are however shared with
> the VIN, which may use a larger line stride (for example 3296 instead of
> 3280 bytes for a 1640 pixel wide 10 bit image). The dmabuf exported by
> the ISP was then smaller than the VIN buffer size, and queueing it to
> the VIN failed with -EINVAL:
>
>   __prepare_dmabuf: invalid dmabuf length 4042752 for plane 0,
>   minimum length 4060672
>
> Use the requested bytesperline if it is larger than the minimum.
>

This is worth a fixes imo

> Signed-off-by: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
> [Niklas: Use clamp(..) instead of if statements]
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> * Changes since v1
> - Use clamp() instead of max(min()).
> - Upper limit at SZ_64K - 1, not SZ_64K.
> ---
>  drivers/media/platform/renesas/rcar-isp/core-io.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
> index b60b91f43d42..cc538e984aa1 100644
> --- a/drivers/media/platform/renesas/rcar-isp/core-io.c
> +++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
> @@ -5,6 +5,8 @@
>   * Copyright (C) 2026 Ragnatech AB
>   */
>
> +#include <linux/sizes.h>
> +
>  #include <media/v4l2-ctrls.h>
>  #include <media/v4l2-event.h>
>  #include <media/v4l2-ioctl.h>
> @@ -335,6 +337,7 @@ static void risp_io_input_try_format(struct rcar_isp_core_io *io,
>  				     struct v4l2_pix_format_mplane *pix)
>  {
>  	unsigned int bpp = 0;
> +	unsigned int bpl;
>
>  	v4l_bound_align_image(&pix->width, RISP_MIN_WIDTH, RISP_MAX_WIDTH, RISP_SIZE_ALIGNMENT,
>  			      &pix->height, RISP_MIN_HEIGHT, RISP_MAX_HEIGHT, RISP_SIZE_ALIGNMENT,
> @@ -352,11 +355,17 @@ static void risp_io_input_try_format(struct rcar_isp_core_io *io,
>  		bpp = risp_io_input_formats[0].bpp;
>  	}
>
> +	/*
> +	 * Honour the line stride requested by userspace, the buffers are
> +	 * shared with the VIN which may use a larger stride than the minimum.
> +	 */
> +	bpl = clamp(pix->plane_fmt[0].bytesperline, pix->width * bpp, SZ_64K - 1);
> +

There is a (quite long) anlysis of this bug in our forge:
https://git.ideasonboard.com/renesas-v4h-isp/libcamera/issues/14

and while the commit message of this patch correctly identify the issue
it doesn't take into account any requirement (stride alignment and max
stride length) of the VSP-X unit which actually does the transfer on
behalf of the ISP.

We didn't get to the bottom of VSP-X stride alignment constraints, but
the RPF unit documentation specifies a max size for the source picture
stride (which is the SZ_64K - 1 value that is used by this patch).
https://git.ideasonboard.com/renesas-v4h-isp/libcamera/issues/14#issuecomment-40317

Laurent suggested to get the VSP-X stride alignment and max size by
adding a function (possibily a try format) in the ISP/VSP-X interface.

I'm more of the opinion that as the ISP-core, VSP-X and VIN are part
of the same SoC it is not too crazy to use (SZ_64K - 1) here directly
(maybe adding a comment on where the limits comes from).

What do you think ?


>  	pix->field = V4L2_FIELD_NONE;
>  	pix->colorspace = V4L2_COLORSPACE_RAW;
>
>  	pix->num_planes = 1;
> -	pix->plane_fmt[0].bytesperline = pix->width * bpp;
> +	pix->plane_fmt[0].bytesperline = bpl;
>  	pix->plane_fmt[0].sizeimage = pix->plane_fmt[0].bytesperline * pix->height;
>  }
>
>
> --
> 2.55.0
>
>

  reply	other threads:[~2026-11-16 11:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 19:55 [PATCH v2 0/4] media: rcar-isp: Add NV12M support and fix stride Niklas Söderlund
2026-11-14 19:55 ` [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input Niklas Söderlund
2026-11-16 11:21   ` Jacopo Mondi [this message]
2026-11-14 19:55 ` [PATCH v2 2/4] media: rcar-isp: ispcore: Update image data flush settings Niklas Söderlund
2026-11-14 19:55 ` [PATCH v2 3/4] media: rcar-isp: ispcore: Look at number of planes when programming Niklas Söderlund
2026-11-14 19:55 ` [PATCH v2 4/4] media: rcar-isp: ispcore: Add NV12M support Niklas Söderlund

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=avrjjCYcqsQOzhvf@zed \
    --to=jacopo.mondi@ideasonboard.com \
    --cc=barnabas.pocze+renesas@ideasonboard.com \
    --cc=geert+renesas@glider.be \
    --cc=jacopo.mondi+renesas@ideasonboard.com \
    --cc=jai.luthra+renesas@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=yusuke.goda.sx@renesas.com \
    --cc=yuya.hamamachi.sx@renesas.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

all inboxes | Powered by JetHome®