From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E21AACD342F for ; Fri, 8 May 2026 21:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j/W7yF4iOzAybbzn+adlgTCiE6+XgdcWBL2jlioW4B0=; b=HPNr9uPnTmz8qBDso41EAUnoP6 RhqjjAk+P8AXWLnieJjqwOOS7cG6KpFmY56XMvhQ45bwdJHetjG72TzJAnE/UEFHoje8NtDoNXXVF 3qyMsgv1f6QeNIlin6ayLIlGCYrPzxz/grlFqmoh5D/R3vWOt4sU4oEqLOn1y9tYhTlGivbGl3iHB Y5Rd9XHOUJirFSFWLt7Yy1B/VLktIi6Pt8Zu5pnEKcXoTd+/9vtpoVWhYVkt3UU6MRxTUtStX6EP/ G0OTfF7WWQUJ2pBKG49jqkzMKzGX+X8eiJFrlVl88DWsIQF3PUtAnrCCBh3PKAh3H39KO7yWpQlP/ mQ+PyJkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wLSRo-00000007W82-0SCE; Fri, 08 May 2026 21:09:24 +0000 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wLSRl-00000007W7A-3RPQ for linux-arm-kernel@lists.infradead.org; Fri, 08 May 2026 21:09:23 +0000 Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-8b4000e51fdso24934306d6.1 for ; Fri, 08 May 2026 14:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ndufresne-ca.20251104.gappssmtp.com; s=20251104; t=1778274560; x=1778879360; darn=lists.infradead.org; h=mime-version:user-agent:autocrypt:references:in-reply-to:date:cc:to :from:subject:message-id:from:to:cc:subject:date:message-id:reply-to; bh=j/W7yF4iOzAybbzn+adlgTCiE6+XgdcWBL2jlioW4B0=; b=zmlPYcWA9BqWG3Rhu6Otx/a15B1b/Np+UTqRysi2tvghdwzwKAXjrgeebLZMWkwMKP /g+MR+fERAQ+1MBkszjlZs39HcCM9058de2RgEgaPXsh56BMSKQcD4+vNGaG/vEv1NKO muR6lo1aHSbMqqiML6kA6Tp4SqaokQKOCSE7yrQ8Ja/wo4W81okk6JlxXruz9AT0IHd6 ZVKU8cmyLyMzna0drFJKHuvsEPeJ4G3f2YJLfeMObeDSivG3SS1dGmDp7Rr4fC16gYHM biyRyxng+ONp/qZUivIS6CG9rMi3GhEjIAykO788p5nwpPXSl3wU8AFLhyadQAjyzOFc KDWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778274560; x=1778879360; h=mime-version:user-agent:autocrypt:references:in-reply-to:date:cc:to :from:subject:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j/W7yF4iOzAybbzn+adlgTCiE6+XgdcWBL2jlioW4B0=; b=OX76drmHUXn3bXkDxmTHFZsoa14jXdiGAioocN5ekbBh8V8KfQ2avRSZBAOgxSPWin /tRjDsmN7yXW/Dz983itTAeQbVUJjkV0cfkgjTHCTZMr/wXi7/GBDo3kTpfic2hFzTLZ 2WFYRuH2sB89KOn8yPldSk7htEVGMqijmQqisbrHWmeFkdhjaeuX6XIiaRQflqjMqkpH 0/RgbbpV3KQyLetFK76iEvsIiRmoou+pz+YkBoebT2ZhZ+FhC2tGasvpgFBqs4XekPqn qAwlC6g5VufkP0xaUDOfCTUyqyyu2f0WBWKpfZqgGbUeaf+yxhdzsvKLMXNWskYOn+pO oGow== X-Forwarded-Encrypted: i=1; AFNElJ/h5Khq4gk09AiW4b5SaD6Ikx9ycF8+C3sLFwrDiQyVITxkBgr/pfGjBF8YnBjUIK14IkBxLCTOljPKq5778aFO@lists.infradead.org X-Gm-Message-State: AOJu0Yx82vWEYLfHcmUjICB4qixQ9USt8zCqbJVXsaG4yzODAxbR2ZNK 0Z/nzk2PsPSQVXLeb0vzcO3wGHVAVjNI+ai1GEoMF5KpsHRTKiAxq1sKLEmzz9jgjwE= X-Gm-Gg: Acq92OGebyG4DnrfHBM1ABF9WVuYofAqSDN6JJ2+t+Athq/JmS/YNhDiLbkO2SV0RM+ 5tvuLBX2vvBFT/uV57HHccbmDOBWiQFpXwpXvEyMLvTCFBEzVnywNef3yTKYRatuZS2ez53WBU4 XSXsKhjawYNaIAYE+frJcdwkeS0M/1BNgh6o6XBykyTntB+b2ss2hA0qrIrkBq7TXX+UgPr6meH I/u9pUkHjinZspbFYpfZPVDMjAnhxLeq1AtxEmJSX90Pz4v/raiPLIlWis7O/hx85KBzD6KMRer vzSQI/+PzXPv+RwCqvhjnPxqOG9YXX3RhYskZojrnaak20fgJA1KjEwQDaIJB/DkCV5gBgAVi5w TZGAyp22MVUltFUsSWckzNbnbsKOP/m4RE6SdxQ7wAl1s4GCEXgHsxfh8jd1tAuHg5y3Sj5vosp vwULaFqYbnNq7juT2Jx36LITHIjZcC X-Received: by 2002:a05:6214:4c81:b0:8ac:b24a:f543 with SMTP id 6a1803df08f44-8bc464f4650mr207346636d6.50.1778274560503; Fri, 08 May 2026 14:09:20 -0700 (PDT) Received: from ?IPv6:2606:6d00:15:e06b::c41? ([2606:6d00:15:e06b::c41]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8bf39c82420sm33673916d6.33.2026.05.08.14.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 14:09:19 -0700 (PDT) Message-ID: <2818a1f2be8dac4c7bc83046ed3a9ba3a11cf62d.camel@ndufresne.ca> Subject: Re: [PATCH v5 05/29] media: v4l2-common: add v4l2_fill_pixfmt_mp_aligned helper From: Nicolas Dufresne To: Sven =?ISO-8859-1?Q?P=FCschel?= , Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, sebastian.reichel@collabora.com Date: Fri, 08 May 2026 17:09:17 -0400 In-Reply-To: <20260428-spu-rga3-v5-5-eb7f5d019d86@pengutronix.de> References: <20260428-spu-rga3-v5-0-eb7f5d019d86@pengutronix.de> <20260428-spu-rga3-v5-5-eb7f5d019d86@pengutronix.de> Autocrypt: addr=nicolas@ndufresne.ca; prefer-encrypt=mutual; keydata=mDMEaCN2ixYJKwYBBAHaRw8BAQdAM0EHepTful3JOIzcPv6ekHOenE1u0vDG1gdHFrChD /e0J05pY29sYXMgRHVmcmVzbmUgPG5pY29sYXNAbmR1ZnJlc25lLmNhPoicBBMWCgBEAhsDBQsJCA cCAiICBhUKCQgLAgQWAgMBAh4HAheABQkJZfd1FiEE7w1SgRXEw8IaBG8S2UGUUSlgcvQFAmibrjo CGQEACgkQ2UGUUSlgcvQlQwD/RjpU1SZYcKG6pnfnQ8ivgtTkGDRUJ8gP3fK7+XUjRNIA/iXfhXMN abIWxO2oCXKf3TdD7aQ4070KO6zSxIcxgNQFtDFOaWNvbGFzIER1ZnJlc25lIDxuaWNvbGFzLmR1Z nJlc25lQGNvbGxhYm9yYS5jb20+iJkEExYKAEECGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4 AWIQTvDVKBFcTDwhoEbxLZQZRRKWBy9AUCaCyyxgUJCWX3dQAKCRDZQZRRKWBy9ARJAP96pFmLffZ smBUpkyVBfFAf+zq6BJt769R0al3kHvUKdgD9G7KAHuioxD2v6SX7idpIazjzx8b8rfzwTWyOQWHC AAS0LU5pY29sYXMgRHVmcmVzbmUgPG5pY29sYXMuZHVmcmVzbmVAZ21haWwuY29tPoiZBBMWCgBBF iEE7w1SgRXEw8IaBG8S2UGUUSlgcvQFAmibrGYCGwMFCQll93UFCwkIBwICIgIGFQoJCAsCBBYCAw ECHgcCF4AACgkQ2UGUUSlgcvRObgD/YnQjfi4+L8f4fI7p1pPMTwRTcaRdy6aqkKEmKsCArzQBAK8 bRLv9QjuqsE6oQZra/RB4widZPvphs78H0P6NmpIJ Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-DjeBDKHW1TZncnU04JxD" User-Agent: Evolution 3.60.1 (3.60.1-1.fc44) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260508_140922_024504_C0DC0224 X-CRM114-Status: GOOD ( 24.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --=-DjeBDKHW1TZncnU04JxD Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le mardi 28 avril 2026 =C3=A0 11:00 +0200, Sven P=C3=BCschel a =C3=A9crit= =C2=A0: > Add a v4l2_fill_pixfmt_mp_aligned helper which allows the user to > specify a custom stride alignment in bytes. This is necessary for > hardware like the Rockchip RGA3, which requires the stride value to be > aligned to a 16 bytes boundary. >=20 > The code makes some assumptions about the v4l2 format to simplify the > calculation. They currently hold for all known v4l2 formats. >=20 > Signed-off-by: Sven P=C3=BCschel Reviewed-by: Nicolas Dufresne > --- > =C2=A0drivers/media/v4l2-core/v4l2-common.c | 51 ++++++++++++++++++++++++= ++--------- > =C2=A0include/media/v4l2-common.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0 4 +++ > =C2=A02 files changed, 43 insertions(+), 12 deletions(-) >=20 > diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-c= ore/v4l2-common.c > index 2b5ccedeb6841..d64d7e76c834d 100644 > --- a/drivers/media/v4l2-core/v4l2-common.c > +++ b/drivers/media/v4l2-core/v4l2-common.c > @@ -431,14 +431,28 @@ static inline unsigned int v4l2_format_block_height= (const struct v4l2_format_inf > =C2=A0} > =C2=A0 > =C2=A0static inline unsigned int v4l2_format_plane_stride(const struct v4= l2_format_info *info, int plane, > - =C2=A0=C2=A0=C2=A0 unsigned int width) > + =C2=A0=C2=A0=C2=A0 unsigned int width, u8 byte_alignment) > =C2=A0{ > =C2=A0 unsigned int hdiv =3D plane ? info->hdiv : 1; > =C2=A0 unsigned int aligned_width =3D > =C2=A0 ALIGN(width, v4l2_format_block_width(info, plane)); > =C2=A0 > - return DIV_ROUND_UP(aligned_width, hdiv) * > - =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 info->bpp[plane] / info->bpp_div[p= lane]; > + /* > + * Formats with a single memory plane derive the stride of the > + * other planes from the y stride. Due to chroma subsampling this > + * may cause the other plane strides to break the byte_alignment. > + * Increase the alignment if necessary to prevent this. > + * > + * It assumes the following format properties: > + * - bpp_div[0] =3D=3D bpp_div[1] > + * - The multiplication factor doesn't differ between the non y planes > + */ > + if (info->mem_planes =3D=3D 1 && info->comp_planes > 1 && plane =3D=3D = 0) > + byte_alignment *=3D info->hdiv * info->bpp[0] / info->bpp[1]; > + > + return ALIGN(DIV_ROUND_UP(aligned_width, hdiv) * info->bpp[plane] / > + =C2=A0=C2=A0=C2=A0=C2=A0 info->bpp_div[plane], > + =C2=A0=C2=A0=C2=A0=C2=A0 byte_alignment); > =C2=A0} > =C2=A0 > =C2=A0static inline unsigned int v4l2_format_plane_height(const struct v4= l2_format_info *info, int plane, > @@ -452,9 +466,10 @@ static inline unsigned int v4l2_format_plane_height(= const struct v4l2_format_inf > =C2=A0} > =C2=A0 > =C2=A0static inline unsigned int v4l2_format_plane_size(const struct v4l2= _format_info *info, int plane, > - =C2=A0 unsigned int width, unsigned int height) > + =C2=A0 unsigned int width, unsigned int height, > + =C2=A0 u8 stride_alignment) > =C2=A0{ > - return v4l2_format_plane_stride(info, plane, width) * > + return v4l2_format_plane_stride(info, plane, width, stride_alignment) * > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 v4l2_format_plane_height(info= , plane, height); > =C2=A0} > =C2=A0 > @@ -475,8 +490,9 @@ void v4l2_apply_frmsize_constraints(u32 *width, u32 *= height, > =C2=A0} > =C2=A0EXPORT_SYMBOL_GPL(v4l2_apply_frmsize_constraints); > =C2=A0 > -int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, > - u32 pixelformat, u32 width, u32 height) > +int v4l2_fill_pixfmt_mp_aligned(struct v4l2_pix_format_mplane *pixfmt, > + u32 pixelformat, u32 width, u32 height, > + u8 stride_alignment) > =C2=A0{ > =C2=A0 const struct v4l2_format_info *info; > =C2=A0 struct v4l2_plane_pix_format *plane; > @@ -493,23 +509,34 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mpla= ne *pixfmt, > =C2=A0 > =C2=A0 if (info->mem_planes =3D=3D 1) { > =C2=A0 plane =3D &pixfmt->plane_fmt[0]; > - plane->bytesperline =3D v4l2_format_plane_stride(info, 0, width); > + plane->bytesperline =3D v4l2_format_plane_stride(info, 0, width, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 stride_alignment); > =C2=A0 plane->sizeimage =3D 0; > =C2=A0 > =C2=A0 for (i =3D 0; i < info->comp_planes; i++) > =C2=A0 plane->sizeimage +=3D > - v4l2_format_plane_size(info, i, width, height); > + v4l2_format_plane_size(info, i, width, height, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 stride_alignment); > =C2=A0 } else { > =C2=A0 for (i =3D 0; i < info->comp_planes; i++) { > =C2=A0 plane =3D &pixfmt->plane_fmt[i]; > =C2=A0 plane->bytesperline =3D > - v4l2_format_plane_stride(info, i, width); > + v4l2_format_plane_stride(info, i, width, > + stride_alignment); > =C2=A0 plane->sizeimage =3D plane->bytesperline * > =C2=A0 v4l2_format_plane_height(info, i, height); > =C2=A0 } > =C2=A0 } > =C2=A0 return 0; > =C2=A0} > +EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_mp_aligned); > + > +int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, > + u32 pixelformat, u32 width, u32 height) > +{ > + return v4l2_fill_pixfmt_mp_aligned(pixfmt, pixelformat, > + =C2=A0=C2=A0 width, height, 1); > +} > =C2=A0EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_mp); > =C2=A0 > =C2=A0int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelforma= t, > @@ -529,12 +556,12 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt= , u32 pixelformat, > =C2=A0 pixfmt->width =3D width; > =C2=A0 pixfmt->height =3D height; > =C2=A0 pixfmt->pixelformat =3D pixelformat; > - pixfmt->bytesperline =3D v4l2_format_plane_stride(info, 0, width); > + pixfmt->bytesperline =3D v4l2_format_plane_stride(info, 0, width, 1); > =C2=A0 pixfmt->sizeimage =3D 0; > =C2=A0 > =C2=A0 for (i =3D 0; i < info->comp_planes; i++) > =C2=A0 pixfmt->sizeimage +=3D > - v4l2_format_plane_size(info, i, width, height); > + v4l2_format_plane_size(info, i, width, height, 1); > =C2=A0 return 0; > =C2=A0} > =C2=A0EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt); > diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h > index 401d8506c24b5..edd416178c333 100644 > --- a/include/media/v4l2-common.h > +++ b/include/media/v4l2-common.h > @@ -558,6 +558,10 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt,= u32 pixelformat, > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 u32 width, u32 height); > =C2=A0int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 = pixelformat, > =C2=A0 u32 width, u32 height); > +/* @stride_alignment is a power of 2 value in bytes */ > +int v4l2_fill_pixfmt_mp_aligned(struct v4l2_pix_format_mplane *pixfmt, > + u32 pixelformat, u32 width, u32 height, > + u8 stride_alignment); > =C2=A0 > =C2=A0/** > =C2=A0 * v4l2_get_link_freq - Get link rate from transmitter --=-DjeBDKHW1TZncnU04JxD Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTvDVKBFcTDwhoEbxLZQZRRKWBy9AUCaf5Q/QAKCRDZQZRRKWBy 9AnlAP9cooZ/VayjTUTxzM//lgkDGPmrBKHxbxW/WchUCxMWBwD/ez/nSbGJZ/64 eie7bw26VxXneIW/zvSNXCU5L5Fivgg= =frYa -----END PGP SIGNATURE----- --=-DjeBDKHW1TZncnU04JxD--