From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9ABC93385A3 for ; Wed, 3 Dec 2025 15:54:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777244; cv=none; b=rYSHrr4JN1gzQwypYOJw15df3JN2N3qtlwLSdqZoyoHMvQ1vfnRBQKIZyTYbRPo8kV+t1bMWCRcp+2Z5rqzhl1+z2XEEGYhTRSSPgrOH4UaJcYUKwlAmKZbwOMbXMviH3vlYg72gRnjftgX2QHfDbAKCfDqdV4EwPEXLjrs+LzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777244; c=relaxed/simple; bh=1iKX6yGh144AM2DwtL+VDliq5LXQEDHsXQf9gW15O7Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OVJ9bOnPfqSANk8zkL3dG3IMogXIJz8rOdKTeIFd7uigyAxRoqS5rKvMJ6oH1WKswd4QzOVa7bRwzDWMgEnEVzLaEA1psEGFAa7Oo5N+pTffxJzzjFLtTQ7WoI6Pxj95Ao58nvhaobY3pBRBHn/AH1O5RDHPeNly0/keCRtupdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAc-0007dW-Hs; Wed, 03 Dec 2025 16:53:34 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:23 +0100 Subject: [PATCH v2 01/22] media: dt-bindings: media: rockchip-rga: add rockchip,rk3588-rga3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-1-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add a new compatible for the RGA3 (Raster Graphic Acceleration 3) peripheral found on the RK3588 SoC. The existing rga node refers to the RGA2 peripheral. The RK3588 contains one RGA2 core and two RGA3 cores. Both feature a similar functionality of scaling, cropping and rotating of up to two input images into one output image. Key differences of the RGA3 are: - supports 10bit YUV output formats - supports 8x8 tiles and FBCD as inputs and outputs - supports BT2020 color space conversion - max output resolution of (8192-64)x(8192-64) - MMU can map up to 32G DDR RAM - fully planar formats (3 planes) are not supported - max scale up/down factor of 8 Signed-off-by: Sven P=C3=BCschel Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/media/rockchip-rga.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/rockchip-rga.yaml b/Do= cumentation/devicetree/bindings/media/rockchip-rga.yaml index ac17cda65191b..4d11ca313749f 100644 --- a/Documentation/devicetree/bindings/media/rockchip-rga.yaml +++ b/Documentation/devicetree/bindings/media/rockchip-rga.yaml @@ -9,7 +9,9 @@ title: Rockchip 2D raster graphic acceleration controller (= RGA) description: RGA is a standalone 2D raster graphic acceleration unit. It accelerates = 2D graphics operations, such as point/line drawing, image scaling, rotation, - BitBLT, alpha blending and image blur/sharpness. + BitBLT, alpha blending and image blur/sharpness. There exist two variants + named RGA2 and RGA3 that differ in the supported inputs/output formats, + the attached IOMMU and the supported operations on the input. =20 maintainers: - Jacob Chen @@ -20,6 +22,7 @@ properties: oneOf: - const: rockchip,rk3288-rga - const: rockchip,rk3399-rga + - const: rockchip,rk3588-rga3 - items: - enum: - rockchip,rk3228-rga --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8F8D33A714 for ; Wed, 3 Dec 2025 15:54:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777248; cv=none; b=QT966KPkdYSWoWAr+o2aX0etIm02tu1Fs4VTtVnLuKdTxDbHUacvUajAUAF5Ea35ZXl6ZATf6r/P0qMKp6T3GMJI9oIQ9X/QojY+FBBXurXVPYL6SqkzxR/Hs+Fg+mf1FqeXFA9ZjM7/ydTHSr4Mb7uXt6Oasl/RogkE20XO538= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777248; c=relaxed/simple; bh=J7mwH984cvIJIJhiTwxB1iDiluiow76CQADuzkbExEo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lAjhWMI1EvxUT3/Sr9e4NlxSfTEhdRo69gOgwBmuq7ngXAH4lBYcxrrWK7KQ6h+MCmIwcpZYuvDVvRKXiHAk3hvqsf0dx38yV/4vVRDSTy3/tmKiwZM3w0fKC6mxpNAqAQQKFutLmzvLnHgzHxbs9ihu++fQRRmQHY1JUTWSxPY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAc-0007dW-L5; Wed, 03 Dec 2025 16:53:34 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:24 +0100 Subject: [PATCH v2 02/22] media: v4l2-common: add has_alpha to v4l2_format_info Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-2-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add a has_alpha value to the v4l2_format_info struct to indicate if the format contains an alpha component. The implementation is based on the drm_format_info implementation. Signed-off-by: Sven P=C3=BCschel --- drivers/media/v4l2-core/v4l2-common.c | 14 +++++++------- include/media/v4l2-common.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-cor= e/v4l2-common.c index 554c591e11133..2c7ac70c0f486 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -256,10 +256,10 @@ const struct v4l2_format_info *v4l2_format_info(u32 f= ormat) { .format =3D V4L2_PIX_FMT_XRGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGBX32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_HSV32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ARGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBA32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ABGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGRA32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, + { .format =3D V4L2_PIX_FMT_RGBA32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, + { .format =3D V4L2_PIX_FMT_ABGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, + { .format =3D V4L2_PIX_FMT_BGRA32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_RGB565, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB565X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, @@ -267,10 +267,10 @@ const struct v4l2_format_info *v4l2_format_info(u32 f= ormat) { .format =3D V4L2_PIX_FMT_BGR48_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_BGR48, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .me= m_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div =3D {= 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB48, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .me= m_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div =3D {= 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ABGR64_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 8, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBA1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR64_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 8, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, + { .format =3D V4L2_PIX_FMT_RGBA1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_RGBX1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ARGB2101010, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB2101010, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, =20 /* YUV packed formats */ { .format =3D V4L2_PIX_FMT_YUYV, .pixel_enc =3D V4L2_PIXEL_ENC_YUV, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 2, .vdiv =3D 1 }, diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index f8b1faced79c8..401d8506c24b5 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -520,6 +520,7 @@ enum v4l2_pixel_encoding { * @vdiv: Vertical chroma subsampling factor * @block_w: Per-plane macroblock pixel width (optional) * @block_h: Per-plane macroblock pixel height (optional) + * @has_alpha: Does the format embeds an alpha component? */ struct v4l2_format_info { u32 format; @@ -532,6 +533,7 @@ struct v4l2_format_info { u8 vdiv; u8 block_w[4]; u8 block_h[4]; + bool has_alpha; }; =20 static inline bool v4l2_is_format_rgb(const struct v4l2_format_info *f) --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B774133BBAC for ; Wed, 3 Dec 2025 15:54:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777255; cv=none; b=LcIAwG+VI0rDmAMeCtYDiNicv75flMF3GaFxZ6ScKgDnvmO3xKvmG5dRL4I2nr1GSG2nXVnqkszcUyyUIaiJzXZm9X3iqdrHPwiI8+8l06y9MDwZKfyS75SJrWMgYWziWedn8A+EQY4C+ScfJpL5TBrNlkEBD9WcMS399K1GCq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777255; c=relaxed/simple; bh=S1KRTM8otBDVIbKewLunEJ3SPlMTmvRMefwX2WHTke0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mCP+EpjlbgL5/oZVPjI49BiuY8RLT8559DybsgCblzlMNBvifmRbLpCxYCVgiZMyi4WqSWykg1zopvmEsYbl9t3mqMTw1ghM+LSoxdMUZ9NqIFyMlBVS/CrEd0bXfiQwkOHfB5p2cAxyKgfbOU4MtEajd3sVEsvOOJMhlwYRg3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAc-0007dW-Oc; Wed, 03 Dec 2025 16:53:34 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:25 +0100 Subject: [PATCH v2 03/22] media: v4l2-common: add v4l2_fill_pixfmt_mp_aligned helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-3-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org 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 byte boundary. Signed-off-by: Sven P=C3=BCschel --- drivers/media/v4l2-core/v4l2-common.c | 34 ++++++++++++++++++++++++-------= --- include/media/v4l2-common.h | 4 ++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-cor= e/v4l2-common.c index 2c7ac70c0f486..f86e7d7d29b8e 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -404,11 +404,12 @@ static inline unsigned int v4l2_format_block_height(c= onst struct v4l2_format_inf } =20 static inline unsigned int v4l2_format_plane_stride(const struct v4l2_form= at_info *info, int plane, - unsigned int width) + unsigned int width, u8 alignment) { unsigned int hdiv =3D plane ? info->hdiv : 1; unsigned int aligned_width =3D ALIGN(width, v4l2_format_block_width(info, plane)); + aligned_width =3D ALIGN(aligned_width, alignment); =20 return DIV_ROUND_UP(aligned_width, hdiv) * info->bpp[plane] / info->bpp_div[plane]; @@ -425,9 +426,10 @@ static inline unsigned int v4l2_format_plane_height(co= nst struct v4l2_format_inf } =20 static inline unsigned int v4l2_format_plane_size(const struct v4l2_format= _info *info, int plane, - unsigned int width, unsigned int height) + unsigned int width, unsigned int height, + u8 stride_alignment) { - return v4l2_format_plane_stride(info, plane, width) * + return v4l2_format_plane_stride(info, plane, width, stride_alignment) * v4l2_format_plane_height(info, plane, height); } =20 @@ -448,8 +450,9 @@ void v4l2_apply_frmsize_constraints(u32 *width, u32 *he= ight, } EXPORT_SYMBOL_GPL(v4l2_apply_frmsize_constraints); =20 -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) { const struct v4l2_format_info *info; struct v4l2_plane_pix_format *plane; @@ -466,23 +469,34 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane= *pixfmt, =20 if (info->mem_planes =3D=3D 1) { 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, + stride_alignment); plane->sizeimage =3D 0; =20 for (i =3D 0; i < info->comp_planes; i++) plane->sizeimage +=3D - v4l2_format_plane_size(info, i, width, height); + v4l2_format_plane_size(info, i, width, height, + stride_alignment); } else { for (i =3D 0; i < info->comp_planes; i++) { plane =3D &pixfmt->plane_fmt[i]; plane->bytesperline =3D - v4l2_format_plane_stride(info, i, width); + v4l2_format_plane_stride(info, i, width, + stride_alignment); plane->sizeimage =3D plane->bytesperline * v4l2_format_plane_height(info, i, height); } } return 0; } +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, + width, height, 1); +} EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_mp); =20 int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, @@ -502,12 +516,12 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, = u32 pixelformat, pixfmt->width =3D width; pixfmt->height =3D height; 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); pixfmt->sizeimage =3D 0; =20 for (i =3D 0; i < info->comp_planes; i++) pixfmt->sizeimage +=3D - v4l2_format_plane_size(info, i, width, height); + v4l2_format_plane_size(info, i, width, height, 1); return 0; } EXPORT_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, u= 32 pixelformat, u32 width, u32 height); int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelfo= rmat, 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); =20 /** * v4l2_get_link_freq - Get link rate from transmitter --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CEEE33A71F for ; Wed, 3 Dec 2025 15:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777249; cv=none; b=J5vngYm8+xdGLlJdqdzDwqU3iPkppFori+FnHYXilkpRExelqrcjm5vqsH1L+M7/e1xPsnLjN5gXATHrTG15QmUrxT/UYs6PK2Pq3QhJHGHxqZVSZBDO+GQnSFOlIEo1+pKVb5cekjTgq6NEAvqT5t8ShaHYhPZgUdxsQsARZ3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777249; c=relaxed/simple; bh=91K69kTgFVyqoZdNHEA1NXAnIQwM6WFuUF+QYV8K9xs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q2SIJfBx6ZXrLVwwk7SoF0HFFQjoKuUAKoEzkAY7aPaVvpoH5YkhrOkLqDuvstWnlvO/VivmrWABWf/YkPTNRPM/Fk1Sj5M1pPN5V68BW/fohLyRVUbwNA/co987q6Jm30BTznbpGt64/saLKUtkQoyyO/fOH9sIWeWPUd+n6rQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAc-0007dW-S2; Wed, 03 Dec 2025 16:53:34 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:26 +0100 Subject: [PATCH v2 04/22] media: rockchip: rga: use clk_bulk api Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-4-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Use the clk_bulk API to avoid code duplication for each of the three clocks. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 64 ++++-----------------------= ---- drivers/media/platform/rockchip/rga/rga.h | 5 +-- 2 files changed, 9 insertions(+), 60 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 43f6a8d993811..ef568b3758380 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -698,48 +698,10 @@ static const struct video_device rga_videodev =3D { .device_caps =3D V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING, }; =20 -static int rga_enable_clocks(struct rockchip_rga *rga) -{ - int ret; - - ret =3D clk_prepare_enable(rga->sclk); - if (ret) { - dev_err(rga->dev, "Cannot enable rga sclk: %d\n", ret); - return ret; - } - - ret =3D clk_prepare_enable(rga->aclk); - if (ret) { - dev_err(rga->dev, "Cannot enable rga aclk: %d\n", ret); - goto err_disable_sclk; - } - - ret =3D clk_prepare_enable(rga->hclk); - if (ret) { - dev_err(rga->dev, "Cannot enable rga hclk: %d\n", ret); - goto err_disable_aclk; - } - - return 0; - -err_disable_aclk: - clk_disable_unprepare(rga->aclk); -err_disable_sclk: - clk_disable_unprepare(rga->sclk); - - return ret; -} - -static void rga_disable_clocks(struct rockchip_rga *rga) -{ - clk_disable_unprepare(rga->sclk); - clk_disable_unprepare(rga->hclk); - clk_disable_unprepare(rga->aclk); -} - static int rga_parse_dt(struct rockchip_rga *rga) { struct reset_control *core_rst, *axi_rst, *ahb_rst; + int ret; =20 core_rst =3D devm_reset_control_get(rga->dev, "core"); if (IS_ERR(core_rst)) { @@ -771,22 +733,10 @@ static int rga_parse_dt(struct rockchip_rga *rga) udelay(1); reset_control_deassert(ahb_rst); =20 - rga->sclk =3D devm_clk_get(rga->dev, "sclk"); - if (IS_ERR(rga->sclk)) { - dev_err(rga->dev, "failed to get sclk clock\n"); - return PTR_ERR(rga->sclk); - } - - rga->aclk =3D devm_clk_get(rga->dev, "aclk"); - if (IS_ERR(rga->aclk)) { - dev_err(rga->dev, "failed to get aclk clock\n"); - return PTR_ERR(rga->aclk); - } - - rga->hclk =3D devm_clk_get(rga->dev, "hclk"); - if (IS_ERR(rga->hclk)) { - dev_err(rga->dev, "failed to get hclk clock\n"); - return PTR_ERR(rga->hclk); + ret =3D devm_clk_bulk_get(rga->dev, ARRAY_SIZE(rga->clks), rga->clks); + if (ret) { + dev_err(rga->dev, "failed to get clocks\n"); + return ret; } =20 return 0; @@ -935,7 +885,7 @@ static int __maybe_unused rga_runtime_suspend(struct de= vice *dev) { struct rockchip_rga *rga =3D dev_get_drvdata(dev); =20 - rga_disable_clocks(rga); + clk_bulk_disable_unprepare(ARRAY_SIZE(rga->clks), rga->clks); =20 return 0; } @@ -944,7 +894,7 @@ static int __maybe_unused rga_runtime_resume(struct dev= ice *dev) { struct rockchip_rga *rga =3D dev_get_drvdata(dev); =20 - return rga_enable_clocks(rga); + return clk_bulk_prepare_enable(ARRAY_SIZE(rga->clks), rga->clks); } =20 static const struct dev_pm_ops rga_pm =3D { diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 72a28b120fabf..a922fac0c01a3 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -6,6 +6,7 @@ #ifndef __RGA_H__ #define __RGA_H__ =20 +#include #include #include #include @@ -81,9 +82,7 @@ struct rockchip_rga { struct device *dev; struct regmap *grf; void __iomem *regs; - struct clk *sclk; - struct clk *aclk; - struct clk *hclk; + struct clk_bulk_data clks[3]; struct rockchip_rga_version version; =20 /* vfd lock */ --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56892337103 for ; Wed, 3 Dec 2025 15:54:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777245; cv=none; b=uixI479wj3lHQ1PyNO+p9zUrKSMXBpAZpIKj8oTts6yZIQ7VihNcVgz13CShXtTEGvBIq0l7HlgdyDHw0ZeBaH3hVUVzB6cYutjkA6KY4oxLR1U1EyWFAqITglzCYl97QVTQMfJ1SG75IWQQhgG4iDZb84iO9f9WZAmBCYyvHXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777245; c=relaxed/simple; bh=+Z1AjhguhTucy98v/8QNfYO/LgsZOWNSPRoTFJfdjLQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E1YwaCqY3mlvMuX8qxZ8g9El8FEQa5nJyzBwjYlI2M6+5jvctMHlRSgZN0ZxsYJkMyVBaQo1gz+nKAmECpRflo4QvKguAKwWaRQteFqarfwHeS6fccuNCxP193GogtNCJsZLbP8WE9UhuZpztD3XPPcWHKMl9nGS4QEiMp6DXCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAc-0007dW-VQ; Wed, 03 Dec 2025 16:53:34 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:27 +0100 Subject: [PATCH v2 05/22] media: rockchip: rga: use stride for offset calculation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-5-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Use the stride instead of the width for the offset calculation. This ensures that the bytesperline value doesn't need to match the width value of the image. Furthermore this patch removes the dependency on the uv_factor property and instead reuses the v4l2_format_info to determine the correct division factor. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index 730bdf98565a5..b5e6b1b527ca8 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -14,7 +14,6 @@ #include #include =20 -#include "rga-hw.h" #include "rga.h" =20 static ssize_t fill_descriptors(struct rga_dma_desc *desc, size_t max_desc, @@ -92,14 +91,19 @@ static int rga_buf_init(struct vb2_buffer *vb) return 0; } =20 -static int get_plane_offset(struct rga_frame *f, int plane) +static int get_plane_offset(struct rga_frame *f, + const struct v4l2_format_info *info, + int plane) { + u32 stride =3D f->pix.plane_fmt[0].bytesperline; + if (plane =3D=3D 0) return 0; if (plane =3D=3D 1) - return f->width * f->height; + return stride * f->height; if (plane =3D=3D 2) - return f->width * f->height + (f->width * f->height / f->fmt->uv_factor); + return stride * f->height + + (stride * f->height / info->hdiv / info->vdiv); =20 return -EINVAL; } @@ -145,7 +149,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb) /* Fill the remaining planes */ info =3D v4l2_format_info(f->fmt->fourcc); for (i =3D info->mem_planes; i < info->comp_planes; i++) - offsets[i] =3D get_plane_offset(f, i); + offsets[i] =3D get_plane_offset(f, info, i); =20 rbuf->offset.y_off =3D offsets[0]; rbuf->offset.u_off =3D offsets[1]; --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C34ED33CEB6 for ; Wed, 3 Dec 2025 15:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777260; cv=none; b=Gk1OfHnCJ8hPjudjpPcTJkvUO0t50wUpJE8Q0CW6O1EIPz3rbhJJZcPzmHXVhbK5gRF9lNB87yFFzVny6prv/1deNMF6iZZGTXKFO0Z8KQ86wNn//F9VEa305yMTruOAODvZbHGbdJqfCBWEFTYYgMXY0n2z5EJ063lvx6Mi1WE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777260; c=relaxed/simple; bh=JqXs1xY0bABWRToTWbi2Ze6HDkaXyYHOGyGdtuEuuYA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FSQxMgL4LINjpXYjappdowHTxBecfP8EsMrG6pvRQCryVrHdHUay+tl1jkylTIfMK/t2uLdWg37BU0ZvvAz4PJRgxsrrOo35xcgXnDY0Odkog0Ax/0e9DgJVfv1WMciHTr9nOLXUrwxDBzCeTMGwKfQxRloxbdtLyzRBSEprX80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAd-0007dW-2J; Wed, 03 Dec 2025 16:53:35 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:28 +0100 Subject: [PATCH v2 06/22] media: rockchip: rga: remove redundant rga_frame variables Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-6-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Remove the redundant rga_frame variables width, height and color space. The value of these variables is already contained in the pix member of rga_frame. The code also keeps these values in sync. Therefore drop them in favor of the existing pix member. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 6 ++--- drivers/media/platform/rockchip/rga/rga-hw.c | 6 ++--- drivers/media/platform/rockchip/rga/rga.c | 32 ++++++++++-------------= ---- drivers/media/platform/rockchip/rga/rga.h | 5 ----- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index b5e6b1b527ca8..0c59a4d330888 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -100,10 +100,10 @@ static int get_plane_offset(struct rga_frame *f, if (plane =3D=3D 0) return 0; if (plane =3D=3D 1) - return stride * f->height; + return stride * f->pix.height; if (plane =3D=3D 2) - return stride * f->height + - (stride * f->height / info->hdiv / info->vdiv); + return stride * f->pix.height + + (stride * f->pix.height / info->hdiv / info->vdiv); =20 return -EINVAL; } diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 43ed742a16492..f1d5237472941 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -53,7 +53,7 @@ rga_get_addr_offset(struct rga_frame *frm, struct rga_add= r_offset *offset, x_div =3D frm->fmt->x_div; y_div =3D frm->fmt->y_div; uv_stride =3D frm->stride / x_div; - pixel_width =3D frm->stride / frm->width; + pixel_width =3D frm->stride / frm->pix.width; =20 lt->y_off =3D offset->y_off + y * frm->stride + x * pixel_width; lt->u_off =3D offset->u_off + (y / y_div) * uv_stride + x / x_div; @@ -191,7 +191,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) =20 if (RGA_COLOR_FMT_IS_YUV(ctx->in.fmt->hw_format) && RGA_COLOR_FMT_IS_RGB(ctx->out.fmt->hw_format)) { - switch (ctx->in.colorspace) { + switch (ctx->in.pix.colorspace) { case V4L2_COLORSPACE_REC709: src_info.data.csc_mode =3D RGA_SRC_CSC_MODE_BT709_R0; break; @@ -203,7 +203,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) =20 if (RGA_COLOR_FMT_IS_RGB(ctx->in.fmt->hw_format) && RGA_COLOR_FMT_IS_YUV(ctx->out.fmt->hw_format)) { - switch (ctx->out.colorspace) { + switch (ctx->out.pix.colorspace) { case V4L2_COLORSPACE_REC709: dst_info.data.csc_mode =3D RGA_SRC_CSC_MODE_BT709_R0; break; diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index ef568b3758380..f50fbbab0645e 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -345,9 +345,6 @@ static struct rga_fmt *rga_fmt_find(u32 pixelformat) } =20 static struct rga_frame def_frame =3D { - .width =3D DEFAULT_WIDTH, - .height =3D DEFAULT_HEIGHT, - .colorspace =3D V4L2_COLORSPACE_DEFAULT, .crop.left =3D 0, .crop.top =3D 0, .crop.width =3D DEFAULT_WIDTH, @@ -379,9 +376,9 @@ static int rga_open(struct file *file) ctx->out =3D def_frame; =20 v4l2_fill_pixfmt_mp(&ctx->in.pix, - ctx->in.fmt->fourcc, ctx->out.width, ctx->out.height); + ctx->in.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT); v4l2_fill_pixfmt_mp(&ctx->out.pix, - ctx->out.fmt->fourcc, ctx->out.width, ctx->out.height); + ctx->out.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT); =20 if (mutex_lock_interruptible(&rga->mutex)) { kfree(ctx); @@ -469,10 +466,8 @@ static int vidioc_g_fmt(struct file *file, void *priv,= struct v4l2_format *f) if (IS_ERR(frm)) return PTR_ERR(frm); =20 - v4l2_fill_pixfmt_mp(pix_fmt, frm->fmt->fourcc, frm->width, frm->height); - + *pix_fmt =3D frm->pix; pix_fmt->field =3D V4L2_FIELD_NONE; - pix_fmt->colorspace =3D frm->colorspace; =20 return 0; } @@ -521,27 +516,24 @@ static int vidioc_s_fmt(struct file *file, void *priv= , struct v4l2_format *f) frm =3D rga_get_frame(ctx, f->type); if (IS_ERR(frm)) return PTR_ERR(frm); - frm->width =3D pix_fmt->width; - frm->height =3D pix_fmt->height; frm->size =3D 0; for (i =3D 0; i < pix_fmt->num_planes; i++) frm->size +=3D pix_fmt->plane_fmt[i].sizeimage; frm->fmt =3D rga_fmt_find(pix_fmt->pixelformat); frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; - frm->colorspace =3D pix_fmt->colorspace; =20 /* Reset crop settings */ frm->crop.left =3D 0; frm->crop.top =3D 0; - frm->crop.width =3D frm->width; - frm->crop.height =3D frm->height; + frm->crop.width =3D pix_fmt->width; + frm->crop.height =3D pix_fmt->height; =20 frm->pix =3D *pix_fmt; =20 v4l2_dbg(debug, 1, &rga->v4l2_dev, "[%s] fmt - %p4cc %dx%d (stride %d, sizeimage %d)\n", V4L2_TYPE_IS_OUTPUT(f->type) ? "OUTPUT" : "CAPTURE", - &frm->fmt->fourcc, frm->width, frm->height, + &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, frm->stride, frm->size); =20 for (i =3D 0; i < pix_fmt->num_planes; i++) { @@ -595,8 +587,8 @@ static int vidioc_g_selection(struct file *file, void *= priv, } else { s->r.left =3D 0; s->r.top =3D 0; - s->r.width =3D f->width; - s->r.height =3D f->height; + s->r.width =3D f->pix.width; + s->r.height =3D f->pix.height; } =20 return 0; @@ -645,8 +637,8 @@ static int vidioc_s_selection(struct file *file, void *= priv, return -EINVAL; } =20 - if (s->r.left + s->r.width > f->width || - s->r.top + s->r.height > f->height || + if (s->r.left + s->r.width > f->pix.width || + s->r.top + s->r.height > f->pix.height || s->r.width < MIN_WIDTH || s->r.height < MIN_HEIGHT) { v4l2_dbg(debug, 1, &rga->v4l2_dev, "unsupported crop value.\n"); return -EINVAL; @@ -836,8 +828,8 @@ static int rga_probe(struct platform_device *pdev) goto rel_m2m; } =20 - def_frame.stride =3D (def_frame.width * def_frame.fmt->depth) >> 3; - def_frame.size =3D def_frame.stride * def_frame.height; + def_frame.stride =3D (DEFAULT_WIDTH * def_frame.fmt->depth) >> 3; + def_frame.size =3D def_frame.stride * DEFAULT_HEIGHT; =20 ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index a922fac0c01a3..7ec1fcc03ed32 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -25,11 +25,6 @@ struct rga_fmt { }; =20 struct rga_frame { - /* Original dimensions */ - u32 width; - u32 height; - u32 colorspace; - /* Crop */ struct v4l2_rect crop; =20 --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91A3D33EB0E for ; Wed, 3 Dec 2025 15:54:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777271; cv=none; b=i76ny+fx/Olpgwwg+UzG5fZpwlU0MqsEzAc/Mah3beZ78LnoqEIphZ7f6hDcZhvfZSKOVf/k0QTMlbvHSWKC7lr9tl6WPbFcwd1YQ5sZk7F0OyHxmeEHy2FnQ1bs9V+10/Hy0cvjzMo5y2FfR6BCffPXsMzE/Kw4Glv+1l1K0Cs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777271; c=relaxed/simple; bh=H7j5GUTtbWcZmKzomIajCTJhuI+yvK5wgbCGABvEgJM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cgQudJtFZLPZklmx0IvDP3jagXjcnjQf2zIYZxWjguiDy7nnP0CO9kg/ypCox/WMwu6X7cnflMtXqb/0aERdVFsWdSElAIERrhXX+fLoEm3pcA3/Afj+PXOUpXg0uehplwkPNIy5JnYGr6Dfq7qktdqWK+5Um1f//Jz6qf7gJqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAd-0007dW-5P; Wed, 03 Dec 2025 16:53:35 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:29 +0100 Subject: [PATCH v2 07/22] media: rockchip: rga: move hw specific parts to a dedicated struct Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-7-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org In preparation for the RGA3 unit, move RGA2 specific parts from rga.c to rga-hw.c and create a struct to reference the RGA2 specific functions and formats. This also allows to remove the rga-hw.h reference from the include list of the rga driver. Also document the command finish interrupt with a dedicated define. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 183 ++++++++++++++++++++- drivers/media/platform/rockchip/rga/rga-hw.h | 5 +- drivers/media/platform/rockchip/rga/rga.c | 228 +++++------------------= ---- drivers/media/platform/rockchip/rga/rga.h | 23 ++- 4 files changed, 245 insertions(+), 194 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index f1d5237472941..7419784efc693 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -437,8 +437,8 @@ static void rga_cmd_set(struct rga_ctx *ctx, PAGE_SIZE, DMA_BIDIRECTIONAL); } =20 -void rga_hw_start(struct rockchip_rga *rga, - struct rga_vb_buffer *src, struct rga_vb_buffer *dst) +static void rga_hw_start(struct rockchip_rga *rga, + struct rga_vb_buffer *src, struct rga_vb_buffer *dst) { struct rga_ctx *ctx =3D rga->curr; =20 @@ -452,3 +452,182 @@ void rga_hw_start(struct rockchip_rga *rga, =20 rga_write(rga, RGA_CMD_CTRL, 0x1); } + +static bool rga_handle_irq(struct rockchip_rga *rga) +{ + int intr; + + intr =3D rga_read(rga, RGA_INT) & 0xf; + + rga_mod(rga, RGA_INT, intr << 4, 0xf << 4); + + return intr & RGA_INT_COMMAND_FINISHED; +} + +static void rga_get_version(struct rockchip_rga *rga) +{ + rga->version.major =3D (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF; + rga->version.minor =3D (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F; +} + +static struct rga_fmt formats[] =3D { + { + .fourcc =3D V4L2_PIX_FMT_ARGB32, + .color_swap =3D RGA_COLOR_ALPHA_SWAP, + .hw_format =3D RGA_COLOR_FMT_ABGR8888, + .depth =3D 32, + .uv_factor =3D 1, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_ABGR32, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_ABGR8888, + .depth =3D 32, + .uv_factor =3D 1, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_XBGR32, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_XBGR8888, + .depth =3D 32, + .uv_factor =3D 1, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGB24, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_RGB888, + .depth =3D 24, + .uv_factor =3D 1, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_BGR24, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_RGB888, + .depth =3D 24, + .uv_factor =3D 1, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_ARGB444, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_ABGR4444, + .depth =3D 16, + .uv_factor =3D 1, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_ARGB555, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_ABGR1555, + .depth =3D 16, + .uv_factor =3D 1, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGB565, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_BGR565, + .depth =3D 16, + .uv_factor =3D 1, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV21, + .color_swap =3D RGA_COLOR_UV_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420SP, + .depth =3D 12, + .uv_factor =3D 4, + .y_div =3D 2, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV61, + .color_swap =3D RGA_COLOR_UV_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV422SP, + .depth =3D 16, + .uv_factor =3D 2, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV12, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420SP, + .depth =3D 12, + .uv_factor =3D 4, + .y_div =3D 2, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV12M, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420SP, + .depth =3D 12, + .uv_factor =3D 4, + .y_div =3D 2, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV16, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV422SP, + .depth =3D 16, + .uv_factor =3D 2, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_YUV420, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420P, + .depth =3D 12, + .uv_factor =3D 4, + .y_div =3D 2, + .x_div =3D 2, + }, + { + .fourcc =3D V4L2_PIX_FMT_YUV422P, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV422P, + + .depth =3D 16, + .uv_factor =3D 2, + .y_div =3D 1, + .x_div =3D 2, + }, + { + .fourcc =3D V4L2_PIX_FMT_YVU420, + .color_swap =3D RGA_COLOR_UV_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420P, + .depth =3D 12, + .uv_factor =3D 4, + .y_div =3D 2, + .x_div =3D 2, + }, +}; + +const struct rga_hw rga2_hw =3D { + .formats =3D formats, + .num_formats =3D ARRAY_SIZE(formats), + .cmdbuf_size =3D RGA_CMDBUF_SIZE, + .min_width =3D MIN_WIDTH, + .max_width =3D MAX_WIDTH, + .min_height =3D MIN_HEIGHT, + .max_height =3D MAX_HEIGHT, + + .start =3D rga_hw_start, + .handle_irq =3D rga_handle_irq, + .get_version =3D rga_get_version, +}; diff --git a/drivers/media/platform/rockchip/rga/rga-hw.h b/drivers/media/p= latform/rockchip/rga/rga-hw.h index cc6bd7f5b0300..f4752aa823051 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.h +++ b/drivers/media/platform/rockchip/rga/rga-hw.h @@ -15,9 +15,6 @@ #define MIN_WIDTH 34 #define MIN_HEIGHT 34 =20 -#define DEFAULT_WIDTH 100 -#define DEFAULT_HEIGHT 100 - #define RGA_TIMEOUT 500 =20 /* Registers address */ @@ -178,6 +175,8 @@ #define RGA_ALPHA_COLOR_NORMAL 0 #define RGA_ALPHA_COLOR_MULTIPLY_CAL 1 =20 +#define RGA_INT_COMMAND_FINISHED 4 + /* Registers union */ union rga_mode_ctrl { unsigned int val; diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index f50fbbab0645e..d8b14c2d9f6a4 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -25,7 +25,6 @@ #include #include =20 -#include "rga-hw.h" #include "rga.h" =20 static int debug; @@ -47,7 +46,7 @@ static void device_run(void *prv) =20 dst =3D v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); =20 - rga_hw_start(rga, vb_to_rga(src), vb_to_rga(dst)); + rga->hw->start(rga, vb_to_rga(src), vb_to_rga(dst)); =20 spin_unlock_irqrestore(&rga->ctrl_lock, flags); } @@ -55,13 +54,8 @@ static void device_run(void *prv) static irqreturn_t rga_isr(int irq, void *prv) { struct rockchip_rga *rga =3D prv; - int intr; =20 - intr =3D rga_read(rga, RGA_INT) & 0xf; - - rga_mod(rga, RGA_INT, intr << 4, 0xf << 4); - - if (intr & 0x04) { + if (rga->hw->handle_irq(rga)) { struct vb2_v4l2_buffer *src, *dst; struct rga_ctx *ctx =3D rga->curr; =20 @@ -184,174 +178,17 @@ static int rga_setup_ctrls(struct rga_ctx *ctx) return 0; } =20 -static struct rga_fmt formats[] =3D { - { - .fourcc =3D V4L2_PIX_FMT_ARGB32, - .color_swap =3D RGA_COLOR_ALPHA_SWAP, - .hw_format =3D RGA_COLOR_FMT_ABGR8888, - .depth =3D 32, - .uv_factor =3D 1, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_ABGR32, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_ABGR8888, - .depth =3D 32, - .uv_factor =3D 1, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_XBGR32, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_XBGR8888, - .depth =3D 32, - .uv_factor =3D 1, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_RGB24, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_RGB888, - .depth =3D 24, - .uv_factor =3D 1, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_BGR24, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_RGB888, - .depth =3D 24, - .uv_factor =3D 1, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_ARGB444, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_ABGR4444, - .depth =3D 16, - .uv_factor =3D 1, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_ARGB555, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_ABGR1555, - .depth =3D 16, - .uv_factor =3D 1, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_RGB565, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_BGR565, - .depth =3D 16, - .uv_factor =3D 1, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV21, - .color_swap =3D RGA_COLOR_UV_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, - .uv_factor =3D 4, - .y_div =3D 2, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV61, - .color_swap =3D RGA_COLOR_UV_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV422SP, - .depth =3D 16, - .uv_factor =3D 2, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV12, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, - .uv_factor =3D 4, - .y_div =3D 2, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV12M, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, - .uv_factor =3D 4, - .y_div =3D 2, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV16, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV422SP, - .depth =3D 16, - .uv_factor =3D 2, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_YUV420, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420P, - .depth =3D 12, - .uv_factor =3D 4, - .y_div =3D 2, - .x_div =3D 2, - }, - { - .fourcc =3D V4L2_PIX_FMT_YUV422P, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV422P, - .depth =3D 16, - .uv_factor =3D 2, - .y_div =3D 1, - .x_div =3D 2, - }, - { - .fourcc =3D V4L2_PIX_FMT_YVU420, - .color_swap =3D RGA_COLOR_UV_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420P, - .depth =3D 12, - .uv_factor =3D 4, - .y_div =3D 2, - .x_div =3D 2, - }, -}; - -#define NUM_FORMATS ARRAY_SIZE(formats) - -static struct rga_fmt *rga_fmt_find(u32 pixelformat) +static struct rga_fmt *rga_fmt_find(struct rockchip_rga *rga, u32 pixelfor= mat) { unsigned int i; =20 - for (i =3D 0; i < NUM_FORMATS; i++) { - if (formats[i].fourcc =3D=3D pixelformat) - return &formats[i]; + for (i =3D 0; i < rga->hw->num_formats; i++) { + if (rga->hw->formats[i].fourcc =3D=3D pixelformat) + return &rga->hw->formats[i]; } return NULL; } =20 -static struct rga_frame def_frame =3D { - .crop.left =3D 0, - .crop.top =3D 0, - .crop.width =3D DEFAULT_WIDTH, - .crop.height =3D DEFAULT_HEIGHT, - .fmt =3D &formats[0], -}; - struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type ty= pe) { if (V4L2_TYPE_IS_OUTPUT(type)) @@ -366,6 +203,18 @@ static int rga_open(struct file *file) struct rockchip_rga *rga =3D video_drvdata(file); struct rga_ctx *ctx =3D NULL; int ret =3D 0; + u32 def_width =3D clamp(DEFAULT_WIDTH, rga->hw->min_width, rga->hw->max_w= idth); + u32 def_height =3D clamp(DEFAULT_HEIGHT, rga->hw->min_height, rga->hw->ma= x_height); + struct rga_frame def_frame =3D { + .crop.left =3D 0, + .crop.top =3D 0, + .crop.width =3D def_width, + .crop.height =3D def_height, + .fmt =3D &rga->hw->formats[0], + }; + + def_frame.stride =3D (def_width * def_frame.fmt->depth) >> 3; + def_frame.size =3D def_frame.stride * def_height; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) @@ -376,9 +225,9 @@ static int rga_open(struct file *file) ctx->out =3D def_frame; =20 v4l2_fill_pixfmt_mp(&ctx->in.pix, - ctx->in.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT); + ctx->in.fmt->fourcc, def_width, def_height); v4l2_fill_pixfmt_mp(&ctx->out.pix, - ctx->out.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT); + ctx->out.fmt->fourcc, def_width, def_height); =20 if (mutex_lock_interruptible(&rga->mutex)) { kfree(ctx); @@ -445,12 +294,13 @@ vidioc_querycap(struct file *file, void *priv, struct= v4l2_capability *cap) =20 static int vidioc_enum_fmt(struct file *file, void *priv, struct v4l2_fmtd= esc *f) { + struct rockchip_rga *rga =3D video_drvdata(file); struct rga_fmt *fmt; =20 - if (f->index >=3D NUM_FORMATS) + if (f->index >=3D rga->hw->num_formats) return -EINVAL; =20 - fmt =3D &formats[f->index]; + fmt =3D &rga->hw->formats[f->index]; f->pixelformat =3D fmt->fourcc; =20 return 0; @@ -475,16 +325,18 @@ static int vidioc_g_fmt(struct file *file, void *priv= , struct v4l2_format *f) static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_forma= t *f) { struct v4l2_pix_format_mplane *pix_fmt =3D &f->fmt.pix_mp; + struct rockchip_rga *rga =3D video_drvdata(file); + const struct rga_hw *hw =3D rga->hw; struct rga_fmt *fmt; =20 - fmt =3D rga_fmt_find(pix_fmt->pixelformat); + fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); if (!fmt) - fmt =3D &formats[0]; + fmt =3D &hw->formats[0]; =20 pix_fmt->width =3D clamp(pix_fmt->width, - (u32)MIN_WIDTH, (u32)MAX_WIDTH); + hw->min_width, hw->max_width); pix_fmt->height =3D clamp(pix_fmt->height, - (u32)MIN_HEIGHT, (u32)MAX_HEIGHT); + hw->min_height, hw->max_height); =20 v4l2_fill_pixfmt_mp(pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt->height= ); pix_fmt->field =3D V4L2_FIELD_NONE; @@ -519,7 +371,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) frm->size =3D 0; for (i =3D 0; i < pix_fmt->num_planes; i++) frm->size +=3D pix_fmt->plane_fmt[i].sizeimage; - frm->fmt =3D rga_fmt_find(pix_fmt->pixelformat); + frm->fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; =20 /* Reset crop settings */ @@ -639,7 +491,7 @@ static int vidioc_s_selection(struct file *file, void *= priv, =20 if (s->r.left + s->r.width > f->pix.width || s->r.top + s->r.height > f->pix.height || - s->r.width < MIN_WIDTH || s->r.height < MIN_HEIGHT) { + s->r.width < rga->hw->min_width || s->r.height < rga->hw->min_height)= { v4l2_dbg(debug, 1, &rga->v4l2_dev, "unsupported crop value.\n"); return -EINVAL; } @@ -748,6 +600,10 @@ static int rga_probe(struct platform_device *pdev) if (!rga) return -ENOMEM; =20 + rga->hw =3D of_device_get_match_data(&pdev->dev); + if (!rga->hw) + return dev_err_probe(&pdev->dev, -ENODEV, "failed to get match data\n"); + rga->dev =3D &pdev->dev; spin_lock_init(&rga->ctrl_lock); mutex_init(&rga->mutex); @@ -811,8 +667,7 @@ static int rga_probe(struct platform_device *pdev) if (ret < 0) goto rel_m2m; =20 - rga->version.major =3D (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF; - rga->version.minor =3D (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F; + rga->hw->get_version(rga); =20 v4l2_info(&rga->v4l2_dev, "HW Version: 0x%02x.%02x\n", rga->version.major, rga->version.minor); @@ -820,7 +675,7 @@ static int rga_probe(struct platform_device *pdev) pm_runtime_put(rga->dev); =20 /* Create CMD buffer */ - rga->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, RGA_CMDBUF_SIZE, + rga->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, rga->hw->cmdbuf_size, &rga->cmdbuf_phy, GFP_KERNEL, DMA_ATTR_WRITE_COMBINE); if (!rga->cmdbuf_virt) { @@ -828,9 +683,6 @@ static int rga_probe(struct platform_device *pdev) goto rel_m2m; } =20 - def_frame.stride =3D (DEFAULT_WIDTH * def_frame.fmt->depth) >> 3; - def_frame.size =3D def_frame.stride * DEFAULT_HEIGHT; - ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { v4l2_err(&rga->v4l2_dev, "Failed to register video device\n"); @@ -843,7 +695,7 @@ static int rga_probe(struct platform_device *pdev) return 0; =20 free_dma: - dma_free_attrs(rga->dev, RGA_CMDBUF_SIZE, rga->cmdbuf_virt, + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt, rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); rel_m2m: v4l2_m2m_release(rga->m2m_dev); @@ -861,7 +713,7 @@ static void rga_remove(struct platform_device *pdev) { struct rockchip_rga *rga =3D platform_get_drvdata(pdev); =20 - dma_free_attrs(rga->dev, RGA_CMDBUF_SIZE, rga->cmdbuf_virt, + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt, rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); =20 v4l2_info(&rga->v4l2_dev, "Removing\n"); @@ -897,9 +749,11 @@ static const struct dev_pm_ops rga_pm =3D { static const struct of_device_id rockchip_rga_match[] =3D { { .compatible =3D "rockchip,rk3288-rga", + .data =3D &rga2_hw, }, { .compatible =3D "rockchip,rk3399-rga", + .data =3D &rga2_hw, }, {}, }; diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 7ec1fcc03ed32..98635ddd50d7c 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -14,6 +14,9 @@ =20 #define RGA_NAME "rockchip-rga" =20 +#define DEFAULT_WIDTH 100 +#define DEFAULT_HEIGHT 100 + struct rga_fmt { u32 fourcc; int depth; @@ -69,6 +72,8 @@ static inline struct rga_ctx *file_to_rga_ctx(struct file= *filp) return container_of(file_to_v4l2_fh(filp), struct rga_ctx, fh); } =20 +struct rga_hw; + struct rockchip_rga { struct v4l2_device v4l2_dev; struct v4l2_m2m_dev *m2m_dev; @@ -88,6 +93,8 @@ struct rockchip_rga { struct rga_ctx *curr; dma_addr_t cmdbuf_phy; void *cmdbuf_virt; + + const struct rga_hw *hw; }; =20 struct rga_addr_offset { @@ -138,7 +145,19 @@ static inline void rga_mod(struct rockchip_rga *rga, u= 32 reg, u32 val, u32 mask) rga_write(rga, reg, temp); }; =20 -void rga_hw_start(struct rockchip_rga *rga, - struct rga_vb_buffer *src, struct rga_vb_buffer *dst); +struct rga_hw { + struct rga_fmt *formats; + u32 num_formats; + size_t cmdbuf_size; + u32 min_width, min_height; + u32 max_width, max_height; + + void (*start)(struct rockchip_rga *rga, + struct rga_vb_buffer *src, struct rga_vb_buffer *dst); + bool (*handle_irq)(struct rockchip_rga *rga); + void (*get_version)(struct rockchip_rga *rga); +}; + +extern const struct rga_hw rga2_hw; =20 #endif --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E941D33D6D0 for ; Wed, 3 Dec 2025 15:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777263; cv=none; b=EfAE+gaa5bn9gdeHTINlUAY0Q0Ug9t2yxClSZ/ikWr6Mty0doNo/BRGHFBtBb1h0C38EO59l4ZlFXGoW3/e+vfSHmA+009DVU5B47D0AynQ//o5S4svqTW+VUC4StxxWz6u7eU5NF8xCTXL8wXsPcXihtV2CVuX+UKATdMZDYRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777263; c=relaxed/simple; bh=L2iLaXrXDgV/SzCQxLDBonc8cVclGsWi8P33ttvy9/w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FEZpcARfSySlHdWSxazO7AF3NIVWk6SBj+uFGV9uTeaMQMXt/0CFcDti2r6loT9OXby0FPGWwVXbSvw3GgMiL6sK9i2gofN/Wp9Llb7+0kt32nrdsgjXo4FF2pWk/se7hlgho2WsrzkhDT9wkNiur1sprUlNJ1hgZqKNcMoqPaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAd-0007dW-9C; Wed, 03 Dec 2025 16:53:35 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:30 +0100 Subject: [PATCH v2 08/22] media: rockchip: rga: move cmdbuf to rga_ctx Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-8-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Move the command buffer to the rga_ctx struct in preparation to reuse an already prepared command buffer. Having a command buffer per context allows to reuse the command buffer for other frames even when multiple applications are using the RGA in at the same time. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 28 +++++++--------- drivers/media/platform/rockchip/rga/rga.c | 48 ++++++++++++++++--------= ---- drivers/media/platform/rockchip/rga/rga.h | 5 +-- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 7419784efc693..79bf911e74779 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -113,8 +113,7 @@ static struct rga_addr_offset *rga_lookup_draw_pos(stru= ct =20 static void rga_cmd_set_src_addr(struct rga_ctx *ctx, dma_addr_t dma_addr) { - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int reg; =20 reg =3D RGA_MMU_SRC_BASE - RGA_MODE_BASE_REG; @@ -126,8 +125,7 @@ static void rga_cmd_set_src_addr(struct rga_ctx *ctx, d= ma_addr_t dma_addr) =20 static void rga_cmd_set_src1_addr(struct rga_ctx *ctx, dma_addr_t dma_addr) { - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int reg; =20 reg =3D RGA_MMU_SRC1_BASE - RGA_MODE_BASE_REG; @@ -139,8 +137,7 @@ static void rga_cmd_set_src1_addr(struct rga_ctx *ctx, = dma_addr_t dma_addr) =20 static void rga_cmd_set_dst_addr(struct rga_ctx *ctx, dma_addr_t dma_addr) { - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int reg; =20 reg =3D RGA_MMU_DST_BASE - RGA_MODE_BASE_REG; @@ -153,7 +150,7 @@ static void rga_cmd_set_dst_addr(struct rga_ctx *ctx, d= ma_addr_t dma_addr) static void rga_cmd_set_trans_info(struct rga_ctx *ctx) { struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int scale_dst_w, scale_dst_h; unsigned int src_h, src_w, dst_h, dst_w; union rga_src_info src_info; @@ -313,8 +310,7 @@ static void rga_cmd_set_src_info(struct rga_ctx *ctx, struct rga_addr_offset *offset) { struct rga_corners_addr_offset src_offsets; - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int src_h, src_w, src_x, src_y; =20 src_h =3D ctx->in.crop.height; @@ -341,8 +337,7 @@ static void rga_cmd_set_dst_info(struct rga_ctx *ctx, { struct rga_addr_offset *dst_offset; struct rga_corners_addr_offset offsets; - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int dst_h, dst_w, dst_x, dst_y; unsigned int mir_mode =3D 0; unsigned int rot_mode =3D 0; @@ -388,8 +383,7 @@ static void rga_cmd_set_dst_info(struct rga_ctx *ctx, =20 static void rga_cmd_set_mode(struct rga_ctx *ctx) { - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; union rga_mode_ctrl mode; union rga_alpha_ctrl0 alpha_ctrl0; union rga_alpha_ctrl1 alpha_ctrl1; @@ -414,7 +408,7 @@ static void rga_cmd_set(struct rga_ctx *ctx, { struct rockchip_rga *rga =3D ctx->rga; =20 - memset(rga->cmdbuf_virt, 0, RGA_CMDBUF_SIZE * 4); + memset(ctx->cmdbuf_virt, 0, RGA_CMDBUF_SIZE * 4); =20 rga_cmd_set_src_addr(ctx, src->dma_desc_pa); /* @@ -430,11 +424,11 @@ static void rga_cmd_set(struct rga_ctx *ctx, rga_cmd_set_dst_info(ctx, &dst->offset); rga_cmd_set_trans_info(ctx); =20 - rga_write(rga, RGA_CMD_BASE, rga->cmdbuf_phy); + rga_write(rga, RGA_CMD_BASE, ctx->cmdbuf_phy); =20 /* sync CMD buf for RGA */ - dma_sync_single_for_device(rga->dev, rga->cmdbuf_phy, - PAGE_SIZE, DMA_BIDIRECTIONAL); + dma_sync_single_for_device(rga->dev, ctx->cmdbuf_phy, + PAGE_SIZE, DMA_BIDIRECTIONAL); } =20 static void rga_hw_start(struct rockchip_rga *rga, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index d8b14c2d9f6a4..74d94c7fe31ff 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -219,6 +219,16 @@ static int rga_open(struct file *file) ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; + + /* Create CMD buffer */ + ctx->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, rga->hw->cmdbuf_size, + &ctx->cmdbuf_phy, GFP_KERNEL, + DMA_ATTR_WRITE_COMBINE); + if (!ctx->cmdbuf_virt) { + ret =3D -ENOMEM; + goto rel_ctx; + } + ctx->rga =3D rga; /* Set default formats */ ctx->in =3D def_frame; @@ -230,15 +240,13 @@ static int rga_open(struct file *file) ctx->out.fmt->fourcc, def_width, def_height); =20 if (mutex_lock_interruptible(&rga->mutex)) { - kfree(ctx); - return -ERESTARTSYS; + ret =3D -ERESTARTSYS; + goto rel_cmdbuf; } ctx->fh.m2m_ctx =3D v4l2_m2m_ctx_init(rga->m2m_dev, ctx, &queue_init); if (IS_ERR(ctx->fh.m2m_ctx)) { ret =3D PTR_ERR(ctx->fh.m2m_ctx); - mutex_unlock(&rga->mutex); - kfree(ctx); - return ret; + goto unlock_mutex; } v4l2_fh_init(&ctx->fh, video_devdata(file)); v4l2_fh_add(&ctx->fh, file); @@ -252,6 +260,15 @@ static int rga_open(struct file *file) mutex_unlock(&rga->mutex); =20 return 0; + +unlock_mutex: + mutex_unlock(&rga->mutex); +rel_cmdbuf: + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, ctx->cmdbuf_virt, + ctx->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); +rel_ctx: + kfree(ctx); + return ret; } =20 static int rga_release(struct file *file) @@ -266,6 +283,10 @@ static int rga_release(struct file *file) v4l2_ctrl_handler_free(&ctx->ctrl_handler); v4l2_fh_del(&ctx->fh, file); v4l2_fh_exit(&ctx->fh); + + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, ctx->cmdbuf_virt, + ctx->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); + kfree(ctx); =20 mutex_unlock(&rga->mutex); @@ -674,19 +695,10 @@ static int rga_probe(struct platform_device *pdev) =20 pm_runtime_put(rga->dev); =20 - /* Create CMD buffer */ - rga->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, rga->hw->cmdbuf_size, - &rga->cmdbuf_phy, GFP_KERNEL, - DMA_ATTR_WRITE_COMBINE); - if (!rga->cmdbuf_virt) { - ret =3D -ENOMEM; - goto rel_m2m; - } - ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { v4l2_err(&rga->v4l2_dev, "Failed to register video device\n"); - goto free_dma; + goto rel_m2m; } =20 v4l2_info(&rga->v4l2_dev, "Registered %s as /dev/%s\n", @@ -694,9 +706,6 @@ static int rga_probe(struct platform_device *pdev) =20 return 0; =20 -free_dma: - dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt, - rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); rel_m2m: v4l2_m2m_release(rga->m2m_dev); rel_vdev: @@ -713,9 +722,6 @@ static void rga_remove(struct platform_device *pdev) { struct rockchip_rga *rga =3D platform_get_drvdata(pdev); =20 - dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt, - rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); - v4l2_info(&rga->v4l2_dev, "Removing\n"); =20 v4l2_m2m_release(rga->m2m_dev); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 98635ddd50d7c..f8c932fdec21a 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -56,6 +56,9 @@ struct rga_ctx { struct rga_frame out; struct v4l2_ctrl_handler ctrl_handler; =20 + void *cmdbuf_virt; + dma_addr_t cmdbuf_phy; + int osequence; int csequence; =20 @@ -91,8 +94,6 @@ struct rockchip_rga { spinlock_t ctrl_lock; =20 struct rga_ctx *curr; - dma_addr_t cmdbuf_phy; - void *cmdbuf_virt; =20 const struct rga_hw *hw; }; --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19472338934 for ; Wed, 3 Dec 2025 15:54:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777248; cv=none; b=qWQ+WVT4MTXa9qn6hq/Rd84s+9zh1nMPXmdt93WHliLhy5Kvq2RO1op+tAwGxbyCXbdUD3X+yHME/PeW4oiNjXtvTZyawMFHVybBZD/2l51G32b1lgt3HmWKwkq0FBK/U/Z2xnk5B2BE9xohdBO2e+7coQK2q0H7svnONj4xJuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777248; c=relaxed/simple; bh=B0/KFgd5fKwQ5qWLSoIA/yamG6f4fKjqnvtRf6hq2P8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iHXW99aYs50Pv0gzqq+nSbIFrFz5jy/WcMA1Uy2xPwUb9YZVu03eulFqRFMAcxRkFQsG3dv80XD+q+y0I8AUwyORYC5wz3xb1mahufXEsc+6oleXsOPMr+GejkWF/wD2Xp3nmvS6pQ6aiA/u+SHms2f2kruWvTJ8AsTzF06ghdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAd-0007dW-Db; Wed, 03 Dec 2025 16:53:35 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:31 +0100 Subject: [PATCH v2 09/22] media: rockchip: rga: align stride to 4 bytes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-9-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add an alignment setting to rga_hw to set the desired stride alignment. As the RGA2 register for the stride counts in word units, the code already divides the bytesperline value by 4 when writing it into the register. Therefore fix the alignment to a multiple of 4 to avoid potential off by one errors due from the division. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 11 ++++++----- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 79bf911e74779..56a2558539bfb 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -620,6 +620,7 @@ const struct rga_hw rga2_hw =3D { .max_width =3D MAX_WIDTH, .min_height =3D MIN_HEIGHT, .max_height =3D MAX_HEIGHT, + .stride_alignment =3D 4, =20 .start =3D rga_hw_start, .handle_irq =3D rga_handle_irq, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 74d94c7fe31ff..592c977a07cf3 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -234,10 +234,10 @@ static int rga_open(struct file *file) ctx->in =3D def_frame; ctx->out =3D def_frame; =20 - v4l2_fill_pixfmt_mp(&ctx->in.pix, - ctx->in.fmt->fourcc, def_width, def_height); - v4l2_fill_pixfmt_mp(&ctx->out.pix, - ctx->out.fmt->fourcc, def_width, def_height); + v4l2_fill_pixfmt_mp_aligned(&ctx->in.pix, ctx->in.fmt->fourcc, + def_width, def_height, rga->hw->stride_alignment); + v4l2_fill_pixfmt_mp_aligned(&ctx->out.pix, ctx->out.fmt->fourcc, + def_width, def_height, rga->hw->stride_alignment); =20 if (mutex_lock_interruptible(&rga->mutex)) { ret =3D -ERESTARTSYS; @@ -359,7 +359,8 @@ static int vidioc_try_fmt(struct file *file, void *priv= , struct v4l2_format *f) pix_fmt->height =3D clamp(pix_fmt->height, hw->min_height, hw->max_height); =20 - v4l2_fill_pixfmt_mp(pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt->height= ); + v4l2_fill_pixfmt_mp_aligned(pix_fmt, pix_fmt->pixelformat, + pix_fmt->width, pix_fmt->height, hw->stride_alignment); pix_fmt->field =3D V4L2_FIELD_NONE; =20 return 0; diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index f8c932fdec21a..0aef348dddb95 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -152,6 +152,7 @@ struct rga_hw { size_t cmdbuf_size; u32 min_width, min_height; u32 max_width, max_height; + u8 stride_alignment; =20 void (*start)(struct rockchip_rga *rga, struct rga_vb_buffer *src, struct rga_vb_buffer *dst); --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4215C33CEB2 for ; Wed, 3 Dec 2025 15:54:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777262; cv=none; b=OfDx7F2Im4UrXXZLREo1b9A2AqTzrBAJG+2NRHpvpMUZCH2v3W373ez7zcHkAwYVvgcJACU6qiBpXnQhqG1kzoIPmFp9mgWNCScnL8erHfwomLDoT/QyZvcNBrc/o0OYpeDf3S6M3GOH+lC6hFCjSQDSTTbikiOvRzamBhO5O/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777262; c=relaxed/simple; bh=qGXiLoOdYCTswwIRAfav7TuJ1ncuYLuXShD62j9dHa4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B3BUhK0FfkQK3z0i5YAp2sgop8ABSBQr+YffMJW1nOcSYYXxFvqae2oZ7fWIZDQBhDgzvXl/8yFBnUQS3PiZdfB9IjFrkEUI7l6nStjynMN8W2MQRbomxaMZNKxRnr0WkQoQiUs5AsBKL1iQxxnR7TNF/fVMkCfVfJrmL5giCF0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAd-0007dW-Gg; Wed, 03 Dec 2025 16:53:35 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:32 +0100 Subject: [PATCH v2 10/22] media: rockchip: rga: prepare cmdbuf on streamon Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-10-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Prepare the command buffer on streamon to reuse it's contents instead of completely writing it for every frame. Due to the stream settings being fixed after a streamon we only need to replace the source and destination addresses for each frame. This reduces the amount of CPU and memory operations done in each frame. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 13 +++++++++---- drivers/media/platform/rockchip/rga/rga.c | 13 ++++++++++++- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 56a2558539bfb..8cdfe089fd636 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -408,8 +408,6 @@ static void rga_cmd_set(struct rga_ctx *ctx, { struct rockchip_rga *rga =3D ctx->rga; =20 - memset(ctx->cmdbuf_virt, 0, RGA_CMDBUF_SIZE * 4); - rga_cmd_set_src_addr(ctx, src->dma_desc_pa); /* * Due to hardware bug, @@ -418,11 +416,9 @@ static void rga_cmd_set(struct rga_ctx *ctx, rga_cmd_set_src1_addr(ctx, dst->dma_desc_pa); =20 rga_cmd_set_dst_addr(ctx, dst->dma_desc_pa); - rga_cmd_set_mode(ctx); =20 rga_cmd_set_src_info(ctx, &src->offset); rga_cmd_set_dst_info(ctx, &dst->offset); - rga_cmd_set_trans_info(ctx); =20 rga_write(rga, RGA_CMD_BASE, ctx->cmdbuf_phy); =20 @@ -431,6 +427,14 @@ static void rga_cmd_set(struct rga_ctx *ctx, PAGE_SIZE, DMA_BIDIRECTIONAL); } =20 +static void rga_hw_setup_cmdbuf(struct rga_ctx *ctx) +{ + memset(ctx->cmdbuf_virt, 0, RGA_CMDBUF_SIZE * 4); + + rga_cmd_set_mode(ctx); + rga_cmd_set_trans_info(ctx); +} + static void rga_hw_start(struct rockchip_rga *rga, struct rga_vb_buffer *src, struct rga_vb_buffer *dst) { @@ -622,6 +626,7 @@ const struct rga_hw rga2_hw =3D { .max_height =3D MAX_HEIGHT, .stride_alignment =3D 4, =20 + .setup_cmdbuf =3D rga_hw_setup_cmdbuf, .start =3D rga_hw_start, .handle_irq =3D rga_handle_irq, .get_version =3D rga_get_version, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 592c977a07cf3..f02ae02de26ca 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -523,6 +523,17 @@ static int vidioc_s_selection(struct file *file, void = *priv, return ret; } =20 +static int vidioc_streamon(struct file *file, void *priv, + enum v4l2_buf_type type) +{ + struct rga_ctx *ctx =3D file_to_rga_ctx(file); + const struct rga_hw *hw =3D ctx->rga->hw; + + hw->setup_cmdbuf(ctx); + + return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type); +} + static const struct v4l2_ioctl_ops rga_ioctl_ops =3D { .vidioc_querycap =3D vidioc_querycap, =20 @@ -547,7 +558,7 @@ static const struct v4l2_ioctl_ops rga_ioctl_ops =3D { .vidioc_subscribe_event =3D v4l2_ctrl_subscribe_event, .vidioc_unsubscribe_event =3D v4l2_event_unsubscribe, =20 - .vidioc_streamon =3D v4l2_m2m_ioctl_streamon, + .vidioc_streamon =3D vidioc_streamon, .vidioc_streamoff =3D v4l2_m2m_ioctl_streamoff, =20 .vidioc_g_selection =3D vidioc_g_selection, diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 0aef348dddb95..93162b118d069 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -154,6 +154,7 @@ struct rga_hw { u32 max_width, max_height; u8 stride_alignment; =20 + void (*setup_cmdbuf)(struct rga_ctx *ctx); void (*start)(struct rockchip_rga *rga, struct rga_vb_buffer *src, struct rga_vb_buffer *dst); bool (*handle_irq)(struct rockchip_rga *rga); --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64590339B30 for ; Wed, 3 Dec 2025 15:54:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777262; cv=none; b=Axo4+KscAL7woNS2hfwr7qoNX4dRn+nYGbtubmQOWtVnCkqyB5VwOW4VR20MEAbfHPLm3nshslKQJ1Tsp4qCfWFGN0XmZEaIcN+Bykjvaq0FOOUZN/+Ckpry/cJoaSTl2lNfKRI54GMbR8i4MeFvbi8TL+XxH+GGgEikbj7N7vQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777262; c=relaxed/simple; bh=9HzTHn5gf13iYqMGQmwCqPcqOCTeW1bMs7Bc/KZhHQs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O1psS/L/iGfmdcm+wPv7fnSjannvsIV/yZyUk8GKZ5zbYoq7+d65MVu6ltuLfzLjWeTRcJQfD63GfOhQ+0Re73IIO7XJucMAQr+PTzs7gNcSh1ARFTrJqdDSQl4WmdFuuAjXS+AbPcgngnKWfsZVhN8ywT2AzOQ4v5d2PaBUeSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAd-0007dW-K6; Wed, 03 Dec 2025 16:53:35 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:33 +0100 Subject: [PATCH v2 11/22] media: rockchip: rga: check scaling factor Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-11-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Check the scaling factor to avoid potential problems. This is relevant for the upcoming RGA3 support, as it can hang when the scaling factor is exceeded. There are two relevant scenarios that have to be considered to protect against invalid scaling values: When the output or capture is already streaming, setting the format on the other side should consider the max scaling factor and clamp it accordingly. This is only done in the streaming case, as it otherwise may unintentionally clamp the value when the application sets the first format (due to a default format on the other side). When the format is set on both sides first, then the format won't be corrected by above means. Therefore the second streamon call has to check the scaling factor and fail otherwise. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga-hw.h | 1 + drivers/media/platform/rockchip/rga/rga.c | 60 ++++++++++++++++++++++++= +--- drivers/media/platform/rockchip/rga/rga.h | 1 + 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 8cdfe089fd636..2ed4f22a999d5 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -624,6 +624,7 @@ const struct rga_hw rga2_hw =3D { .max_width =3D MAX_WIDTH, .min_height =3D MIN_HEIGHT, .max_height =3D MAX_HEIGHT, + .max_scaling_factor =3D MAX_SCALING_FACTOR, .stride_alignment =3D 4, =20 .setup_cmdbuf =3D rga_hw_setup_cmdbuf, diff --git a/drivers/media/platform/rockchip/rga/rga-hw.h b/drivers/media/p= latform/rockchip/rga/rga-hw.h index f4752aa823051..fffcab0131225 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.h +++ b/drivers/media/platform/rockchip/rga/rga-hw.h @@ -14,6 +14,7 @@ =20 #define MIN_WIDTH 34 #define MIN_HEIGHT 34 +#define MAX_SCALING_FACTOR 16 =20 #define RGA_TIMEOUT 500 =20 diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index f02ae02de26ca..46dc94db6f85e 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -346,18 +346,47 @@ static int vidioc_g_fmt(struct file *file, void *priv= , struct v4l2_format *f) static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_forma= t *f) { struct v4l2_pix_format_mplane *pix_fmt =3D &f->fmt.pix_mp; - struct rockchip_rga *rga =3D video_drvdata(file); + struct rga_ctx *ctx =3D file_to_rga_ctx(file); + struct rockchip_rga *rga =3D ctx->rga; const struct rga_hw *hw =3D rga->hw; struct rga_fmt *fmt; + u32 min_width =3D hw->min_width; + u32 max_width =3D hw->max_width; + u32 min_height =3D hw->min_height; + u32 max_height =3D hw->max_height; =20 fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); if (!fmt) fmt =3D &hw->formats[0]; =20 - pix_fmt->width =3D clamp(pix_fmt->width, - hw->min_width, hw->max_width); - pix_fmt->height =3D clamp(pix_fmt->height, - hw->min_height, hw->max_height); + if (V4L2_TYPE_IS_OUTPUT(f->type) && + v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx)->streaming) { + min_width =3D + MAX(min_width, DIV_ROUND_UP(ctx->out.pix.width, + hw->max_scaling_factor)); + max_width =3D MIN(max_width, + ctx->out.pix.width * hw->max_scaling_factor); + min_height =3D + MAX(min_height, DIV_ROUND_UP(ctx->out.pix.height, + hw->max_scaling_factor)); + max_height =3D MIN(max_height, + ctx->out.pix.height * hw->max_scaling_factor); + } else if (V4L2_TYPE_IS_CAPTURE(f->type) && + v4l2_m2m_get_src_vq(ctx->fh.m2m_ctx)->streaming) { + min_width =3D + MAX(min_width, DIV_ROUND_UP(ctx->in.pix.width, + hw->max_scaling_factor)); + max_width =3D MIN(max_width, + ctx->in.pix.width * hw->max_scaling_factor); + min_height =3D + MAX(min_height, DIV_ROUND_UP(ctx->in.pix.height, + hw->max_scaling_factor)); + max_height =3D MIN(max_height, + ctx->in.pix.height * hw->max_scaling_factor); + } + + pix_fmt->width =3D clamp(pix_fmt->width, min_width, max_width); + pix_fmt->height =3D clamp(pix_fmt->height, min_height, max_height); =20 v4l2_fill_pixfmt_mp_aligned(pix_fmt, pix_fmt->pixelformat, pix_fmt->width, pix_fmt->height, hw->stride_alignment); @@ -523,12 +552,33 @@ static int vidioc_s_selection(struct file *file, void= *priv, return ret; } =20 +static bool check_scaling(const struct rga_hw *hw, u32 src_size, u32 dst_s= ize) +{ + if (src_size < dst_size) + return src_size * hw->max_scaling_factor >=3D dst_size; + else + return dst_size * hw->max_scaling_factor >=3D src_size; +} + static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type type) { struct rga_ctx *ctx =3D file_to_rga_ctx(file); const struct rga_hw *hw =3D ctx->rga->hw; =20 + if ((V4L2_TYPE_IS_OUTPUT(type) && + v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx)->streaming) || + (V4L2_TYPE_IS_CAPTURE(type) && + v4l2_m2m_get_src_vq(ctx->fh.m2m_ctx)->streaming)) { + /* + * As the other side is already streaming, + * check that the max scaling factor isn't exceeded. + */ + if (!check_scaling(hw, ctx->in.pix.width, ctx->out.pix.width) || + !check_scaling(hw, ctx->in.pix.height, ctx->out.pix.height)) + return -EINVAL; + } + hw->setup_cmdbuf(ctx); =20 return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 93162b118d069..d02d5730b4e3b 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -152,6 +152,7 @@ struct rga_hw { size_t cmdbuf_size; u32 min_width, min_height; u32 max_width, max_height; + u8 max_scaling_factor; u8 stride_alignment; =20 void (*setup_cmdbuf)(struct rga_ctx *ctx); --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 205C633AD96 for ; Wed, 3 Dec 2025 15:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777249; cv=none; b=b6ivGhhEWOPMVUy5CmkEzi9Qkix8RMBBrv0N71AjK/joxHlGmy3c6zLVlQKeD3czoDQSgizGdgCJZlAC44T77Be8ERl0QyuAAaaWMJuTptoXDSfYx/IRHEYrbxN8AvWwRfvbVC9pRrs7apCPUHCzIMa3xcsFYxMCmvIkNvxTHmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777249; c=relaxed/simple; bh=Uwaz1yUQjk2gQFCenOj5IINQfj8I4w40DEBFQwcXrmY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V2+88OgwgVW/ORK4LTs9ZwfxMFo3vy3JVEc283rbz33BVx2RtXq+Hvmfehhss0Hl7J4XZRvXqnwjdJTw4UFICc7d8QwYhJg0kyVfEdj/VITXkPvf/sRZadktnhahYD2TOwfpCIRGgxQ9KNC+U4qN1Y8P1q2GjO/6fFq9tDo7nmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAd-0007dW-Nt; Wed, 03 Dec 2025 16:53:35 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:34 +0100 Subject: [PATCH v2 12/22] media: rockchip: rga: use card type to specify rga type Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-12-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org In preparation of the RGA3 support add a filed to the rga_hw struct to specify the desired card type value. This allows the user to differentiate the RGA2 and RGA3 video device nodes. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 4 +++- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 2ed4f22a999d5..8953960d33bc5 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -617,6 +617,7 @@ static struct rga_fmt formats[] =3D { }; =20 const struct rga_hw rga2_hw =3D { + .card_type =3D "rga2", .formats =3D formats, .num_formats =3D ARRAY_SIZE(formats), .cmdbuf_size =3D RGA_CMDBUF_SIZE, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 46dc94db6f85e..c9719c7bcfc1c 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -306,8 +306,10 @@ static const struct v4l2_file_operations rga_fops =3D { static int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap) { + struct rockchip_rga *rga =3D video_drvdata(file); + strscpy(cap->driver, RGA_NAME, sizeof(cap->driver)); - strscpy(cap->card, "rockchip-rga", sizeof(cap->card)); + strscpy(cap->card, rga->hw->card_type, sizeof(cap->card)); strscpy(cap->bus_info, "platform:rga", sizeof(cap->bus_info)); =20 return 0; diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index d02d5730b4e3b..ee50f7f3ed601 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -147,6 +147,7 @@ static inline void rga_mod(struct rockchip_rga *rga, u3= 2 reg, u32 val, u32 mask) }; =20 struct rga_hw { + const char *card_type; struct rga_fmt *formats; u32 num_formats; size_t cmdbuf_size; --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1B053396FA for ; Wed, 3 Dec 2025 15:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777260; cv=none; b=ZNC6KxmF+BXvXzHxKC5qVI2Uj2aEgKEoL8w1yc7nDIMNyE7VygxNeeLhq7Ksw5Qt28bycOzzVZVt8Ze9+2MUVENxNipzRnD2/KEOjgvZdWvdBZP3a3cBBxnpx7U/tiAlrVxC4nZZClQhhLFJExuUbRVcwmHxb8omG6RQ5IinQ/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777260; c=relaxed/simple; bh=nKPE+BniHikaOszlaAzaMCcbSRBJixVgm76ov0nKXKY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NCOjLoEZgvFFSmfMiAEB4m+l7C7VkqAj6mKPegiV0RGuUA6O0NabV8euiCrxTmb21PI+tz7Kd1FOc/18XopA4wxl8gLkVBqUjaI3OwZ+wGBOZmn2aLgl30WJSVYzBQlzMTgNbbVFTuinNThdyvHXgdTBWJGu6rtHnpJUooknQII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAd-0007dW-Se; Wed, 03 Dec 2025 16:53:35 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:35 +0100 Subject: [PATCH v2 13/22] media: rockchip: rga: change offset to dma_addresses Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-13-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Change the offset to dma_addresses, as the current naming is misleading. The offset naming comes from the fact that it references the offset in the mapped iommu address space. But from the hardware point of view this is an address, as also pointed out by the register naming (e.g. RGA_DST_Y_RGB_BASE_ADDR). Therefore also change the type to dma_addr_t, as with an external iommu driver this would also be the correct type. This change is a preparation for the RGA3 support, which uses an external iommu and therefore just gets an dma_addr_t for each buffer. The field renaming allows to reuse the existing fields of rga_vb_buffer to store these values. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 12 +-- drivers/media/platform/rockchip/rga/rga-hw.c | 105 +++++++++++++---------= ---- drivers/media/platform/rockchip/rga/rga.h | 12 +-- 3 files changed, 64 insertions(+), 65 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index 0c59a4d330888..8845e1f894f29 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -118,7 +118,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb) size_t curr_desc =3D 0; int i; const struct v4l2_format_info *info; - unsigned int offsets[VIDEO_MAX_PLANES]; + unsigned int dma_addrs[VIDEO_MAX_PLANES]; =20 if (IS_ERR(f)) return PTR_ERR(f); @@ -142,18 +142,18 @@ static int rga_buf_prepare(struct vb2_buffer *vb) "Failed to map video buffer to RGA\n"); return n_desc; } - offsets[i] =3D curr_desc << PAGE_SHIFT; + dma_addrs[i] =3D curr_desc << PAGE_SHIFT; curr_desc +=3D n_desc; } =20 /* Fill the remaining planes */ info =3D v4l2_format_info(f->fmt->fourcc); for (i =3D info->mem_planes; i < info->comp_planes; i++) - offsets[i] =3D get_plane_offset(f, info, i); + dma_addrs[i] =3D dma_addrs[0] + get_plane_offset(f, info, i); =20 - rbuf->offset.y_off =3D offsets[0]; - rbuf->offset.u_off =3D offsets[1]; - rbuf->offset.v_off =3D offsets[2]; + rbuf->dma_addrs.y_addr =3D dma_addrs[0]; + rbuf->dma_addrs.u_addr =3D dma_addrs[1]; + rbuf->dma_addrs.v_addr =3D dma_addrs[2]; =20 return 0; } diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 8953960d33bc5..fe6f518aedd4e 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -16,11 +16,11 @@ enum e_rga_start_pos { RB =3D 3, }; =20 -struct rga_corners_addr_offset { - struct rga_addr_offset left_top; - struct rga_addr_offset right_top; - struct rga_addr_offset left_bottom; - struct rga_addr_offset right_bottom; +struct rga_corners_addrs { + struct rga_addrs left_top; + struct rga_addrs right_top; + struct rga_addrs left_bottom; + struct rga_addrs right_bottom; }; =20 static unsigned int rga_get_scaling(unsigned int src, unsigned int dst) @@ -36,48 +36,47 @@ static unsigned int rga_get_scaling(unsigned int src, u= nsigned int dst) return (src > dst) ? ((dst << 16) / src) : ((src << 16) / dst); } =20 -static struct rga_corners_addr_offset -rga_get_addr_offset(struct rga_frame *frm, struct rga_addr_offset *offset, - unsigned int x, unsigned int y, unsigned int w, unsigned int h) +static struct rga_corners_addrs +rga_get_corner_addrs(struct rga_frame *frm, struct rga_addrs *addrs, + unsigned int x, unsigned int y, unsigned int w, unsigned int h) { - struct rga_corners_addr_offset offsets; - struct rga_addr_offset *lt, *lb, *rt, *rb; + struct rga_corners_addrs corner_addrs; + struct rga_addrs *lt, *lb, *rt, *rb; unsigned int x_div =3D 0, y_div =3D 0, uv_stride =3D 0, pixel_width =3D 0; =20 - lt =3D &offsets.left_top; - lb =3D &offsets.left_bottom; - rt =3D &offsets.right_top; - rb =3D &offsets.right_bottom; + lt =3D &corner_addrs.left_top; + lb =3D &corner_addrs.left_bottom; + rt =3D &corner_addrs.right_top; + rb =3D &corner_addrs.right_bottom; =20 x_div =3D frm->fmt->x_div; y_div =3D frm->fmt->y_div; uv_stride =3D frm->stride / x_div; pixel_width =3D frm->stride / frm->pix.width; =20 - lt->y_off =3D offset->y_off + y * frm->stride + x * pixel_width; - lt->u_off =3D offset->u_off + (y / y_div) * uv_stride + x / x_div; - lt->v_off =3D offset->v_off + (y / y_div) * uv_stride + x / x_div; + lt->y_addr =3D addrs->y_addr + y * frm->stride + x * pixel_width; + lt->u_addr =3D addrs->u_addr + (y / y_div) * uv_stride + x / x_div; + lt->v_addr =3D addrs->v_addr + (y / y_div) * uv_stride + x / x_div; =20 - lb->y_off =3D lt->y_off + (h - 1) * frm->stride; - lb->u_off =3D lt->u_off + (h / y_div - 1) * uv_stride; - lb->v_off =3D lt->v_off + (h / y_div - 1) * uv_stride; + lb->y_addr =3D lt->y_addr + (h - 1) * frm->stride; + lb->u_addr =3D lt->u_addr + (h / y_div - 1) * uv_stride; + lb->v_addr =3D lt->v_addr + (h / y_div - 1) * uv_stride; =20 - rt->y_off =3D lt->y_off + (w - 1) * pixel_width; - rt->u_off =3D lt->u_off + w / x_div - 1; - rt->v_off =3D lt->v_off + w / x_div - 1; + rt->y_addr =3D lt->y_addr + (w - 1) * pixel_width; + rt->u_addr =3D lt->u_addr + w / x_div - 1; + rt->v_addr =3D lt->v_addr + w / x_div - 1; =20 - rb->y_off =3D lb->y_off + (w - 1) * pixel_width; - rb->u_off =3D lb->u_off + w / x_div - 1; - rb->v_off =3D lb->v_off + w / x_div - 1; + rb->y_addr =3D lb->y_addr + (w - 1) * pixel_width; + rb->u_addr =3D lb->u_addr + w / x_div - 1; + rb->v_addr =3D lb->v_addr + w / x_div - 1; =20 - return offsets; + return corner_addrs; } =20 -static struct rga_addr_offset *rga_lookup_draw_pos(struct - rga_corners_addr_offset - * offsets, u32 rotate_mode, - u32 mirr_mode) +static struct rga_addrs *rga_lookup_draw_pos(struct rga_corners_addrs *cor= ner_addrs, + u32 rotate_mode, + u32 mirr_mode) { static enum e_rga_start_pos rot_mir_point_matrix[4][4] =3D { { @@ -94,18 +93,18 @@ static struct rga_addr_offset *rga_lookup_draw_pos(stru= ct }, }; =20 - if (!offsets) + if (!corner_addrs) return NULL; =20 switch (rot_mir_point_matrix[rotate_mode][mirr_mode]) { case LT: - return &offsets->left_top; + return &corner_addrs->left_top; case LB: - return &offsets->left_bottom; + return &corner_addrs->left_bottom; case RT: - return &offsets->right_top; + return &corner_addrs->right_top; case RB: - return &offsets->right_bottom; + return &corner_addrs->right_bottom; } =20 return NULL; @@ -307,9 +306,9 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) } =20 static void rga_cmd_set_src_info(struct rga_ctx *ctx, - struct rga_addr_offset *offset) + struct rga_addrs *addrs) { - struct rga_corners_addr_offset src_offsets; + struct rga_corners_addrs src_corner_addrs; u32 *dest =3D ctx->cmdbuf_virt; unsigned int src_h, src_w, src_x, src_y; =20 @@ -321,22 +320,22 @@ static void rga_cmd_set_src_info(struct rga_ctx *ctx, /* * Calculate the source framebuffer base address with offset pixel. */ - src_offsets =3D rga_get_addr_offset(&ctx->in, offset, - src_x, src_y, src_w, src_h); + src_corner_addrs =3D rga_get_corner_addrs(&ctx->in, addrs, + src_x, src_y, src_w, src_h); =20 dest[(RGA_SRC_Y_RGB_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - src_offsets.left_top.y_off; + src_corner_addrs.left_top.y_addr; dest[(RGA_SRC_CB_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - src_offsets.left_top.u_off; + src_corner_addrs.left_top.u_addr; dest[(RGA_SRC_CR_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - src_offsets.left_top.v_off; + src_corner_addrs.left_top.v_addr; } =20 static void rga_cmd_set_dst_info(struct rga_ctx *ctx, - struct rga_addr_offset *offset) + struct rga_addrs *addrs) { - struct rga_addr_offset *dst_offset; - struct rga_corners_addr_offset offsets; + struct rga_addrs *dst_addrs; + struct rga_corners_addrs corner_addrs; u32 *dest =3D ctx->cmdbuf_virt; unsigned int dst_h, dst_w, dst_x, dst_y; unsigned int mir_mode =3D 0; @@ -370,15 +369,15 @@ static void rga_cmd_set_dst_info(struct rga_ctx *ctx, /* * Configure the dest framebuffer base address with pixel offset. */ - offsets =3D rga_get_addr_offset(&ctx->out, offset, dst_x, dst_y, dst_w, d= st_h); - dst_offset =3D rga_lookup_draw_pos(&offsets, rot_mode, mir_mode); + corner_addrs =3D rga_get_corner_addrs(&ctx->out, addrs, dst_x, dst_y, dst= _w, dst_h); + dst_addrs =3D rga_lookup_draw_pos(&corner_addrs, rot_mode, mir_mode); =20 dest[(RGA_DST_Y_RGB_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - dst_offset->y_off; + dst_addrs->y_addr; dest[(RGA_DST_CB_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - dst_offset->u_off; + dst_addrs->u_addr; dest[(RGA_DST_CR_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - dst_offset->v_off; + dst_addrs->v_addr; } =20 static void rga_cmd_set_mode(struct rga_ctx *ctx) @@ -417,8 +416,8 @@ static void rga_cmd_set(struct rga_ctx *ctx, =20 rga_cmd_set_dst_addr(ctx, dst->dma_desc_pa); =20 - rga_cmd_set_src_info(ctx, &src->offset); - rga_cmd_set_dst_info(ctx, &dst->offset); + rga_cmd_set_src_info(ctx, &src->dma_addrs); + rga_cmd_set_dst_info(ctx, &dst->dma_addrs); =20 rga_write(rga, RGA_CMD_BASE, ctx->cmdbuf_phy); =20 diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index ee50f7f3ed601..772f7dff9a8e5 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -98,10 +98,10 @@ struct rockchip_rga { const struct rga_hw *hw; }; =20 -struct rga_addr_offset { - unsigned int y_off; - unsigned int u_off; - unsigned int v_off; +struct rga_addrs { + dma_addr_t y_addr; + dma_addr_t u_addr; + dma_addr_t v_addr; }; =20 struct rga_vb_buffer { @@ -113,8 +113,8 @@ struct rga_vb_buffer { dma_addr_t dma_desc_pa; size_t n_desc; =20 - /* Plane offsets of this buffer into the mapping */ - struct rga_addr_offset offset; + /* Plane DMA addresses after the MMU mapping of the buffer */ + struct rga_addrs dma_addrs; }; =20 static inline struct rga_vb_buffer *vb_to_rga(struct vb2_v4l2_buffer *vb) --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65F5F33A714 for ; Wed, 3 Dec 2025 15:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777255; cv=none; b=W6BDsg/gq1yDM59XN9v/7t0pKwmRmDOhkOHyEFUORZTkxA5zaK2JCBcMp0w7uhgI8toRcKg+vgGkhkyV1e30ksi6/DQw7LIHRmy+UXc3/UoP1qJgEtqJFkTR1dT334KbkmIKa1O2yUsRXUQi2gXKqGijvk9RG8gXonZrxPyWEJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777255; c=relaxed/simple; bh=N9TshRJWWUhC0rc/gHrS3TayvokbBYKeSiDZcGbYkUk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WE2NexfgtjgfCKIMwe+BrLxPFbNjxREhpUnv62ZPcMkLLAYrOUfNIYeWklydRMUe8w8yIgi9oev5wQMyp9K/I9NuK9ztf7lkutVv6WOKe/IH9oDCEYxmSUi3PY/UdSzSp8BvT6w4iwyXBhx0OvLXYZsM22UlqaAFdlTHzeaMq4k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAe-0007dW-1P; Wed, 03 Dec 2025 16:53:36 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:36 +0100 Subject: [PATCH v2 14/22] media: rockchip: rga: support external iommus Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-14-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org In preparation for the RGA3 add support for external iommus. This is a transition step to just disable the RGA2 specific mmu table setup code. Currently a simple rga_hw struct field is used to set the internal iommu. But to handle the case of more sophisticated detection mechanisms (e.g. check for an iommu property in the device tree), it is abstracted by an inline function. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 46 ++++++++++++++++-------= ---- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 11 +++++-- drivers/media/platform/rockchip/rga/rga.h | 6 ++++ 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index 8845e1f894f29..e8d1e2e579140 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -12,6 +12,7 @@ #include #include #include +#include #include =20 #include "rga.h" @@ -79,14 +80,16 @@ static int rga_buf_init(struct vb2_buffer *vb) struct rga_frame *f =3D rga_get_frame(ctx, vb->vb2_queue->type); size_t n_desc =3D 0; =20 - n_desc =3D DIV_ROUND_UP(f->size, PAGE_SIZE); + if (rga_has_internal_iommu(rga)) { + n_desc =3D DIV_ROUND_UP(f->size, PAGE_SIZE); =20 - rbuf->n_desc =3D n_desc; - rbuf->dma_desc =3D dma_alloc_coherent(rga->dev, - rbuf->n_desc * sizeof(*rbuf->dma_desc), - &rbuf->dma_desc_pa, GFP_KERNEL); - if (!rbuf->dma_desc) - return -ENOMEM; + rbuf->n_desc =3D n_desc; + rbuf->dma_desc =3D dma_alloc_coherent(rga->dev, + rbuf->n_desc * sizeof(*rbuf->dma_desc), + &rbuf->dma_desc_pa, GFP_KERNEL); + if (!rbuf->dma_desc) + return -ENOMEM; + } =20 return 0; } @@ -133,17 +136,21 @@ static int rga_buf_prepare(struct vb2_buffer *vb) for (i =3D 0; i < vb->num_planes; i++) { vb2_set_plane_payload(vb, i, f->pix.plane_fmt[i].sizeimage); =20 - /* Create local MMU table for RGA */ - n_desc =3D fill_descriptors(&rbuf->dma_desc[curr_desc], - rbuf->n_desc - curr_desc, - vb2_dma_sg_plane_desc(vb, i)); - if (n_desc < 0) { - v4l2_err(&ctx->rga->v4l2_dev, - "Failed to map video buffer to RGA\n"); - return n_desc; + if (rga_has_internal_iommu(ctx->rga)) { + /* Create local MMU table for RGA */ + n_desc =3D fill_descriptors(&rbuf->dma_desc[curr_desc], + rbuf->n_desc - curr_desc, + vb2_dma_sg_plane_desc(vb, i)); + if (n_desc < 0) { + v4l2_err(&ctx->rga->v4l2_dev, + "Failed to map video buffer to RGA\n"); + return n_desc; + } + dma_addrs[i] =3D curr_desc << PAGE_SHIFT; + curr_desc +=3D n_desc; + } else { + dma_addrs[i] =3D vb2_dma_contig_plane_dma_addr(vb, i); } - dma_addrs[i] =3D curr_desc << PAGE_SHIFT; - curr_desc +=3D n_desc; } =20 /* Fill the remaining planes */ @@ -173,8 +180,9 @@ static void rga_buf_cleanup(struct vb2_buffer *vb) struct rga_ctx *ctx =3D vb2_get_drv_priv(vb->vb2_queue); struct rockchip_rga *rga =3D ctx->rga; =20 - dma_free_coherent(rga->dev, rbuf->n_desc * sizeof(*rbuf->dma_desc), - rbuf->dma_desc, rbuf->dma_desc_pa); + if (rga_has_internal_iommu(rga)) + dma_free_coherent(rga->dev, rbuf->n_desc * sizeof(*rbuf->dma_desc), + rbuf->dma_desc, rbuf->dma_desc_pa); } =20 static void rga_buf_return_buffers(struct vb2_queue *q, diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index fe6f518aedd4e..fb0389ae8e132 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -617,6 +617,7 @@ static struct rga_fmt formats[] =3D { =20 const struct rga_hw rga2_hw =3D { .card_type =3D "rga2", + .has_internal_iommu =3D true, .formats =3D formats, .num_formats =3D ARRAY_SIZE(formats), .cmdbuf_size =3D RGA_CMDBUF_SIZE, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index c9719c7bcfc1c..f28ec88c186fa 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -23,6 +23,7 @@ #include #include #include +#include #include =20 #include "rga.h" @@ -95,13 +96,16 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct= vb2_queue *dst_vq) src_vq->io_modes =3D VB2_MMAP | VB2_DMABUF; src_vq->drv_priv =3D ctx; src_vq->ops =3D &rga_qops; - src_vq->mem_ops =3D &vb2_dma_sg_memops; + src_vq->mem_ops =3D &vb2_dma_contig_memops; src_vq->gfp_flags =3D __GFP_DMA32; src_vq->buf_struct_size =3D sizeof(struct rga_vb_buffer); src_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; src_vq->lock =3D &ctx->rga->mutex; src_vq->dev =3D ctx->rga->v4l2_dev.dev; =20 + if (rga_has_internal_iommu(ctx->rga)) + src_vq->mem_ops =3D &vb2_dma_sg_memops; + ret =3D vb2_queue_init(src_vq); if (ret) return ret; @@ -110,13 +114,16 @@ queue_init(void *priv, struct vb2_queue *src_vq, stru= ct vb2_queue *dst_vq) dst_vq->io_modes =3D VB2_MMAP | VB2_DMABUF; dst_vq->drv_priv =3D ctx; dst_vq->ops =3D &rga_qops; - dst_vq->mem_ops =3D &vb2_dma_sg_memops; + dst_vq->mem_ops =3D &vb2_dma_contig_memops; dst_vq->gfp_flags =3D __GFP_DMA32; dst_vq->buf_struct_size =3D sizeof(struct rga_vb_buffer); dst_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; dst_vq->lock =3D &ctx->rga->mutex; dst_vq->dev =3D ctx->rga->v4l2_dev.dev; =20 + if (rga_has_internal_iommu(ctx->rga)) + dst_vq->mem_ops =3D &vb2_dma_sg_memops; + return vb2_queue_init(dst_vq); } =20 diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 772f7dff9a8e5..fc81bc5562792 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -148,6 +148,7 @@ static inline void rga_mod(struct rockchip_rga *rga, u3= 2 reg, u32 val, u32 mask) =20 struct rga_hw { const char *card_type; + bool has_internal_iommu; struct rga_fmt *formats; u32 num_formats; size_t cmdbuf_size; @@ -163,6 +164,11 @@ struct rga_hw { void (*get_version)(struct rockchip_rga *rga); }; =20 +static inline bool rga_has_internal_iommu(const struct rockchip_rga *rga) +{ + return rga->hw->has_internal_iommu; +} + extern const struct rga_hw rga2_hw; =20 #endif --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F851381C4 for ; Wed, 3 Dec 2025 15:54:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777246; cv=none; b=T0vcs4PUfZ9I58GqqeVmjrFcTvLQZdlNOVQpFIdJZchZwzJs/EMXhakoNjD6AKijGEYIP+PcmL/D3Bqpc7aWVkGq2fsMstgwj0EqP68L/ueFXZwC27a3Xlb5dL7hyAkdHRAOblyam/lmMRjUNiS+Lt3noTWbBE3vayYqYwPM4d8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777246; c=relaxed/simple; bh=m3WXOlKOqAZcD7TuLqkO3TR27/awhMrA3k+6cS9jndo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nAfBML6nY2HqT+xGxbXkmQgf7+eXPJugyuUaJvfIAHsxbvFrWTdq4i5LsCr0Y4KZ8cULp6OUEZEt2sDGzDwgTYah4cuxgNSTCjooMXsdL6opFFVRqzA5eGuRh387dQFazJ8K+z3JrJDJT91fffjn+EJIWMDYPoVkR9osF+EZDhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAe-0007dW-5W; Wed, 03 Dec 2025 16:53:36 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:37 +0100 Subject: [PATCH v2 15/22] media: rockchip: rga: share the interrupt when an external iommu is used Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-15-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= , Michael Olbrich X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org From: Michael Olbrich The RGA3 and the corresponding iommu share the interrupt. So in that case, request a shared interrupt so that the iommu driver can request it as well. Signed-off-by: Michael Olbrich Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index f28ec88c186fa..1bfc4021f4a7b 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -718,7 +718,8 @@ static int rga_probe(struct platform_device *pdev) goto err_put_clk; } =20 - ret =3D devm_request_irq(rga->dev, irq, rga_isr, 0, + ret =3D devm_request_irq(rga->dev, irq, rga_isr, + rga_has_internal_iommu(rga) ? 0 : IRQF_SHARED, dev_name(rga->dev), rga); if (ret < 0) { dev_err(rga->dev, "failed to request irq\n"); --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93F9C33BBB7 for ; Wed, 3 Dec 2025 15:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777253; cv=none; b=ljxiDaWbnx/nDzZ+oUoReWXm7PjSfQ/f17M9P4QLz9j/0XvqgJgEGftHZY/PzHpj36UshcHf5dg+kCUSo4fSq3zMEg1sr/jrua4b6pD5m/lw7fspMjAapNQw5c+WDF1wW/BKjWHU9rqKN2LvY0WtsthKVGoZQVRNzwzVZsBlVNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777253; c=relaxed/simple; bh=sXz2bXFgmzva/qisHLmnpzIhxJndvLZhTKwgqdEIUfo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GSV1RBDaLmm8/D1m3IsCQj+i7XbPiIfmnAyz7qACDqSsi1+XybSVgOhWdcMp38vyjAYc4mLmEry93i7BdVYRpdpjtN7o5DqXjbdkQEoFkK/T7tjZeoz6UcFEMWNcRtaz8WWrcI6ehR41EV1XH8VupeChTY8P4vDa8IMRhm0ObDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAe-0007dW-9P; Wed, 03 Dec 2025 16:53:36 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:38 +0100 Subject: [PATCH v2 16/22] media: rockchip: rga: remove size from rga_frame Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-16-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org The size member is only used for the mmu page table mapping. Therefore avoid storing the value and instead only calculate it in place. This also avoids the calculation entirely when an external iommu is used. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 6 +++++- drivers/media/platform/rockchip/rga/rga.c | 8 ++------ drivers/media/platform/rockchip/rga/rga.h | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index e8d1e2e579140..8de6b9c3fd615 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -79,9 +79,13 @@ static int rga_buf_init(struct vb2_buffer *vb) struct rockchip_rga *rga =3D ctx->rga; struct rga_frame *f =3D rga_get_frame(ctx, vb->vb2_queue->type); size_t n_desc =3D 0; + u32 size =3D 0; + u8 i; =20 if (rga_has_internal_iommu(rga)) { - n_desc =3D DIV_ROUND_UP(f->size, PAGE_SIZE); + for (i =3D 0; i < f->pix.num_planes; i++) + size +=3D f->pix.plane_fmt[i].sizeimage; + n_desc =3D DIV_ROUND_UP(size, PAGE_SIZE); =20 rbuf->n_desc =3D n_desc; rbuf->dma_desc =3D dma_alloc_coherent(rga->dev, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 1bfc4021f4a7b..0d7b0bcac950e 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -221,7 +221,6 @@ static int rga_open(struct file *file) }; =20 def_frame.stride =3D (def_width * def_frame.fmt->depth) >> 3; - def_frame.size =3D def_frame.stride * def_height; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) @@ -428,9 +427,6 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) frm =3D rga_get_frame(ctx, f->type); if (IS_ERR(frm)) return PTR_ERR(frm); - frm->size =3D 0; - for (i =3D 0; i < pix_fmt->num_planes; i++) - frm->size +=3D pix_fmt->plane_fmt[i].sizeimage; frm->fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; =20 @@ -443,10 +439,10 @@ static int vidioc_s_fmt(struct file *file, void *priv= , struct v4l2_format *f) frm->pix =3D *pix_fmt; =20 v4l2_dbg(debug, 1, &rga->v4l2_dev, - "[%s] fmt - %p4cc %dx%d (stride %d, sizeimage %d)\n", + "[%s] fmt - %p4cc %dx%d (stride %d)\n", V4L2_TYPE_IS_OUTPUT(f->type) ? "OUTPUT" : "CAPTURE", &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, - frm->stride, frm->size); + frm->stride); =20 for (i =3D 0; i < pix_fmt->num_planes; i++) { v4l2_dbg(debug, 1, &rga->v4l2_dev, diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index fc81bc5562792..466d568b9e614 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -37,7 +37,6 @@ struct rga_frame { =20 /* Variables that can calculated once and reused */ u32 stride; - u32 size; }; =20 struct rga_dma_desc { --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A40B33B963 for ; Wed, 3 Dec 2025 15:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777252; cv=none; b=JxFjnLa9EjHbVWU40BPenh5FARccwfwJlp8ssqfoZycprQ6v3RC9JXkWIXYpdzhzZ8jUAmxX1h6Tllq5i/HpLgGjjHMquREvAl/mwqGNNVa0wfhwf2FPNimtP2ID/YZf9rynR8urAtzriG10y1fv7LtVSmZ9Xd0yyL2uxIJ83EA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777252; c=relaxed/simple; bh=LbD9lIEf8dOkPMBYnVkP1K5bwiRqC1YICvAFOw0NcXM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rxast5nB282DQ8B88F2QUZEC6vbfgWLjNSUugGTA8hfI1/Tjx4ueoQRJjWEGufJStdezf6ihwC/5jpu4TL8f+wr80AlZjQdJeAtStTO3IVsvbyWj6PJb09d+t9AJJ9WQD1m0rqeVYPxsK9oscqMm1SZ3tl7ndPleP8EwkHiby+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAe-0007dW-DS; Wed, 03 Dec 2025 16:53:36 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:39 +0100 Subject: [PATCH v2 17/22] media: rockchip: rga: remove stride from rga_frame Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-17-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Remove the stride variable from rga_frame. Despite the comment it didn't involve any calculation and is just a copy of the plane_fmt[0].bytesperline value. Therefore avoid this struct member and use the bytesperline value directly in the places where it is required. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 20 ++++++++++++-------- drivers/media/platform/rockchip/rga/rga.c | 5 +---- drivers/media/platform/rockchip/rga/rga.h | 3 --- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index fb0389ae8e132..4dee33d8f7206 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -43,7 +43,7 @@ rga_get_corner_addrs(struct rga_frame *frm, struct rga_ad= drs *addrs, struct rga_corners_addrs corner_addrs; struct rga_addrs *lt, *lb, *rt, *rb; unsigned int x_div =3D 0, - y_div =3D 0, uv_stride =3D 0, pixel_width =3D 0; + y_div =3D 0, y_stride =3D 0, uv_stride =3D 0, pixel_width =3D 0; =20 lt =3D &corner_addrs.left_top; lb =3D &corner_addrs.left_bottom; @@ -52,14 +52,15 @@ rga_get_corner_addrs(struct rga_frame *frm, struct rga_= addrs *addrs, =20 x_div =3D frm->fmt->x_div; y_div =3D frm->fmt->y_div; - uv_stride =3D frm->stride / x_div; - pixel_width =3D frm->stride / frm->pix.width; + y_stride =3D frm->pix.plane_fmt[0].bytesperline; + uv_stride =3D y_stride / x_div; + pixel_width =3D y_stride / frm->pix.width; =20 - lt->y_addr =3D addrs->y_addr + y * frm->stride + x * pixel_width; + lt->y_addr =3D addrs->y_addr + y * y_stride + x * pixel_width; lt->u_addr =3D addrs->u_addr + (y / y_div) * uv_stride + x / x_div; lt->v_addr =3D addrs->v_addr + (y / y_div) * uv_stride + x / x_div; =20 - lb->y_addr =3D lt->y_addr + (h - 1) * frm->stride; + lb->y_addr =3D lt->y_addr + (h - 1) * y_stride; lb->u_addr =3D lt->u_addr + (h / y_div - 1) * uv_stride; lb->v_addr =3D lt->v_addr + (h / y_div - 1) * uv_stride; =20 @@ -160,6 +161,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) union rga_src_act_info src_act_info; union rga_dst_vir_info dst_vir_info; union rga_dst_act_info dst_act_info; + u32 in_stride, out_stride; =20 src_h =3D ctx->in.crop.height; src_w =3D ctx->in.crop.width; @@ -282,13 +284,15 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ct= x) * Calculate the framebuffer virtual strides and active size, * note that the step of vir_stride / vir_width is 4 byte words */ - src_vir_info.data.vir_stride =3D ctx->in.stride >> 2; - src_vir_info.data.vir_width =3D ctx->in.stride >> 2; + in_stride =3D ctx->in.pix.plane_fmt[0].bytesperline; + src_vir_info.data.vir_stride =3D in_stride >> 2; + src_vir_info.data.vir_width =3D in_stride >> 2; =20 src_act_info.data.act_height =3D src_h - 1; src_act_info.data.act_width =3D src_w - 1; =20 - dst_vir_info.data.vir_stride =3D ctx->out.stride >> 2; + out_stride =3D ctx->out.pix.plane_fmt[0].bytesperline; + dst_vir_info.data.vir_stride =3D out_stride >> 2; dst_act_info.data.act_height =3D dst_h - 1; dst_act_info.data.act_width =3D dst_w - 1; =20 diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 0d7b0bcac950e..7e30fafb25fab 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -220,8 +220,6 @@ static int rga_open(struct file *file) .fmt =3D &rga->hw->formats[0], }; =20 - def_frame.stride =3D (def_width * def_frame.fmt->depth) >> 3; - ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -428,7 +426,6 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) if (IS_ERR(frm)) return PTR_ERR(frm); frm->fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); - frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; =20 /* Reset crop settings */ frm->crop.left =3D 0; @@ -442,7 +439,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) "[%s] fmt - %p4cc %dx%d (stride %d)\n", V4L2_TYPE_IS_OUTPUT(f->type) ? "OUTPUT" : "CAPTURE", &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, - frm->stride); + pix_fmt->plane_fmt[0].bytesperline); =20 for (i =3D 0; i < pix_fmt->num_planes; i++) { v4l2_dbg(debug, 1, &rga->v4l2_dev, diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 466d568b9e614..a7f891b94a478 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -34,9 +34,6 @@ struct rga_frame { /* Image format */ struct rga_fmt *fmt; struct v4l2_pix_format_mplane pix; - - /* Variables that can calculated once and reused */ - u32 stride; }; =20 struct rga_dma_desc { --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35B6433E374 for ; Wed, 3 Dec 2025 15:54:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777267; cv=none; b=NLjaRlBlVOJlQC/fGxQKR5BBcGydN6ynVdoBfdX02ruFZfAK8EmI36iWY9aJ+jrW6lJA+9QOmV8Ddi2LBvrhW3pgSv8hLnWignphYcKnxZQy/4lkFIkNDbY2aqMnVyRZCDHERmkYa+t/B1G9WQPfMKOWcpVVPziGSLPji/zHJDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777267; c=relaxed/simple; bh=pEZ3AgqgkGFYXkKT43L3uE2VmjxhUre9UmlhpRwiRHU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sfgnL9m0py030BM+bjIOmrbMeHMycEC/h/9hQyE73viG0DXLf/V47ogiEbIsB17M/hzywJxb4aetZruqsHHdReLbkSwfqw0xwAvAurXVMSgHGgLmal7qWxjX3mbIhYTvMiEALNYN/cXeGyHMNjpoNs4kAZ5A4MwjS119XOYvLKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAe-0007dW-HJ; Wed, 03 Dec 2025 16:53:36 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:40 +0100 Subject: [PATCH v2 18/22] media: rockchip: rga: move rga_fmt to rga-hw.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-18-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Move rga_fmt to rga-hw in preparation of the RGA3 addition, as the struct contains many RGA2 specific values. They are used to write the correct register values quickly based on the chosen format. Therefore the pointer to the rga_fmt struct is kept but changed to an opaque void pointer outside of the rga-hw.h. To enumerate and set the correct formats, two helper functions need to be exposed in the rga_hw struct: enum_format just get's the vidioc_enum_fmt format and it's return value is also returned from vidioc_enum_fmt. This is a simple pass-through, as the implementation is very simple. adjust_and_map_format is a simple abstraction around the previous rga_find_format. But unlike rga_find_format, it always returns a valid format. Therefore the passed format value is also a pointer to update it in case the values are not supported by the hardware. Due to the RGA3 supporting different formats on the capture and output side, an additional parameter is_capture has been added to support this use-case. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 2 +- drivers/media/platform/rockchip/rga/rga-hw.c | 53 +++++++++++++++++++++--= ---- drivers/media/platform/rockchip/rga/rga-hw.h | 12 ++++++ drivers/media/platform/rockchip/rga/rga.c | 38 +++++-------------- drivers/media/platform/rockchip/rga/rga.h | 17 ++------- 5 files changed, 68 insertions(+), 54 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index 8de6b9c3fd615..b0f226f7f06d9 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -158,7 +158,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb) } =20 /* Fill the remaining planes */ - info =3D v4l2_format_info(f->fmt->fourcc); + info =3D v4l2_format_info(f->pix.pixelformat); for (i =3D info->mem_planes; i < info->comp_planes; i++) dma_addrs[i] =3D dma_addrs[0] + get_plane_offset(f, info, i); =20 diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 4dee33d8f7206..a868a34a1452e 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -44,14 +44,15 @@ rga_get_corner_addrs(struct rga_frame *frm, struct rga_= addrs *addrs, struct rga_addrs *lt, *lb, *rt, *rb; unsigned int x_div =3D 0, y_div =3D 0, y_stride =3D 0, uv_stride =3D 0, pixel_width =3D 0; + struct rga_fmt *fmt =3D frm->fmt; =20 lt =3D &corner_addrs.left_top; lb =3D &corner_addrs.left_bottom; rt =3D &corner_addrs.right_top; rb =3D &corner_addrs.right_bottom; =20 - x_div =3D frm->fmt->x_div; - y_div =3D frm->fmt->y_div; + x_div =3D fmt->x_div; + y_div =3D fmt->y_div; y_stride =3D frm->pix.plane_fmt[0].bytesperline; uv_stride =3D y_stride / x_div; pixel_width =3D y_stride / frm->pix.width; @@ -162,6 +163,8 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) union rga_dst_vir_info dst_vir_info; union rga_dst_act_info dst_act_info; u32 in_stride, out_stride; + struct rga_fmt *in_fmt =3D ctx->in.fmt; + struct rga_fmt *out_fmt =3D ctx->out.fmt; =20 src_h =3D ctx->in.crop.height; src_w =3D ctx->in.crop.width; @@ -177,18 +180,18 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ct= x) dst_vir_info.val =3D dest[(RGA_DST_VIR_INFO - RGA_MODE_BASE_REG) >> 2]; dst_act_info.val =3D dest[(RGA_DST_ACT_INFO - RGA_MODE_BASE_REG) >> 2]; =20 - src_info.data.format =3D ctx->in.fmt->hw_format; - src_info.data.swap =3D ctx->in.fmt->color_swap; - dst_info.data.format =3D ctx->out.fmt->hw_format; - dst_info.data.swap =3D ctx->out.fmt->color_swap; + src_info.data.format =3D in_fmt->hw_format; + src_info.data.swap =3D in_fmt->color_swap; + dst_info.data.format =3D out_fmt->hw_format; + dst_info.data.swap =3D out_fmt->color_swap; =20 /* * CSC mode must only be set when the colorspace families differ between * input and output. It must remain unset (zeroed) if both are the same. */ =20 - if (RGA_COLOR_FMT_IS_YUV(ctx->in.fmt->hw_format) && - RGA_COLOR_FMT_IS_RGB(ctx->out.fmt->hw_format)) { + if (RGA_COLOR_FMT_IS_YUV(in_fmt->hw_format) && + RGA_COLOR_FMT_IS_RGB(out_fmt->hw_format)) { switch (ctx->in.pix.colorspace) { case V4L2_COLORSPACE_REC709: src_info.data.csc_mode =3D RGA_SRC_CSC_MODE_BT709_R0; @@ -199,8 +202,8 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) } } =20 - if (RGA_COLOR_FMT_IS_RGB(ctx->in.fmt->hw_format) && - RGA_COLOR_FMT_IS_YUV(ctx->out.fmt->hw_format)) { + if (RGA_COLOR_FMT_IS_RGB(in_fmt->hw_format) && + RGA_COLOR_FMT_IS_YUV(out_fmt->hw_format)) { switch (ctx->out.pix.colorspace) { case V4L2_COLORSPACE_REC709: dst_info.data.csc_mode =3D RGA_SRC_CSC_MODE_BT709_R0; @@ -619,11 +622,35 @@ static struct rga_fmt formats[] =3D { }, }; =20 +static void *rga_adjust_and_map_format(struct v4l2_pix_format_mplane *form= at, + bool is_output) +{ + unsigned int i; + + if (!format) + return &formats[0]; + + for (i =3D 0; i < ARRAY_SIZE(formats); i++) { + if (formats[i].fourcc =3D=3D format->pixelformat) + return &formats[i]; + } + + format->pixelformat =3D formats[0].fourcc; + return &formats[0]; +} + +static int rga_enum_format(struct v4l2_fmtdesc *f) +{ + if (f->index >=3D ARRAY_SIZE(formats)) + return -EINVAL; + + f->pixelformat =3D formats[f->index].fourcc; + return 0; +} + const struct rga_hw rga2_hw =3D { .card_type =3D "rga2", .has_internal_iommu =3D true, - .formats =3D formats, - .num_formats =3D ARRAY_SIZE(formats), .cmdbuf_size =3D RGA_CMDBUF_SIZE, .min_width =3D MIN_WIDTH, .max_width =3D MAX_WIDTH, @@ -636,4 +663,6 @@ const struct rga_hw rga2_hw =3D { .start =3D rga_hw_start, .handle_irq =3D rga_handle_irq, .get_version =3D rga_get_version, + .adjust_and_map_format =3D rga_adjust_and_map_format, + .enum_format =3D rga_enum_format, }; diff --git a/drivers/media/platform/rockchip/rga/rga-hw.h b/drivers/media/p= latform/rockchip/rga/rga-hw.h index fffcab0131225..3bc4b1f5acba2 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.h +++ b/drivers/media/platform/rockchip/rga/rga-hw.h @@ -6,6 +6,8 @@ #ifndef __RGA_HW_H__ #define __RGA_HW_H__ =20 +#include + #define RGA_CMDBUF_SIZE 0x20 =20 /* Hardware limits */ @@ -431,4 +433,14 @@ union rga_pat_con { } data; }; =20 +struct rga_fmt { + u32 fourcc; + int depth; + u8 uv_factor; + u8 y_div; + u8 x_div; + u8 color_swap; + u8 hw_format; +}; + #endif diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 7e30fafb25fab..c991cc64b4b7f 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -185,17 +185,6 @@ static int rga_setup_ctrls(struct rga_ctx *ctx) return 0; } =20 -static struct rga_fmt *rga_fmt_find(struct rockchip_rga *rga, u32 pixelfor= mat) -{ - unsigned int i; - - for (i =3D 0; i < rga->hw->num_formats; i++) { - if (rga->hw->formats[i].fourcc =3D=3D pixelformat) - return &rga->hw->formats[i]; - } - return NULL; -} - struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type ty= pe) { if (V4L2_TYPE_IS_OUTPUT(type)) @@ -217,7 +206,6 @@ static int rga_open(struct file *file) .crop.top =3D 0, .crop.width =3D def_width, .crop.height =3D def_height, - .fmt =3D &rga->hw->formats[0], }; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -238,9 +226,11 @@ static int rga_open(struct file *file) ctx->in =3D def_frame; ctx->out =3D def_frame; =20 - v4l2_fill_pixfmt_mp_aligned(&ctx->in.pix, ctx->in.fmt->fourcc, + ctx->in.fmt =3D rga->hw->adjust_and_map_format(&ctx->in.pix, true); + v4l2_fill_pixfmt_mp_aligned(&ctx->in.pix, ctx->in.pix.pixelformat, def_width, def_height, rga->hw->stride_alignment); - v4l2_fill_pixfmt_mp_aligned(&ctx->out.pix, ctx->out.fmt->fourcc, + ctx->out.fmt =3D rga->hw->adjust_and_map_format(&ctx->out.pix, false); + v4l2_fill_pixfmt_mp_aligned(&ctx->out.pix, ctx->out.pix.pixelformat, def_width, def_height, rga->hw->stride_alignment); =20 if (mutex_lock_interruptible(&rga->mutex)) { @@ -322,15 +312,8 @@ vidioc_querycap(struct file *file, void *priv, struct = v4l2_capability *cap) static int vidioc_enum_fmt(struct file *file, void *priv, struct v4l2_fmtd= esc *f) { struct rockchip_rga *rga =3D video_drvdata(file); - struct rga_fmt *fmt; =20 - if (f->index >=3D rga->hw->num_formats) - return -EINVAL; - - fmt =3D &rga->hw->formats[f->index]; - f->pixelformat =3D fmt->fourcc; - - return 0; + return rga->hw->enum_format(f); } =20 static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format = *f) @@ -355,15 +338,13 @@ static int vidioc_try_fmt(struct file *file, void *pr= iv, struct v4l2_format *f) struct rga_ctx *ctx =3D file_to_rga_ctx(file); struct rockchip_rga *rga =3D ctx->rga; const struct rga_hw *hw =3D rga->hw; - struct rga_fmt *fmt; u32 min_width =3D hw->min_width; u32 max_width =3D hw->max_width; u32 min_height =3D hw->min_height; u32 max_height =3D hw->max_height; =20 - fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); - if (!fmt) - fmt =3D &hw->formats[0]; + hw->adjust_and_map_format(pix_fmt, + V4L2_TYPE_IS_OUTPUT(f->type)); =20 if (V4L2_TYPE_IS_OUTPUT(f->type) && v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx)->streaming) { @@ -425,7 +406,8 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) frm =3D rga_get_frame(ctx, f->type); if (IS_ERR(frm)) return PTR_ERR(frm); - frm->fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); + frm->fmt =3D rga->hw->adjust_and_map_format(pix_fmt, + V4L2_TYPE_IS_OUTPUT(f->type)); =20 /* Reset crop settings */ frm->crop.left =3D 0; @@ -438,7 +420,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) v4l2_dbg(debug, 1, &rga->v4l2_dev, "[%s] fmt - %p4cc %dx%d (stride %d)\n", V4L2_TYPE_IS_OUTPUT(f->type) ? "OUTPUT" : "CAPTURE", - &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, + &pix_fmt->pixelformat, pix_fmt->width, pix_fmt->height, pix_fmt->plane_fmt[0].bytesperline); =20 for (i =3D 0; i < pix_fmt->num_planes; i++) { diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index a7f891b94a478..980f70f842317 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -17,22 +17,12 @@ #define DEFAULT_WIDTH 100 #define DEFAULT_HEIGHT 100 =20 -struct rga_fmt { - u32 fourcc; - int depth; - u8 uv_factor; - u8 y_div; - u8 x_div; - u8 color_swap; - u8 hw_format; -}; - struct rga_frame { /* Crop */ struct v4l2_rect crop; =20 /* Image format */ - struct rga_fmt *fmt; + void *fmt; struct v4l2_pix_format_mplane pix; }; =20 @@ -145,8 +135,6 @@ static inline void rga_mod(struct rockchip_rga *rga, u3= 2 reg, u32 val, u32 mask) struct rga_hw { const char *card_type; bool has_internal_iommu; - struct rga_fmt *formats; - u32 num_formats; size_t cmdbuf_size; u32 min_width, min_height; u32 max_width, max_height; @@ -158,6 +146,9 @@ struct rga_hw { struct rga_vb_buffer *src, struct rga_vb_buffer *dst); bool (*handle_irq)(struct rockchip_rga *rga); void (*get_version)(struct rockchip_rga *rga); + void *(*adjust_and_map_format)(struct v4l2_pix_format_mplane *format, + bool is_output); + int (*enum_format)(struct v4l2_fmtdesc *f); }; =20 static inline bool rga_has_internal_iommu(const struct rockchip_rga *rga) --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A24733B6F3 for ; Wed, 3 Dec 2025 15:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777252; cv=none; b=ZQ47onGo/Mh1pEAnMw6Xehpwhe4jqXq+VmGBJrTGM++2GgDgWDO59P1CHoaUJPM5w4JqwwrcKFMVZnObPJHtkguhAgu4ZZkTYEnNGaQLsxw4MCNRi0jiKl6wQsVuooG1tZT5VnvRr62fnce75jYx2tgejPYms4uylNTOIkGX6T0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777252; c=relaxed/simple; bh=rRA5vK2kyldTpiHys/maiuTnUpy5Q8j0TDl7dGgM8b8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U923hMc/L32ULWB/0HTZ800F0ADNzxBZlZwtTcqBxQ8jKE000Jyr6AxPpCzbSmNrVNClFGKOxiI7M5LcuCgfOI1nq4o7qMljYsWpWPvGy6x32wASxrQu5D4cjLscY5h4z3mFHX1ZaAszS7pE17ZKYHnxIklHtWXpn9Ia6+jSajE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAe-0007dW-OX; Wed, 03 Dec 2025 16:53:36 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:41 +0100 Subject: [PATCH v2 19/22] media: rockchip: rga: add feature flags Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-19-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org In preparation to the RGA3 addition add feature flags, which can limit the exposed feature set of the video device, like rotating or selection support. This is necessary as the RGA3 doesn't initially implement the full feature set currently exposed by the driver. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 4 ++++ drivers/media/platform/rockchip/rga/rga.c | 23 +++++++++++++++-------- drivers/media/platform/rockchip/rga/rga.h | 7 +++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index a868a34a1452e..0d1cf911af0d5 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -658,6 +658,10 @@ const struct rga_hw rga2_hw =3D { .max_height =3D MAX_HEIGHT, .max_scaling_factor =3D MAX_SCALING_FACTOR, .stride_alignment =3D 4, + .features =3D RGA_FEATURE_FLIP + | RGA_FEATURE_ROTATE + | RGA_FEATURE_BG_COLOR + | RGA_FEATURE_SELECTION, =20 .setup_cmdbuf =3D rga_hw_setup_cmdbuf, .start =3D rga_hw_start, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index c991cc64b4b7f..3958e71b8987d 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -162,17 +162,21 @@ static int rga_setup_ctrls(struct rga_ctx *ctx) =20 v4l2_ctrl_handler_init(&ctx->ctrl_handler, 4); =20 - v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, - V4L2_CID_HFLIP, 0, 1, 1, 0); + if (rga->hw->features & RGA_FEATURE_FLIP) { + v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, + V4L2_CID_HFLIP, 0, 1, 1, 0); =20 - v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, - V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, + V4L2_CID_VFLIP, 0, 1, 1, 0); + } =20 - v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, - V4L2_CID_ROTATE, 0, 270, 90, 0); + if (rga->hw->features & RGA_FEATURE_ROTATE) + v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, + V4L2_CID_ROTATE, 0, 270, 90, 0); =20 - v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, - V4L2_CID_BG_COLOR, 0, 0xffffffff, 1, 0); + if (rga->hw->features & RGA_FEATURE_BG_COLOR) + v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, + V4L2_CID_BG_COLOR, 0, 0xffffffff, 1, 0); =20 if (ctx->ctrl_handler.error) { int err =3D ctx->ctrl_handler.error; @@ -489,6 +493,9 @@ static int vidioc_s_selection(struct file *file, void *= priv, struct rga_frame *f; int ret =3D 0; =20 + if (!(rga->hw->features & RGA_FEATURE_SELECTION)) + return -EINVAL; + f =3D rga_get_frame(ctx, s->type); if (IS_ERR(f)) return PTR_ERR(f); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 980f70f842317..b9c75b5fda4dc 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -6,6 +6,7 @@ #ifndef __RGA_H__ #define __RGA_H__ =20 +#include #include #include #include @@ -132,6 +133,11 @@ static inline void rga_mod(struct rockchip_rga *rga, u= 32 reg, u32 val, u32 mask) rga_write(rga, reg, temp); }; =20 +#define RGA_FEATURE_FLIP BIT(0) +#define RGA_FEATURE_ROTATE BIT(1) +#define RGA_FEATURE_BG_COLOR BIT(2) +#define RGA_FEATURE_SELECTION BIT(3) + struct rga_hw { const char *card_type; bool has_internal_iommu; @@ -140,6 +146,7 @@ struct rga_hw { u32 max_width, max_height; u8 max_scaling_factor; u8 stride_alignment; + u8 features; =20 void (*setup_cmdbuf)(struct rga_ctx *ctx); void (*start)(struct rockchip_rga *rga, --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6330B3396FA for ; Wed, 3 Dec 2025 15:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777255; cv=none; b=l6lYff/xPvOJCpRxd+KHOzlTilb476ch0GCiHbwtmIg3nrKUnUEYTIyoVzEzC8YE+UjOC4AVQq2c9lTLxASirkM53jc7IsrlxbzlUety7/kKaOwKmaaRxzLC2gpQ5HNXcwYIIu+M5o0togN8eVfYxpZr6FLzeQezOMLpx1NQ41M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777255; c=relaxed/simple; bh=RNLZlK3ZCHBGRd9kdE2qLK4mSIb9x6NAepsB8YXR4CM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UcPaPOhNAyQVes92ij5M0vk2p9x/joDTBmKgN+u6mwBaB1OkG6hMvAvfolcxwFkdE1KDGN63X3C+fknVmENH5iTen3ARvrkeeHVSBu3m8ki146JmWVtSevwlX6mpYzmxQCOmd4duY/U2VH8qGp88T5FOkc7A187rQF/w+Yt10no= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAe-0007dW-SI; Wed, 03 Dec 2025 16:53:36 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:42 +0100 Subject: [PATCH v2 20/22] media: rockchip: rga: disable multi-core support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-20-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Disable multi-core support in preparation of the RGA3 addition. The RK3588 SoC features two equal RGA3 cores. This allows scheduling of the work between both cores, which is not yet implemented. Until it is implemented avoid exposing both cores as independent video devices to prevent an ABI breakage when multi-core support is added. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 3958e71b8987d..65686228b7300 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -660,6 +660,30 @@ static int rga_parse_dt(struct rockchip_rga *rga) return 0; } =20 +static int rga_disable_multicore(struct device *dev) +{ + const char *compatible; + struct device_node *node; + int ret; + + /* Intentionally ignores the fallback strings */ + ret =3D of_property_read_string(dev->of_node, "compatible", &compatible); + if (ret) + return ret; + + /* first compatible node found from the root node is considered the main = core */ + node =3D of_find_compatible_node(NULL, NULL, compatible); + if (!node) + return -EINVAL; /* broken DT? */ + + if (dev->of_node !=3D node) { + dev_info(dev, "missing multi-core support, ignoring this instance\n"); + return -ENODEV; + } + + return 0; +} + static int rga_probe(struct platform_device *pdev) { struct rockchip_rga *rga; @@ -670,6 +694,10 @@ static int rga_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; =20 + ret =3D rga_disable_multicore(&pdev->dev); + if (ret) + return ret; + rga =3D devm_kzalloc(&pdev->dev, sizeof(*rga), GFP_KERNEL); if (!rga) return -ENOMEM; --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00C1633DEE6 for ; Wed, 3 Dec 2025 15:54:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777265; cv=none; b=iWPu/YM4DnDTgpzwjH2EiQI/Yz2JZaj/q1Cr55CZsdTXzkj82ERngNNi2WAzZ+lgGc7EsJTjrJUOip1ITKFYK+8jOaNCcw0uKbR+1+ODQbeXfVYqM3+ZzNH0abrUCYzaAV7e97ofsaSGBbQAHIz2Yjnbo2vJLSgvPI+OghLUPzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777265; c=relaxed/simple; bh=ZRkpJhdCeSsyVyER6cKwnAo9Q9N+XdTxBdRrzHP+CgI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ntq7jBDtVnb6cOxKnVmKCYBnY13+ibNn6TogAULx8yxNtT4pHxuwkQD4eIEgvl66mtojdHSmfeTfjczvDsNcBJnETT+AKIbpnfi29JEZGm10n0WkdF4jooWljip/sRMeB7WN9mvV08ZOVrCcJQHkaWJVQ2hTns03JgT3ZzpLsbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAf-0007dW-03; Wed, 03 Dec 2025 16:53:37 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:43 +0100 Subject: [PATCH v2 21/22] media: rockchip: rga: add rga3 support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-21-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add support for the RGA3 unit contained in the RK3588. Only a basic feature set consisting of scaling and color conversion is implemented. Also the BT601F color space conversion is currently hard coded. Currently unimplemented features include: - Advanced formats like 10bit YUV, FBCE mode and Tile8x8 mode - Colorspace conversions functions BT601L, BT709, BT2020 - Background color (V4L2_CID_BG_COLOR) - Configurable alpha value (V4L2_CID_ALPHA_COMPONENT) - Image flipping (V4L2_CID_HFLIP and V4L2_CID_VFLIP) - Image rotation (V4L2_CID_ROTATE) - Image cropping/composing (VIDIOC_S_SELECTION) The register address defines were copied from the vendor Rockchip kernel sources and slightly adjusted to not start at 0 again for the cmd registers. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/Makefile | 2 +- drivers/media/platform/rockchip/rga/rga.c | 4 + drivers/media/platform/rockchip/rga/rga.h | 2 +- drivers/media/platform/rockchip/rga/rga3-hw.c | 471 ++++++++++++++++++++++= ++++ drivers/media/platform/rockchip/rga/rga3-hw.h | 190 +++++++++++ 5 files changed, 667 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/Makefile b/drivers/media/p= latform/rockchip/rga/Makefile index 1bbecdc3d8df2..7326a548f3dc7 100644 --- a/drivers/media/platform/rockchip/rga/Makefile +++ b/drivers/media/platform/rockchip/rga/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -rockchip-rga-objs :=3D rga.o rga-hw.o rga-buf.o +rockchip-rga-objs :=3D rga.o rga-hw.o rga3-hw.o rga-buf.o =20 obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) +=3D rockchip-rga.o diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 65686228b7300..313d875c789bf 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -843,6 +843,10 @@ static const struct of_device_id rockchip_rga_match[] = =3D { .compatible =3D "rockchip,rk3399-rga", .data =3D &rga2_hw, }, + { + .compatible =3D "rockchip,rk3588-rga3", + .data =3D &rga3_hw, + }, {}, }; =20 diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index b9c75b5fda4dc..2c5f0330879fa 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -163,6 +163,6 @@ static inline bool rga_has_internal_iommu(const struct = rockchip_rga *rga) return rga->hw->has_internal_iommu; } =20 -extern const struct rga_hw rga2_hw; +extern const struct rga_hw rga2_hw, rga3_hw; =20 #endif diff --git a/drivers/media/platform/rockchip/rga/rga3-hw.c b/drivers/media/= platform/rockchip/rga/rga3-hw.c new file mode 100644 index 0000000000000..2b8cd639da39b --- /dev/null +++ b/drivers/media/platform/rockchip/rga/rga3-hw.c @@ -0,0 +1,471 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) Pengutronix e.K. + * Author: Sven P=C3=BCschel + */ + +#include +#include +#include +#include + +#include + +#include "rga3-hw.h" +#include "rga.h" + +static unsigned int rga3_get_scaling(unsigned int src, unsigned int dst) +{ + /* + * RGA3 scaling factor calculation as described in chapter 5.4.7 Resize + * of the TRM Part 2. The resulting scaling factor is a 16-bit value + * and therefore normalized with 2^16. + * + * While the TRM also mentions (dst-1)/(src-1) for the up-scaling case, + * it didn't work as the value always exceeds 16 bit. Flipping the + * factors results in a correct up-scaling. This is possible as the + * RGA3 has the RGA3_WIN_SCALE_XXX_UP bit to determine if it does + * an up or downscale. + * + * With a scaling factor of 1.0 the calculation technically also + * overflows 16 bit. This isn't relevant, as in this case the + * RGA3_WIN_SCALE_XXX_BYPASS bit completely skips the scaling operation. + */ + if (dst > src) { + if (((src - 1) << 16) % (dst - 1) =3D=3D 0) + return ((src - 1) << 16) / (dst - 1) - 1; + else + return ((src - 1) << 16) / (dst - 1); + } else { + return ((dst - 1) << 16) / (src - 1) + 1; + } +} + +/* + * Check if the given format can be captured, as the RGA3 doesn't support = all + * input formats also on it's output. + */ +static bool rga3_can_capture(const struct rga3_fmt *fmt) +{ + return fmt->hw_format <=3D RGA3_COLOR_FMT_LAST_OUTPUT; +} + +/* + * Map the transformations to the RGA3 command buffer. + * Currently this is just the scaling settings and a fixed alpha value. + */ +static void rga3_cmd_set_trans_info(struct rga_ctx *ctx) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + unsigned int src_h, src_w, dst_h, dst_w; + unsigned int reg; + u16 hor_scl_fac, ver_scl_fac; + const struct rga3_fmt *in =3D ctx->in.fmt; + + src_h =3D ctx->in.pix.height; + src_w =3D ctx->in.pix.width; + dst_h =3D ctx->out.pix.height; + dst_w =3D ctx->out.pix.width; + + reg =3D RGA3_WIN0_RD_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] |=3D FIELD_PREP(RGA3_WIN_SCALE_HOR_UP, dst_w > src_w) + | FIELD_PREP(RGA3_WIN_SCALE_HOR_BYPASS, dst_w =3D=3D src_w) + | FIELD_PREP(RGA3_WIN_SCALE_VER_UP, dst_h > src_h) + | FIELD_PREP(RGA3_WIN_SCALE_VER_BYPASS, dst_h =3D=3D src_h); + + hor_scl_fac =3D rga3_get_scaling(src_w, dst_w); + ver_scl_fac =3D rga3_get_scaling(src_h, dst_h); + reg =3D RGA3_WIN0_SCL_FAC - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_SCALE_HOR_FAC, hor_scl_fac) + | FIELD_PREP(RGA3_SCALE_VER_FAC, ver_scl_fac); + + if (v4l2_format_info(in->fourcc)->has_alpha) { + /* copy alpha from input */ + reg =3D RGA3_OVLP_TOP_ALPHA - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_ALPHA_SELECT_MODE, 1) + | FIELD_PREP(RGA3_ALPHA_BLEND_MODE, 1); + reg =3D RGA3_OVLP_BOT_ALPHA - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_ALPHA_SELECT_MODE, 1) + | FIELD_PREP(RGA3_ALPHA_BLEND_MODE, 1); + } else { + /* just use a 255 alpha value */ + reg =3D RGA3_OVLP_TOP_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_OVLP_GLOBAL_ALPHA, 0xff) + | FIELD_PREP(RGA3_OVLP_COLOR_MODE, 1); + reg =3D RGA3_OVLP_BOT_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_OVLP_GLOBAL_ALPHA, 0xff) + | FIELD_PREP(RGA3_OVLP_COLOR_MODE, 1); + } +} + +static void rga3_cmd_set_win0_addr(struct rga_ctx *ctx, + const struct rga_addrs *addrs) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + unsigned int reg; + + reg =3D RGA3_WIN0_Y_BASE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D addrs->y_addr; + reg =3D RGA3_WIN0_U_BASE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D addrs->u_addr; +} + +static void rga3_cmd_set_wr_addr(struct rga_ctx *ctx, + const struct rga_addrs *addrs) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + unsigned int reg; + + reg =3D RGA3_WR_Y_BASE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D addrs->y_addr; + reg =3D RGA3_WR_U_BASE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D addrs->u_addr; +} + +/* Map the input pixel format to win0 of the comamnd buffer. */ +static void rga3_cmd_set_win0_format(struct rga_ctx *ctx) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + const struct rga3_fmt *in =3D ctx->in.fmt; + const struct rga3_fmt *out =3D ctx->out.fmt; + const struct v4l2_format_info *in_fmt, *out_fmt; + unsigned int src_h, src_w; + bool r2y, y2r; + u8 rd_format; + unsigned int reg; + + src_h =3D ctx->in.pix.height; + src_w =3D ctx->in.pix.width; + + in_fmt =3D v4l2_format_info(in->fourcc); + out_fmt =3D v4l2_format_info(out->fourcc); + r2y =3D v4l2_is_format_rgb(in_fmt) && v4l2_is_format_yuv(out_fmt); + y2r =3D v4l2_is_format_yuv(in_fmt) && v4l2_is_format_rgb(out_fmt); + + if (in->semi_planar) + rd_format =3D RGA3_RDWR_FORMAT_SEMI_PLANAR; + else + rd_format =3D RGA3_RDWR_FORMAT_INTERLEAVED; + + /* set pixel format and CSC */ + reg =3D RGA3_WIN0_RD_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] |=3D FIELD_PREP(RGA3_WIN_PIC_FORMAT, in->hw_format) + | FIELD_PREP(RGA3_WIN_YC_SWAP, in->yc_swap) + | FIELD_PREP(RGA3_WIN_RBUV_SWAP, in->rbuv_swap) + | FIELD_PREP(RGA3_WIN_RD_FORMAT, rd_format) + | FIELD_PREP(RGA3_WIN_R2Y, r2y) + | FIELD_PREP(RGA3_WIN_Y2R, y2r) + | FIELD_PREP(RGA3_WIN_CSC_MODE, RGA3_WIN_CSC_MODE_BT601_F); + + /* set stride */ + reg =3D RGA3_WIN0_VIR_STRIDE - RGA3_FIRST_CMD_REG; + /* stride needs to be in words */ + cmd[reg >> 2] =3D ctx->in.pix.plane_fmt[0].bytesperline >> 2; + reg =3D RGA3_WIN0_UV_VIR_STRIDE - RGA3_FIRST_CMD_REG; + /* The Hardware only supports formats with 1/2 planes */ + if (ctx->in.pix.num_planes =3D=3D 2) + cmd[reg >> 2] =3D ctx->in.pix.plane_fmt[1].bytesperline >> 2; + else + cmd[reg >> 2] =3D ctx->in.pix.plane_fmt[0].bytesperline >> 2; + + /* set size */ + reg =3D RGA3_WIN0_ACT_SIZE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_WIDTH, src_w) + | FIELD_PREP(RGA3_HEIGHT, src_h); + /* no cropping support. Use same value as ACT_SIZE */ + reg =3D RGA3_WIN0_SRC_SIZE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_WIDTH, src_w) + | FIELD_PREP(RGA3_HEIGHT, src_h); +} + +static void rga3_cmd_enable_win0(struct rga_ctx *ctx) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + unsigned int reg; + + reg =3D RGA3_WIN0_RD_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] |=3D FIELD_PREP(RGA3_WIN_ENABLE, 1); +} + +/* Map the output pixel format to the command buffer */ +static void rga3_cmd_set_wr_format(struct rga_ctx *ctx) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + const struct rga3_fmt *out =3D ctx->out.fmt; + unsigned int dst_h, dst_w; + u8 wr_format; + unsigned int reg; + + dst_h =3D ctx->out.pix.height; + dst_w =3D ctx->out.pix.width; + + if (out->semi_planar) + wr_format =3D RGA3_RDWR_FORMAT_SEMI_PLANAR; + else + wr_format =3D RGA3_RDWR_FORMAT_INTERLEAVED; + + /* set pixel format */ + reg =3D RGA3_WR_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] |=3D FIELD_PREP(RGA3_WR_PIC_FORMAT, out->hw_format) + | FIELD_PREP(RGA3_WR_YC_SWAP, out->yc_swap) + | FIELD_PREP(RGA3_WR_RBUV_SWAP, out->rbuv_swap) + | FIELD_PREP(RGA3_WR_FORMAT, wr_format); + + /* set stride */ + reg =3D RGA3_WR_VIR_STRIDE - RGA3_FIRST_CMD_REG; + /* stride needs to be in words */ + cmd[reg >> 2] =3D ctx->out.pix.plane_fmt[0].bytesperline >> 2; + reg =3D RGA3_WR_PL_VIR_STRIDE - RGA3_FIRST_CMD_REG; + /* The Hardware only supports formats with 1/2 planes */ + if (ctx->out.pix.num_planes =3D=3D 2) + cmd[reg >> 2] =3D ctx->out.pix.plane_fmt[1].bytesperline >> 2; + else + cmd[reg >> 2] =3D ctx->out.pix.plane_fmt[0].bytesperline >> 2; + + /* Set size. + * As two inputs are not supported, we don't use win1. + * Therefore only set the size for win0. + */ + reg =3D RGA3_WIN0_DST_SIZE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_WIDTH, dst_w) + | FIELD_PREP(RGA3_HEIGHT, dst_h); +} + +static void rga3_cmd_disable_wr_limitation(struct rga_ctx *ctx) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + unsigned int reg; + + /* Use the max value to avoid limiting the write speed */ + reg =3D RGA3_WR_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] |=3D FIELD_PREP(RGA3_WR_SW_OUTSTANDING_MAX, 63); +} + +static void rga3_hw_setup_cmdbuf(struct rga_ctx *ctx) +{ + memset(ctx->cmdbuf_virt, 0, RGA3_CMDBUF_SIZE * 4); + + rga3_cmd_set_win0_format(ctx); + rga3_cmd_enable_win0(ctx); + rga3_cmd_set_trans_info(ctx); + rga3_cmd_set_wr_format(ctx); + rga3_cmd_disable_wr_limitation(ctx); +} + +static void rga3_hw_start(struct rockchip_rga *rga, + struct rga_vb_buffer *src, struct rga_vb_buffer *dst) +{ + struct rga_ctx *ctx =3D rga->curr; + + rga3_cmd_set_win0_addr(ctx, &src->dma_addrs); + rga3_cmd_set_wr_addr(ctx, &dst->dma_addrs); + + rga_write(rga, RGA3_CMD_ADDR, ctx->cmdbuf_phy); + + /* sync CMD buf for RGA */ + dma_sync_single_for_device(rga->dev, ctx->cmdbuf_phy, + PAGE_SIZE, DMA_BIDIRECTIONAL); + + /* set to master mode and start the conversion */ + rga_write(rga, RGA3_SYS_CTRL, + FIELD_PREP(RGA3_CMD_MODE, RGA3_CMD_MODE_MASTER)); + rga_write(rga, RGA3_INT_EN, FIELD_PREP(RGA3_INT_FRM_DONE, 1)); + rga_write(rga, RGA3_CMD_CTRL, + FIELD_PREP(RGA3_CMD_LINE_START_PULSE, 1)); +} + +static bool rga3_handle_irq(struct rockchip_rga *rga) +{ + u32 intr; + + intr =3D rga_read(rga, RGA3_INT_RAW); + /* clear all interrupts */ + rga_write(rga, RGA3_INT_CLR, intr); + + return FIELD_GET(RGA3_INT_FRM_DONE, intr); +} + +static void rga3_get_version(struct rockchip_rga *rga) +{ + u32 version =3D rga_read(rga, RGA3_VERSION_NUM); + + rga->version.major =3D FIELD_GET(RGA3_VERSION_NUM_MAJOR, version); + rga->version.minor =3D FIELD_GET(RGA3_VERSION_NUM_MINOR, version); +} + +static struct rga3_fmt rga3_formats[] =3D { + { + .fourcc =3D V4L2_PIX_FMT_RGB24, + .hw_format =3D RGA3_COLOR_FMT_BGR888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_BGR24, + .hw_format =3D RGA3_COLOR_FMT_BGR888, + }, + { + .fourcc =3D V4L2_PIX_FMT_ABGR32, + .hw_format =3D RGA3_COLOR_FMT_BGRA8888, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGBA32, + .hw_format =3D RGA3_COLOR_FMT_BGRA8888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_XBGR32, + .hw_format =3D RGA3_COLOR_FMT_BGRA8888, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGBX32, + .hw_format =3D RGA3_COLOR_FMT_BGRA8888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGB565, + .hw_format =3D RGA3_COLOR_FMT_BGR565, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV12M, + .hw_format =3D RGA3_COLOR_FMT_YUV420, + .semi_planar =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV12, + .hw_format =3D RGA3_COLOR_FMT_YUV420, + .semi_planar =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV21M, + .hw_format =3D RGA3_COLOR_FMT_YUV420, + .rbuv_swap =3D 1, + .semi_planar =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV21, + .hw_format =3D RGA3_COLOR_FMT_YUV420, + .rbuv_swap =3D 1, + .semi_planar =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV16M, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .semi_planar =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV16, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .semi_planar =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV61M, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .rbuv_swap =3D 1, + .semi_planar =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV61, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .rbuv_swap =3D 1, + .semi_planar =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_YUYV, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .yc_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_YVYU, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .yc_swap =3D 1, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_UYVY, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + }, + { + .fourcc =3D V4L2_PIX_FMT_VYUY, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .rbuv_swap =3D 1, + }, + /* Input only formats last to keep rga3_enum_format simple */ + { + .fourcc =3D V4L2_PIX_FMT_ARGB32, + .hw_format =3D RGA3_COLOR_FMT_ABGR8888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_BGRA32, + .hw_format =3D RGA3_COLOR_FMT_ABGR8888, + }, + { + .fourcc =3D V4L2_PIX_FMT_XRGB32, + .hw_format =3D RGA3_COLOR_FMT_ABGR8888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_BGRX32, + .hw_format =3D RGA3_COLOR_FMT_ABGR8888, + }, +}; + +static int rga3_enum_format(struct v4l2_fmtdesc *f) +{ + struct rga3_fmt *fmt; + + if (f->index >=3D ARRAY_SIZE(rga3_formats)) + return -EINVAL; + + fmt =3D &rga3_formats[f->index]; + if (V4L2_TYPE_IS_CAPTURE(f->type) && !rga3_can_capture(fmt)) + return -EINVAL; + + f->pixelformat =3D fmt->fourcc; + return 0; +} + +static void *rga3_adjust_and_map_format(struct v4l2_pix_format_mplane *for= mat, + bool is_output) +{ + unsigned int i; + + if (!format) + return &rga3_formats[0]; + + format->ycbcr_enc =3D V4L2_YCBCR_ENC_601; + format->quantization =3D V4L2_QUANTIZATION_FULL_RANGE; + + for (i =3D 0; i < ARRAY_SIZE(rga3_formats); i++) { + if (!is_output && !rga3_can_capture(&rga3_formats[i])) + continue; + + if (rga3_formats[i].fourcc =3D=3D format->pixelformat) + return &rga3_formats[i]; + } + + format->pixelformat =3D rga3_formats[0].fourcc; + return &rga3_formats[0]; +} + +const struct rga_hw rga3_hw =3D { + .card_type =3D "rga3", + .has_internal_iommu =3D false, + .cmdbuf_size =3D RGA3_CMDBUF_SIZE, + .min_width =3D RGA3_MIN_WIDTH, + .min_height =3D RGA3_MIN_HEIGHT, + /* use output size, as it's a bit smaller than the input size */ + .max_width =3D RGA3_MAX_OUTPUT_WIDTH, + .max_height =3D RGA3_MAX_OUTPUT_HEIGHT, + .max_scaling_factor =3D RGA3_MAX_SCALING_FACTOR, + .stride_alignment =3D 16, + .features =3D 0, + + .setup_cmdbuf =3D rga3_hw_setup_cmdbuf, + .start =3D rga3_hw_start, + .handle_irq =3D rga3_handle_irq, + .get_version =3D rga3_get_version, + .enum_format =3D rga3_enum_format, + .adjust_and_map_format =3D rga3_adjust_and_map_format, +}; diff --git a/drivers/media/platform/rockchip/rga/rga3-hw.h b/drivers/media/= platform/rockchip/rga/rga3-hw.h new file mode 100644 index 0000000000000..fa16b95fb43ba --- /dev/null +++ b/drivers/media/platform/rockchip/rga/rga3-hw.h @@ -0,0 +1,190 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) Pengutronix e.K. + * Author: Sven P=C3=BCschel + */ +#ifndef __RGA3_HW_H__ +#define __RGA3_HW_H__ + +#include +#include + +#define RGA3_CMDBUF_SIZE 0x2e + +#define RGA3_MIN_WIDTH 128 +#define RGA3_MIN_HEIGHT 128 +#define RGA3_MAX_INPUT_WIDTH (8192 - 16) +#define RGA3_MAX_INPUT_HEIGHT (8192 - 16) +#define RGA3_MAX_OUTPUT_WIDTH (8192 - 64) +#define RGA3_MAX_OUTPUT_HEIGHT (8192 - 64) +#define RGA3_MAX_SCALING_FACTOR 8 +#define RGA3_RESET_TIMEOUT 1000 + +/* Registers address */ +/* sys reg */ +#define RGA3_SYS_CTRL 0x000 +#define RGA3_CMD_CTRL 0x004 +#define RGA3_CMD_ADDR 0x008 +#define RGA3_MI_GROUP_CTRL 0x00c +#define RGA3_ARQOS_CTRL 0x010 +#define RGA3_VERSION_NUM 0x018 +#define RGA3_VERSION_TIM 0x01c +#define RGA3_INT_EN 0x020 +#define RGA3_INT_RAW 0x024 +#define RGA3_INT_MSK 0x028 +#define RGA3_INT_CLR 0x02c +#define RGA3_RO_SRST 0x030 +#define RGA3_STATUS0 0x034 +#define RGA3_SCAN_CNT 0x038 +#define RGA3_CMD_STATE 0x040 + +/* cmd reg */ +#define RGA3_WIN0_RD_CTRL 0x100 +#define RGA3_FIRST_CMD_REG RGA3_WIN0_RD_CTRL +#define RGA3_WIN0_Y_BASE 0x110 +#define RGA3_WIN0_U_BASE 0x114 +#define RGA3_WIN0_V_BASE 0x118 +#define RGA3_WIN0_VIR_STRIDE 0x11c +#define RGA3_WIN0_FBC_OFF 0x120 +#define RGA3_WIN0_SRC_SIZE 0x124 +#define RGA3_WIN0_ACT_OFF 0x128 +#define RGA3_WIN0_ACT_SIZE 0x12c +#define RGA3_WIN0_DST_SIZE 0x130 +#define RGA3_WIN0_SCL_FAC 0x134 +#define RGA3_WIN0_UV_VIR_STRIDE 0x138 +#define RGA3_WIN1_RD_CTRL 0x140 +#define RGA3_WIN1_Y_BASE 0x150 +#define RGA3_WIN1_U_BASE 0x154 +#define RGA3_WIN1_V_BASE 0x158 +#define RGA3_WIN1_VIR_STRIDE 0x15c +#define RGA3_WIN1_FBC_OFF 0x160 +#define RGA3_WIN1_SRC_SIZE 0x164 +#define RGA3_WIN1_ACT_OFF 0x168 +#define RGA3_WIN1_ACT_SIZE 0x16c +#define RGA3_WIN1_DST_SIZE 0x170 +#define RGA3_WIN1_SCL_FAC 0x174 +#define RGA3_WIN1_UV_VIR_STRIDE 0x178 +#define RGA3_OVLP_CTRL 0x180 +#define RGA3_OVLP_OFF 0x184 +#define RGA3_OVLP_TOP_KEY_MIN 0x188 +#define RGA3_OVLP_TOP_KEY_MAX 0x18c +#define RGA3_OVLP_TOP_CTRL 0x190 +#define RGA3_OVLP_BOT_CTRL 0x194 +#define RGA3_OVLP_TOP_ALPHA 0x198 +#define RGA3_OVLP_BOT_ALPHA 0x19c +#define RGA3_WR_CTRL 0x1a0 +#define RGA3_WR_FBCE_CTRL 0x1a4 +#define RGA3_WR_VIR_STRIDE 0x1a8 +#define RGA3_WR_PL_VIR_STRIDE 0x1ac +#define RGA3_WR_Y_BASE 0x1b0 +#define RGA3_WR_U_BASE 0x1b4 +#define RGA3_WR_V_BASE 0x1b8 + +/* Registers value */ +#define RGA3_COLOR_FMT_YUV420 0x0 +#define RGA3_COLOR_FMT_YUV422 0x1 +#define RGA3_COLOR_FMT_YUV420_10B 0x2 +#define RGA3_COLOR_FMT_YUV422_10B 0x3 +/* + * Use memory ordering names + * instead of the datasheet naming RGB formats in big endian order + */ +#define RGA3_COLOR_FMT_BGR565 0x4 +#define RGA3_COLOR_FMT_BGR888 0x5 +#define RGA3_COLOR_FMT_FIRST_HAS_ALPHA RGA3_COLOR_FMT_BGRA8888 +#define RGA3_COLOR_FMT_BGRA8888 0x6 +#define RGA3_COLOR_FMT_LAST_OUTPUT RGA3_COLOR_FMT_BGRA8888 +/* the following are only supported as inputs */ +#define RGA3_COLOR_FMT_ABGR8888 0x7 +/* + * the following seem to be unnecessary, + * as they can be achieved with RB swaps + */ +#define RGA3_COLOR_FMT_RGBA8888 0x8 +#define RGA3_COLOR_FMT_ARGB8888 0x9 + +#define RGA3_RDWR_FORMAT_SEMI_PLANAR 0x1 +#define RGA3_RDWR_FORMAT_INTERLEAVED 0x2 + +#define RGA3_CMD_MODE_MASTER 0x1 + +#define RGA3_WIN_CSC_MODE_BT601_F 0x2 + +/* RGA masks */ +/* SYS_CTRL */ +#define RGA3_CCLK_SRESET BIT(4) +#define RGA3_ACLK_SRESET BIT(3) +#define RGA3_CMD_MODE BIT(1) + +/* CMD_CTRL */ +#define RGA3_CMD_LINE_START_PULSE BIT(0) + +/* VERSION_NUM */ +#define RGA3_VERSION_NUM_MAJOR GENMASK(31, 28) +#define RGA3_VERSION_NUM_MINOR GENMASK(27, 20) + +/* INT_* */ +#define RGA3_INT_FRM_DONE BIT(0) +#define RGA3_INT_DMA_READ_BUS_ERR BIT(2) +#define RGA3_INT_WIN0_FBC_DEC_ERR BIT(5) +#define RGA3_INT_WIN0_HOR_ERR BIT(6) +#define RGA3_INT_WIN0_VER_ERR BIT(7) +#define RGA3_INT_WR_VER_ERR BIT(13) +#define RGA3_INT_WR_HOR_ERR BIT(14) +#define RGA3_INT_WR_BUS_ERR BIT(15) +#define RGA3_INT_WIN0_IN_FIFO_WR_ERR BIT(16) +#define RGA3_INT_WIN0_IN_FIFO_RD_ERR BIT(17) +#define RGA3_INT_WIN0_HOR_FIFO_WR_ERR BIT(18) +#define RGA3_INT_WIN0_HOR_FIFO_RD_ERR BIT(19) +#define RGA3_INT_WIN0_VER_FIFO_WR_ERR BIT(20) +#define RGA3_INT_WIN0_VER_FIFO_RD_ERR BIT(21) + +/* RO_SRST */ +#define RGA3_RO_SRST_DONE GENMASK(5, 0) + +/* *_SIZE */ +#define RGA3_HEIGHT GENMASK(28, 16) +#define RGA3_WIDTH GENMASK(12, 0) + +/* SCL_FAC */ +#define RGA3_SCALE_VER_FAC GENMASK(31, 16) +#define RGA3_SCALE_HOR_FAC GENMASK(15, 0) + +/* WINx_CTRL */ +#define RGA3_WIN_CSC_MODE GENMASK(27, 26) +#define RGA3_WIN_R2Y BIT(25) +#define RGA3_WIN_Y2R BIT(24) +#define RGA3_WIN_SCALE_VER_UP BIT(23) +#define RGA3_WIN_SCALE_VER_BYPASS BIT(22) +#define RGA3_WIN_SCALE_HOR_UP BIT(21) +#define RGA3_WIN_SCALE_HOR_BYPASS BIT(20) +#define RGA3_WIN_YC_SWAP BIT(13) +#define RGA3_WIN_RBUV_SWAP BIT(12) +#define RGA3_WIN_RD_FORMAT GENMASK(9, 8) +#define RGA3_WIN_PIC_FORMAT GENMASK(7, 4) +#define RGA3_WIN_ENABLE BIT(0) + +/* COLOR_CTRL */ +#define RGA3_OVLP_GLOBAL_ALPHA GENMASK(23, 16) +#define RGA3_OVLP_COLOR_MODE BIT(0) + +/* ALPHA_CTRL */ +#define RGA3_ALPHA_SELECT_MODE BIT(4) +#define RGA3_ALPHA_BLEND_MODE GENMASK(3, 2) + +/* WR_CTRL */ +#define RGA3_WR_YC_SWAP BIT(20) +#define RGA3_WR_SW_OUTSTANDING_MAX GENMASK(18, 13) +#define RGA3_WR_RBUV_SWAP BIT(12) +#define RGA3_WR_FORMAT GENMASK(9, 8) +#define RGA3_WR_PIC_FORMAT GENMASK(7, 4) + +struct rga3_fmt { + u32 fourcc; + u8 hw_format; + bool rbuv_swap; + bool yc_swap; + bool semi_planar; +}; + +#endif --=20 2.52.0 From nobody Fri Dec 19 20:37:34 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17B2033B976 for ; Wed, 3 Dec 2025 15:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777253; cv=none; b=V/20Z8hrAhJXCmrcHXmmX0oJubFtL0we4DycS5Y+4AYqy6eP2Ms9Ry7XtTSbgXPl0lLEMDS9KcyhsaYLiG0bZB163EEXiHZUmEPj+oXij+5INlbgt7xVOREhk6TV08JqrzGuhU/DTAzsHx+ROdZhsauv68Z4zdf16oIEda9HwV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764777253; c=relaxed/simple; bh=/JWmeTmO5hiwoa9aiMgEtTQMM3FwFfPwkO3+4OKaRK4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JSwdY0RiD9Y0HZWF2oXllxyweylYfk2SSesp0husfFB7fxlEy14UByy9s9VDd1LYiCPwpc19HsShUGesXDMLvFtzPtg/PSGqjjGqm+KuaIHPxcezDrXeqHF/YStCjxR18WAH8vqn1jNZRPIjYxupzhPrGo7iiCLudyQ4VihMbRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vQpAf-0007dW-4Q; Wed, 03 Dec 2025 16:53:37 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Wed, 03 Dec 2025 16:52:44 +0100 Subject: [PATCH v2 22/22] arm64: dts: rockchip: add rga3 dt nodes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251203-spu-rga3-v2-22-989a67947f71@pengutronix.de> References: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> In-Reply-To: <20251203-spu-rga3-v2-0-989a67947f71@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add devicetree nodes for the RGA3 (Raster Graphics Acceleration 3) peripheral in the RK3588. The existing rga node refers to the RGA2 peripheral. The RK3588 contains one RGA2 core and two RGA3 cores. Both feature a similar functionality of scaling, cropping and rotating of up to two input images into one output image. Key differences of the RGA3 are: - supports 10bit YUV output formats - supports 8x8 tiles and FBCD as inputs and outputs - supports BT2020 color space conversion - max output resolution of (8192-64)x(8192-64) - MMU can map up to 32G DDR RAM - fully planar formats (3 planes) are not supported - max scale up/down factor of 8 Signed-off-by: Sven P=C3=BCschel --- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 46 +++++++++++++++++++++++= ++++ 1 file changed, 46 insertions(+) diff --git a/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi b/arch/arm64/boo= t/dts/rockchip/rk3588-base.dtsi index e2500e31c434a..11bad1f41a864 100644 --- a/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +++ b/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi @@ -1273,6 +1273,52 @@ rga: rga@fdb80000 { power-domains =3D <&power RK3588_PD_VDPU>; }; =20 + rga3_core0: rga@fdb60000 { + compatible =3D "rockchip,rk3588-rga3"; + reg =3D <0x0 0xfdb60000 0x0 0x200>; + interrupts =3D ; + interrupt-names =3D "rga3_core0_irq"; + clocks =3D <&cru ACLK_RGA3_0>, <&cru HCLK_RGA3_0>, <&cru CLK_RGA3_0_CORE= >; + clock-names =3D "aclk", "hclk", "sclk"; + resets =3D <&cru SRST_RGA3_0_CORE>, <&cru SRST_A_RGA3_0>, <&cru SRST_H_R= GA3_0>; + reset-names =3D "core", "axi", "ahb"; + power-domains =3D <&power RK3588_PD_RGA30>; + iommus =3D <&rga3_0_mmu>; + }; + + rga3_0_mmu: iommu@fdb60f00 { + compatible =3D "rockchip,rk3588-iommu", "rockchip,rk3568-iommu"; + reg =3D <0x0 0xfdb60f00 0x0 0x100>; + interrupts =3D ; + clocks =3D <&cru ACLK_RGA3_0>, <&cru HCLK_RGA3_0>; + clock-names =3D "aclk", "iface"; + #iommu-cells =3D <0>; + power-domains =3D <&power RK3588_PD_RGA30>; + }; + + rga3_core1: rga@fdb70000 { + compatible =3D "rockchip,rk3588-rga3"; + reg =3D <0x0 0xfdb70000 0x0 0x200>; + interrupts =3D ; + interrupt-names =3D "rga3_core1_irq"; + clocks =3D <&cru ACLK_RGA3_1>, <&cru HCLK_RGA3_1>, <&cru CLK_RGA3_1_CORE= >; + clock-names =3D "aclk", "hclk", "sclk"; + resets =3D <&cru SRST_RGA3_1_CORE>, <&cru SRST_A_RGA3_1>, <&cru SRST_H_R= GA3_1>; + reset-names =3D "core", "axi", "ahb"; + power-domains =3D <&power RK3588_PD_RGA31>; + iommus =3D <&rga3_1_mmu>; + }; + + rga3_1_mmu: iommu@fdb70f00 { + compatible =3D "rockchip,rk3588-iommu", "rockchip,rk3568-iommu"; + reg =3D <0x0 0xfdb70f00 0x0 0x100>; + interrupts =3D ; + clocks =3D <&cru ACLK_RGA3_1>, <&cru HCLK_RGA3_1>; + clock-names =3D "aclk", "iface"; + #iommu-cells =3D <0>; + power-domains =3D <&power RK3588_PD_RGA31>; + }; + vepu121_0: video-codec@fdba0000 { compatible =3D "rockchip,rk3588-vepu121"; reg =3D <0x0 0xfdba0000 0x0 0x800>; --=20 2.52.0