From nobody Mon Jun 8 06:38:19 2026 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 B325140DFC5 for ; Fri, 5 Jun 2026 22:08:33 +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=1780697315; cv=none; b=TI3W7Cm+0ibylvJ5T3W9vkOmsewXUMYvK0P73Qnwx4cGRwDCDJX4Zi+QG5U/2bj+AJzyz5xvPF3rXecgFwdPQ+qVcXpiAdl2SIuzD8VcUxfKHZPeCIqM97dzdhvw1jw6wvTcgvLJGtju6eGZdMT5t9/bY5ntWRxyHNYsXPpWLRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697315; c=relaxed/simple; bh=gBIn6at9O3Wt35zYuxm/cCdj3/DyWLNMazznsspcUNg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TgA7u65mHJVh3uPr0O0f7bevYW6HwzhJ2OnCaH+nC5r6Jj3yEwktIhPT1qaJkelKNdX4/lURa+35l2+rbwXQAAl9KaLj/sB28RDdHCDGWBP2gdu+2M9PSgG9kLdihm+k9J3zNgzegy0QXYBLRb/TUXOq6b5OkUmqRhY0uCyY6gU= 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 1wVchz-0000LW-W1; Sat, 06 Jun 2026 00:08:08 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:47 +0200 Subject: [PATCH 01/17] media: rockchip: rga: zero cmdbuf in shared code 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: <20260606-spu-rga3multicore-v1-1-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 Zero the command buffer (cmdbuf) in the shared code instead of the individual RGA2/RGA3 implementations. Besides centralizing the memset operation this also uses the cmdbuf_size member for the memset size, which is also used as the size for the actual allocation. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 2 -- drivers/media/platform/rockchip/rga/rga.c | 1 + drivers/media/platform/rockchip/rga/rga.h | 3 +++ drivers/media/platform/rockchip/rga/rga3-hw.c | 2 -- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index be1bc8ddbd03b..4d7b0a03820a1 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -443,8 +443,6 @@ static void rga_cmd_set(struct rga_ctx *ctx, =20 static void rga_hw_setup_cmdbuf(struct rga_ctx *ctx) { - memset(ctx->cmdbuf_virt, 0, RGA_CMDBUF_SIZE); - rga_cmd_set_mode(ctx); rga_cmd_set_trans_info(ctx); } diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index b3cb6bf8eb863..bd0afd33affe4 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -41,6 +41,7 @@ static void device_run(void *prv) spin_lock_irqsave(&rga->ctrl_lock, flags); if (ctx->cmdbuf_dirty) { ctx->cmdbuf_dirty =3D false; + memset(ctx->cmdbuf_virt, 0, rga->hw->cmdbuf_size); rga->hw->setup_cmdbuf(ctx); } spin_unlock_irqrestore(&rga->ctrl_lock, flags); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index bd431534d0d39..2b4f5694375a4 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -152,6 +152,9 @@ struct rga_hw { u8 stride_alignment; u8 features; =20 + /* + * Requires that the cmdbuf is already zeroed. + */ void (*setup_cmdbuf)(struct rga_ctx *ctx); void (*start)(struct rockchip_rga *rga, struct rga_vb_buffer *src, struct rga_vb_buffer *dst); diff --git a/drivers/media/platform/rockchip/rga/rga3-hw.c b/drivers/media/= platform/rockchip/rga/rga3-hw.c index ca1c268303dd4..72741e1faccff 100644 --- a/drivers/media/platform/rockchip/rga/rga3-hw.c +++ b/drivers/media/platform/rockchip/rga/rga3-hw.c @@ -261,8 +261,6 @@ static void rga3_cmd_set_wr_format(struct rga_ctx *ctx) =20 static void rga3_hw_setup_cmdbuf(struct rga_ctx *ctx) { - memset(ctx->cmdbuf_virt, 0, RGA3_CMDBUF_SIZE); - rga3_cmd_set_win0_format(ctx); rga3_cmd_set_trans_info(ctx); rga3_cmd_set_wr_format(ctx); --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 DE538390CA9 for ; Fri, 5 Jun 2026 22:08:24 +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=1780697306; cv=none; b=fg4yvkiCxGqgfVIW5Z5P/Tijm6MPZNTq9dguQwe3AjvXoGR+t00UymeUSkohjqFZ/9wSICGynkqDy5FMa3S+j4j4aI18CExmGPlzAuEP9Wedu1v48VmpbBR/Dvx99lgVpLhCwns+MiS6koY+Xm/3Li5Slse7Wu9QqJyF1EoNuZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697306; c=relaxed/simple; bh=bXQht49bvYf9xLyh22jOVZ8etw4Eivx0tPanO1hKY24=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B4aIjQernAAQHR5+8DKBLoqcmw60vXyOB7NWn1+Hsj3ci9PEUi5PagxNLFZVN/hVKHhTp039gHjLJ90QurN55Whm918kZAWHocx66zus2iJFFZo0k0O4ccr8rxmXSqo2K/SJCTxZ1cLwMIA3Qmlqa+lEI5NlgYnMd3oEa28xH9o= 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 1wVci0-0000LW-Uk; Sat, 06 Jun 2026 00:08:09 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:48 +0200 Subject: [PATCH 02/17] media: rockchip: rga: add comment about pixel alignment for YUV formats 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: <20260606-spu-rga3multicore-v1-2-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 comment to clarify the use of fixed step_height values for all YUV formats. While the commit introducing the change already explains the reasoning, add an explicit comment to improve the visibility of the reasoning. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index bd0afd33affe4..efe5541078214 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -414,6 +414,16 @@ static int vidioc_try_fmt(struct file *file, void *pri= v, struct v4l2_format *f) .step_height =3D 1, }; =20 + /* + * Technically 4:2:2 YUV formats don't need a step_height of 2. + * But for the RGA3 this is explicitly documented in section 5.6.3 + * of the RK3588 TRM Part 2. + * And the RGA2 vendor driver also checks that the height (and width) + * is aligned to 2 when a YUV format is used. + * + * Therefore be safe and always align width and height to 2 + * when a YUV format is used. + */ if (v4l2_is_format_yuv(v4l2_format_info(pix_fmt->pixelformat))) { frmsize.step_width =3D 2; frmsize.step_height =3D 2; --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 DE5D53D3309 for ; Fri, 5 Jun 2026 22:08:24 +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=1780697307; cv=none; b=M7DidaVeY2uwOS63qZf0Y21UJdbhyZZbjvz09RbthtnPUVu8CgjTLBN1Ch+VzhWeSJPxqCa0+0IPdyzRJlAfMyOrxyAGiHejLInhZ1k0ClOBUPLHqUIHw054dP1P4u/TYzCSbXKeR9qnSRZiw0H+UV1/7gJJbHS2ubuo+cnh1fE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697307; c=relaxed/simple; bh=gltwkq3brxXYPHfKtonHoQuzbxzFYrFy3iDCOXdvKfs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RAl/APcU1o8RVDlAw++yP8/mMWajOxk78gTsyD5cYm3PSOEDdf+EMXpaYa8xFqZ6NUGGjhQGgD2EFdatf2cme1pNemcxQBax7RcyPs4MS22k0fb7GJyStDCsDugmpoUiy7TBvJLNO+K5X3gnGGDGP91/BnU2j4GbR2allJDkGtQ= 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 1wVci2-0000LW-0f; Sat, 06 Jun 2026 00:08:10 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:49 +0200 Subject: [PATCH 03/17] media: rockchip: rga: move early return into if condition in vidioc_enum_fmt 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: <20260606-spu-rga3multicore-v1-3-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 Instead of a doing an early return when we don't have a capture device, merge the condition with the following if condition. This improves readability, as the condition now explicitly contains a check for a capture device instead of returning when we don't have a capture device. Also use the V4L2_TYPE_IS_CAPTURE helper and improve the comment. The early return if was copied from the vivid drivers vivid_enum_fmt_vid function. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index efe5541078214..8c03422d669cf 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -372,12 +372,14 @@ static int vidioc_enum_fmt(struct file *file, void *p= riv, struct v4l2_fmtdesc *f if (ret !=3D 0) return ret; =20 - if (f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE && - f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) - return 0; - - /* allow changing the quantization and xfer func for YUV formats */ - if (v4l2_is_format_yuv(v4l2_format_info(f->pixelformat))) + /* + * Allow changing the quantization and ycbcr_enc func for YUV formats + * on the capture side for RGB -> YUV conversions. + * + * These flags are only relevant for capture devices. + */ + if (V4L2_TYPE_IS_CAPTURE(f->type) && + v4l2_is_format_yuv(v4l2_format_info(f->pixelformat))) f->flags |=3D V4L2_FMT_FLAG_CSC_QUANTIZATION | V4L2_FMT_FLAG_CSC_YCBCR_ENC; =20 --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 5B8713D45EF for ; Fri, 5 Jun 2026 22:08: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=1780697309; cv=none; b=l6lfuFSjeC2eHGQ52eeMg4vrQ8M9yAxVhc/loY86ls1B4xCm1zgO9EhfYYmg/ipDvtVf3yza1Omw/08JQHPODXiQJBe9Upd3Sop+io1xpZnV3L1XFImW2kZUya+zdtvjaN8ZWLPIALAmlyBoIdYCyB4LaWZM/crd+3dJCL/0lxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697309; c=relaxed/simple; bh=syyEnY9XmmQzLu2TKA1dRzGFRXoui/qqATCvflzhmi8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z2mJZqmNl2ENy4mlqnu6bkzb+fWNaxhuoHC9KkNLypWcRR+9F3grcBpl0AVq+yEEccKTs8IuAzzoFU5qLzz3i+7kWt6cK0naRX6GcWuWAZMWzvLv6yTguKrsB/ygwqOD77X2lQ6MhBbfCvrT42/NWu92tLASlMwlVEhc3QNb+Dw= 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 1wVci3-0000LW-2z; Sat, 06 Jun 2026 00:08:11 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:50 +0200 Subject: [PATCH 04/17] media: rockchip: rga: removed unused regmap member 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: <20260606-spu-rga3multicore-v1-4-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 grf member variable is never accessed or written by the RGA driver. Therefore drop it from the rockchip_rga struct. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 2b4f5694375a4..0e62337f8dd38 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -71,7 +71,6 @@ struct rockchip_rga { struct video_device *vfd; =20 struct device *dev; - struct regmap *grf; void __iomem *regs; struct clk_bulk_data *clks; int num_clks; --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 2AD184183A2 for ; Fri, 5 Jun 2026 22:08:35 +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=1780697316; cv=none; b=XulnKeAU2vDkQqyXlWTzMP8vLbAoMad4Dylv8qV+qPfOAw26VUsc2cHJ2OU7kgUzXcnIxSUw9bcGaCz7pp7lmqLYN8ZKR7BgVnoloSqsq/qu2GHnRwJGO6A3ucThBY2CZajoQqHhWxsH9PXKFu6/gtiBX+OIPQoA9+Mmk57cLZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697316; c=relaxed/simple; bh=k+VeuzoqUVqVnWHcMCJVI9Mw8uHdDe+vIOQrWpAAza8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Yq8U4V9Jw55Ibb+KvS8hQ6E5/GYLXWHskqfqU7iWGlwaxX0UXSxSjLXJ6QWlY6uNM3vN37erITrvA+Y61t28vSJ08hezERhJaaAMH9GT+gSJp0YgeK6eWUWbWtM/S/umJLZSYU423SsB2KAB76Up1IzmIUVwbVd6+6xLrj7374w= 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 1wVci4-0000LW-3e; Sat, 06 Jun 2026 00:08:12 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:51 +0200 Subject: [PATCH 05/17] media: v4l2-mem2mem: support running multiple jobs in parallel 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: <20260606-spu-rga3multicore-v1-5-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 running multiple jobs in parallel for SoCs containing multiple identical devices. An example is the Rockchip RK3588 SoC, which contains two identical RGA3 devices. Therefore it is desirable to have the kernel schedule the work across all available devices and only expose one video device to the userspace. Previously the curr_ctx member of a v4l2_m2m_dev was used to track the currently running context. But the currently running context will always be at the top of the job_queue. As the TRANS_RUNNING flag can be used to check if the queue head is already running, the curr_ctx member can be completely dropped To avoid queueing too many parallel jobs, the v4l2_m2m_set_max_parallel_jobs method is added. It allows a driver to set the number of parallel jobs and avoids calling device_run when the given number of jobs is already running. This is set to 1 by default to prevent parallel job runs. Drivers with the need and support for scheduling jobs can adjust this value accordingly. Note that this change doesn't allow a context to be used multiple times in parallel. So a single stream won't be able to utilize multiple devices at once, but N streams can utilize up to N devices. This is caused by the fact that a context is not added multiple times to the job_list and also holds the job_flags to distinguish if it's currently running. Signed-off-by: Sven P=C3=BCschel --- drivers/media/v4l2-core/v4l2-mem2mem.c | 89 ++++++++++++++++++++++--------= ---- include/media/v4l2-mem2mem.h | 3 ++ 2 files changed, 62 insertions(+), 30 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-co= re/v4l2-mem2mem.c index a65cbb124cfe0..14ac9c85803d1 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -84,16 +84,15 @@ static const char * const m2m_entity_name[] =3D { * v4l2_m2m_unregister_media_controller(). * @intf_devnode: &struct media_intf devnode pointer with the interface * with controls the M2M device. - * @curr_ctx: currently running instance * @job_queue: instances queued to run * @job_spinlock: protects job_queue * @job_work: worker to run queued jobs. * @job_queue_flags: flags of the queue status, %QUEUE_PAUSED. + * @max_parallel_jobs: max job_queue instances number marked as running * @m2m_ops: driver callbacks * @kref: device reference count */ struct v4l2_m2m_dev { - struct v4l2_m2m_ctx *curr_ctx; #ifdef CONFIG_MEDIA_CONTROLLER struct media_entity *source; struct media_pad source_pad; @@ -108,6 +107,7 @@ struct v4l2_m2m_dev { spinlock_t job_spinlock; struct work_struct job_work; unsigned long job_queue_flags; + u32 max_parallel_jobs; =20 const struct v4l2_m2m_ops *m2m_ops; =20 @@ -123,6 +123,12 @@ static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct= v4l2_m2m_ctx *m2m_ctx, return &m2m_ctx->cap_q_ctx; } =20 +void v4l2_m2m_set_max_parallel_jobs(struct v4l2_m2m_dev *m2m_dev, + u32 max_parallel_jobs) +{ + m2m_dev->max_parallel_jobs =3D max_parallel_jobs; +} + struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx, enum v4l2_buf_type type) { @@ -229,14 +235,22 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_buf_remove_by_idx); void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev) { unsigned long flags; - void *ret =3D NULL; + struct v4l2_m2m_ctx *first_ctx; =20 spin_lock_irqsave(&m2m_dev->job_spinlock, flags); - if (m2m_dev->curr_ctx) - ret =3D m2m_dev->curr_ctx->priv; + if (list_empty(&m2m_dev->job_queue)) { + spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); + return NULL; + } + + first_ctx =3D list_first_entry(&m2m_dev->job_queue, + struct v4l2_m2m_ctx, queue); spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); =20 - return ret; + if (first_ctx->job_flags & TRANS_RUNNING) + return first_ctx->priv; + else + return NULL; } EXPORT_SYMBOL(v4l2_m2m_get_curr_priv); =20 @@ -252,13 +266,11 @@ EXPORT_SYMBOL(v4l2_m2m_get_curr_priv); static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m_dev) { unsigned long flags; + struct v4l2_m2m_ctx *ctx; + struct v4l2_m2m_ctx *chosen_ctx =3D NULL; + u32 running_jobs =3D 0; =20 spin_lock_irqsave(&m2m_dev->job_spinlock, flags); - if (NULL !=3D m2m_dev->curr_ctx) { - spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); - dprintk("Another instance is running, won't run now\n"); - return; - } =20 if (list_empty(&m2m_dev->job_queue)) { spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); @@ -272,13 +284,30 @@ static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m= _dev) return; } =20 - m2m_dev->curr_ctx =3D list_first_entry(&m2m_dev->job_queue, - struct v4l2_m2m_ctx, queue); - m2m_dev->curr_ctx->job_flags |=3D TRANS_RUNNING; + list_for_each_entry(ctx, &m2m_dev->job_queue, queue) { + if (!(ctx->job_flags & TRANS_RUNNING)) { + chosen_ctx =3D ctx; + break; + } + + running_jobs++; + } + if (running_jobs >=3D m2m_dev->max_parallel_jobs) { + spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); + dprintk("Maximum number of parallel jobs reached\n"); + return; + } + if (!chosen_ctx) { + spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); + dprintk("All jobs already running\n"); + return; + } + + chosen_ctx->job_flags |=3D TRANS_RUNNING; spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); =20 - dprintk("Running job on m2m_ctx: %p\n", m2m_dev->curr_ctx); - m2m_dev->m2m_ops->device_run(m2m_dev->curr_ctx->priv); + dprintk("Running job on m2m_ctx: %p\n", chosen_ctx); + m2m_dev->m2m_ops->device_run(chosen_ctx->priv); } =20 /* @@ -469,15 +498,14 @@ static void v4l2_m2m_schedule_next_job(struct v4l2_m2= m_dev *m2m_dev, static bool _v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev, struct v4l2_m2m_ctx *m2m_ctx) { - if (!m2m_dev->curr_ctx || m2m_dev->curr_ctx !=3D m2m_ctx) { + if (!m2m_ctx || !(m2m_ctx->job_flags & TRANS_RUNNING)) { dprintk("Called by an instance not currently running\n"); return false; } =20 - list_del(&m2m_dev->curr_ctx->queue); - m2m_dev->curr_ctx->job_flags &=3D ~(TRANS_QUEUED | TRANS_RUNNING); - wake_up(&m2m_dev->curr_ctx->finished); - m2m_dev->curr_ctx =3D NULL; + list_del(&m2m_ctx->queue); + m2m_ctx->job_flags &=3D ~(TRANS_QUEUED | TRANS_RUNNING); + wake_up(&m2m_ctx->finished); return true; } =20 @@ -544,16 +572,19 @@ EXPORT_SYMBOL(v4l2_m2m_buf_done_and_job_finish); void v4l2_m2m_suspend(struct v4l2_m2m_dev *m2m_dev) { unsigned long flags; - struct v4l2_m2m_ctx *curr_ctx; + struct v4l2_m2m_ctx *ctx; + struct v4l2_m2m_ctx *ctx_safe; =20 spin_lock_irqsave(&m2m_dev->job_spinlock, flags); m2m_dev->job_queue_flags |=3D QUEUE_PAUSED; - curr_ctx =3D m2m_dev->curr_ctx; spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); =20 - if (curr_ctx) - wait_event(curr_ctx->finished, - !(curr_ctx->job_flags & TRANS_RUNNING)); + list_for_each_entry_safe(ctx, ctx_safe, &m2m_dev->job_queue, queue) { + if (!(ctx->job_flags & TRANS_RUNNING)) + break; + + wait_event(ctx->finished, !(ctx->job_flags & TRANS_RUNNING)); + } } EXPORT_SYMBOL(v4l2_m2m_suspend); =20 @@ -896,10 +927,8 @@ int v4l2_m2m_streamoff(struct file *file, struct v4l2_= m2m_ctx *m2m_ctx, q_ctx->num_rdy =3D 0; spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags); =20 - if (m2m_dev->curr_ctx =3D=3D m2m_ctx) { - m2m_dev->curr_ctx =3D NULL; + if (m2m_ctx->job_flags & TRANS_RUNNING) wake_up(&m2m_ctx->finished); - } spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job); =20 return 0; @@ -1194,12 +1223,12 @@ struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l= 2_m2m_ops *m2m_ops) if (!m2m_dev) return ERR_PTR(-ENOMEM); =20 - m2m_dev->curr_ctx =3D NULL; m2m_dev->m2m_ops =3D m2m_ops; INIT_LIST_HEAD(&m2m_dev->job_queue); spin_lock_init(&m2m_dev->job_spinlock); INIT_WORK(&m2m_dev->job_work, v4l2_m2m_device_run_work); kref_init(&m2m_dev->kref); + m2m_dev->max_parallel_jobs =3D 1; =20 return m2m_dev; } diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h index 31de25d792b98..e6177d0eaf637 100644 --- a/include/media/v4l2-mem2mem.h +++ b/include/media/v4l2-mem2mem.h @@ -594,6 +594,9 @@ static inline void v4l2_m2m_set_dst_buffered(struct v4l= 2_m2m_ctx *m2m_ctx, m2m_ctx->cap_q_ctx.buffered =3D buffered; } =20 +void v4l2_m2m_set_max_parallel_jobs(struct v4l2_m2m_dev *m2m_dev, + u32 max_parallel_jobs); + /** * v4l2_m2m_ctx_release() - release m2m context * --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 2A71F3D890C for ; Fri, 5 Jun 2026 22:08:49 +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=1780697330; cv=none; b=cJ3vwDCT7z2EWwr5YunNgTp+rOJTOnaWRkAelHJovfEwzlcfnFwhNpJkW1J2xRTszWiNVGaJlH6UeN+DVEb+1Hm1S3RW0rxeSocV3ZxL62w7BZFllWkU+WOonBtqCgl5F5RRCzKKNR9MUfjHu1WCmbUAKD7mTJagDn4aCFXJ+2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697330; c=relaxed/simple; bh=MeB+Hhj4GHnZw4qwxj05LAHj8PlUYMFLq2BrXqIRPXY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QPKGsuVCpVD7hDyc8tpMKkI/fQeKF7ja4Qi6IQnKTL5JPrTPykkpzY7zwTEPNZ4XPmk2bvJNJ/xy4DThYhD4eUK5W24rtIgVUFpq8Tf4JbZCIXrKa56nUqrlldqXGLnu43imqGXOs42OO8WllpcMvJZudyLWC83BI7KlBqnDp9w= 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 1wVci5-0000LW-3d; Sat, 06 Jun 2026 00:08:13 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:52 +0200 Subject: [PATCH 06/17] media: rockchip: rga: move power handling to device_run 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: <20260606-spu-rga3multicore-v1-6-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 power handling to the device_run function in preparation for enabling multiple cores. This allows to power the only the necessary cores instead of powering all available cores. As the decision on which core the given job is executed will be done in device_run, we can only power to correct core there. To avoid unpowering the core in a streaming state switch to autosuspend. This avoids powering down the core when the next frame is scheduled in the next 50ms. The timeout maps to a framerate of 20fps, which should be pretty uncommon in a normal video stream. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 12 ------------ drivers/media/platform/rockchip/rga/rga.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index c0ea6003336bf..3f7c3c68e0cb8 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -242,14 +242,6 @@ static int rga_buf_prepare_streaming(struct vb2_queue = *q) static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count) { struct rga_ctx *ctx =3D vb2_get_drv_priv(q); - struct rockchip_rga *rga =3D ctx->rga; - int ret; - - ret =3D pm_runtime_resume_and_get(rga->dev); - if (ret < 0) { - rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED); - return ret; - } =20 if (V4L2_TYPE_IS_OUTPUT(q->type)) ctx->osequence =3D 0; @@ -261,11 +253,7 @@ static int rga_buf_start_streaming(struct vb2_queue *q= , unsigned int count) =20 static void rga_buf_stop_streaming(struct vb2_queue *q) { - struct rga_ctx *ctx =3D vb2_get_drv_priv(q); - struct rockchip_rga *rga =3D ctx->rga; - rga_buf_return_buffers(q, VB2_BUF_STATE_ERROR); - pm_runtime_put(rga->dev); } =20 const struct vb2_ops rga_qops =3D { diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 8c03422d669cf..0eff558d7f133 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -37,6 +37,14 @@ static void device_run(void *prv) struct rockchip_rga *rga =3D ctx->rga; struct vb2_v4l2_buffer *src, *dst; unsigned long flags; + int ret; + + ret =3D pm_runtime_resume_and_get(rga->dev); + if (ret < 0) { + v4l2_m2m_buf_done_and_job_finish(rga->m2m_dev, ctx->fh.m2m_ctx, + VB2_BUF_STATE_ERROR); + return; + } =20 spin_lock_irqsave(&rga->ctrl_lock, flags); if (ctx->cmdbuf_dirty) { @@ -81,6 +89,8 @@ static irqreturn_t rga_isr(int irq, void *prv) v4l2_m2m_buf_done(src, VB2_BUF_STATE_DONE); v4l2_m2m_buf_done(dst, VB2_BUF_STATE_DONE); v4l2_m2m_job_finish(rga->m2m_dev, ctx->fh.m2m_ctx); + + pm_runtime_put_autosuspend(rga->dev); } =20 return IRQ_HANDLED; @@ -797,6 +807,7 @@ static int rga_probe(struct platform_device *pdev) if (ret) return dev_err_probe(&pdev->dev, ret, "Unable to parse OF data\n"); =20 + pm_runtime_set_autosuspend_delay(rga->dev, 50); pm_runtime_enable(rga->dev); =20 rga->regs =3D devm_platform_ioremap_resource(pdev, 0); --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 7D1FE3D5253 for ; Fri, 5 Jun 2026 22:08:41 +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=1780697322; cv=none; b=LpEUErcrfakA4OxGygl06+qIyoI+5gUM7j/uw2rQPb/7etQSTtGMIVevqWIBNJWP5erPD+2UAhpUoofJjTtTjPXthUdrNggd8pY1aS6hIVmljsugAYy1LBKl2LSZVeUcyxIzSakN9YZSVvyJA9a5gRvTUdKE93Dm3LQH9he9yeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697322; c=relaxed/simple; bh=nXnXuEGMvyXGosVUqwEHGnlF3tbPuC8XpDqtbSxS2Is=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W4JM7p+VgULWpk9wtbAQQgRr9H1nui6+i+0ZdFUO1mX+V2aaNaPAjaIv/QouAdIgR2RBxYr+WMvSzmOYAPFhkozxz9fkiopgiL6SYk+d0l1CRFyxAtYA28MDYwfB/C0Je6BGpFrpns4AXbXEbYZ4qGUbqPhI4WBo+O8aErUsP3U= 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 1wVci6-0000LW-2z; Sat, 06 Jun 2026 00:08:14 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:53 +0200 Subject: [PATCH 07/17] media: rockchip: rga: adjust get_version to return the version 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: <20260606-spu-rga3multicore-v1-7-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 Adjust get_version to return the version instead of directly updating it in the rockchip_rga structure. This is done in preparation for a multi-core support to check that cores with the same compatible share the same version. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 10 +++++++--- drivers/media/platform/rockchip/rga/rga.c | 2 +- drivers/media/platform/rockchip/rga/rga.h | 2 +- drivers/media/platform/rockchip/rga/rga3-hw.c | 8 +++++--- 4 files changed, 14 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 4d7b0a03820a1..190104f3b2954 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -474,10 +474,14 @@ static bool rga_handle_irq(struct rockchip_rga *rga) return intr & RGA_INT_COMMAND_FINISHED; } =20 -static void rga_get_version(struct rockchip_rga *rga) +static struct rockchip_rga_version rga_get_version(struct rockchip_rga *rg= a) { - rga->version.major =3D (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF; - rga->version.minor =3D (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F; + u32 version =3D rga_read(rga, RGA_VERSION_INFO); + + return (struct rockchip_rga_version) { + .major =3D (version >> 24) & 0xFF, + .minor =3D (version >> 20) & 0x0F, + }; } =20 static struct rga_fmt formats[] =3D { diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 0eff558d7f133..b8edd3596c919 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -864,7 +864,7 @@ static int rga_probe(struct platform_device *pdev) if (ret < 0) goto rel_m2m; =20 - rga->hw->get_version(rga); + rga->version =3D rga->hw->get_version(rga); =20 v4l2_info(&rga->v4l2_dev, "HW Version: 0x%02x.%02x\n", rga->version.major, rga->version.minor); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 0e62337f8dd38..0e854cdf739f4 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -158,7 +158,7 @@ struct rga_hw { 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); + struct rockchip_rga_version (*get_version)(struct rockchip_rga *rga); void *(*adjust_and_map_format)(struct rga_ctx *ctx, struct v4l2_pix_format_mplane *format, bool is_output); diff --git a/drivers/media/platform/rockchip/rga/rga3-hw.c b/drivers/media/= platform/rockchip/rga/rga3-hw.c index 72741e1faccff..3469523a5ecad 100644 --- a/drivers/media/platform/rockchip/rga/rga3-hw.c +++ b/drivers/media/platform/rockchip/rga/rga3-hw.c @@ -299,12 +299,14 @@ static bool rga3_handle_irq(struct rockchip_rga *rga) return FIELD_GET(RGA3_INT_FRM_DONE, intr); } =20 -static void rga3_get_version(struct rockchip_rga *rga) +static struct rockchip_rga_version rga3_get_version(struct rockchip_rga *r= ga) { u32 version =3D rga_read(rga, RGA3_VERSION_NUM); =20 - rga->version.major =3D FIELD_GET(RGA3_VERSION_NUM_MAJOR, version); - rga->version.minor =3D FIELD_GET(RGA3_VERSION_NUM_MINOR, version); + return (struct rockchip_rga_version) { + .major =3D FIELD_GET(RGA3_VERSION_NUM_MAJOR, version), + .minor =3D FIELD_GET(RGA3_VERSION_NUM_MINOR, version), + }; } =20 static struct rga3_fmt rga3_formats[] =3D { --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 D58FA40E8F5 for ; Fri, 5 Jun 2026 22:08:33 +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=1780697315; cv=none; b=eeWTQZrt+j+DFSEQvxJh6qzAMQkVwv2bGs4/36bLQstC8birfHhBIpmUvUhwgej4W4ookwj9rIIz0ZJpDZsPX67dtHalPQqr4vh/i+Q94FTAN1ll4adkvsoSfbjO0cdrculT8L8th8/8/Scp0UDPoCmY8zTnw9hB2GP5O09gEXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697315; c=relaxed/simple; bh=SU32LXQJz34n3BITcLFHwxiZbCPnWU2v3CskJfNsuvE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XsfOByG3HFKyEImvvRkYEQeYUxo4EDtjVUEDZJy3DCSYbpA/luWPXGONU0vQWjY0efcpkVpL2iUM3Lv9TJANHPa6ycfdymy+BlF81NGjJRZmAXGWuz3gTs1kxQQd0u1fhtIsYrHDLoAPWqjb8bZCf3yLkOYHvMtX9QWvCWDTncc= 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 1wVci7-0000LW-Cu; Sat, 06 Jun 2026 00:08:15 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:54 +0200 Subject: [PATCH 08/17] media: rockchip: rga: add rga_core structure 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: <20260606-spu-rga3multicore-v1-8-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 rga_core structure to separate the core specific data from the m2m device. This is done in preparation for multi-core support, where multiple identical cores are exposed as a single m2m device to the user-space. Allocation related calls are explicitly done on the first core, as the scheduling decisions will be made on demand after the buffers have been allocated and filled. In preparation of storing the rockchip_rga struct on a dedicated master platform device, the rga_core struct is allocated on it's own and only a pointer is saved in the rockchip_rga struct. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 4 +- drivers/media/platform/rockchip/rga/rga-hw.c | 32 ++++---- drivers/media/platform/rockchip/rga/rga.c | 104 ++++++++++++++--------= ---- drivers/media/platform/rockchip/rga/rga.h | 39 +++++----- drivers/media/platform/rockchip/rga/rga3-hw.c | 24 +++--- 5 files changed, 108 insertions(+), 95 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index 3f7c3c68e0cb8..47a8d5a4500a3 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -93,7 +93,7 @@ static int rga_buf_init(struct vb2_buffer *vb) 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, + rbuf->dma_desc =3D dma_alloc_coherent(rga->cores[0]->dev, rbuf->n_desc * sizeof(*rbuf->dma_desc), &rbuf->dma_desc_pa, GFP_KERNEL); if (!rbuf->dma_desc) @@ -191,7 +191,7 @@ static void rga_buf_cleanup(struct vb2_buffer *vb) if (!rga_has_internal_iommu(rga)) return; =20 - dma_free_coherent(rga->dev, rbuf->n_desc * sizeof(*rbuf->dma_desc), + dma_free_coherent(rga->cores[0]->dev, rbuf->n_desc * sizeof(*rbuf->dma_de= sc), rbuf->dma_desc, rbuf->dma_desc_pa); } =20 diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 190104f3b2954..9a5da4e1716ca 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -417,10 +417,10 @@ static void rga_cmd_set_mode(struct rga_ctx *ctx) dest[(RGA_MODE_CTRL - RGA_MODE_BASE_REG) >> 2] =3D mode.val; } =20 -static void rga_cmd_set(struct rga_ctx *ctx, +static void rga_cmd_set(struct rga_core *core, struct rga_vb_buffer *src, struct rga_vb_buffer *dst) { - struct rockchip_rga *rga =3D ctx->rga; + struct rga_ctx *ctx =3D core->curr; =20 rga_cmd_set_src_addr(ctx, src->dma_desc_pa); /* @@ -434,10 +434,10 @@ static void rga_cmd_set(struct rga_ctx *ctx, 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); + rga_write(core, RGA_CMD_BASE, ctx->cmdbuf_phy); =20 /* sync CMD buf for RGA */ - dma_sync_single_for_device(rga->dev, ctx->cmdbuf_phy, + dma_sync_single_for_device(core->rga->cores[0]->dev, ctx->cmdbuf_phy, PAGE_SIZE, DMA_BIDIRECTIONAL); } =20 @@ -447,36 +447,34 @@ static void rga_hw_setup_cmdbuf(struct rga_ctx *ctx) rga_cmd_set_trans_info(ctx); } =20 -static void rga_hw_start(struct rockchip_rga *rga, +static void rga_hw_start(struct rga_core *core, struct rga_vb_buffer *src, struct rga_vb_buffer *dst) { - struct rga_ctx *ctx =3D rga->curr; - - rga_cmd_set(ctx, src, dst); + rga_cmd_set(core, src, dst); =20 - rga_write(rga, RGA_SYS_CTRL, 0x00); + rga_write(core, RGA_SYS_CTRL, 0x00); =20 - rga_write(rga, RGA_SYS_CTRL, 0x22); + rga_write(core, RGA_SYS_CTRL, 0x22); =20 - rga_write(rga, RGA_INT, 0x600); + rga_write(core, RGA_INT, 0x600); =20 - rga_write(rga, RGA_CMD_CTRL, 0x1); + rga_write(core, RGA_CMD_CTRL, 0x1); } =20 -static bool rga_handle_irq(struct rockchip_rga *rga) +static bool rga_handle_irq(struct rga_core *core) { int intr; =20 - intr =3D rga_read(rga, RGA_INT) & 0xf; + intr =3D rga_read(core, RGA_INT) & 0xf; =20 - rga_mod(rga, RGA_INT, intr << 4, 0xf << 4); + rga_mod(core, RGA_INT, intr << 4, 0xf << 4); =20 return intr & RGA_INT_COMMAND_FINISHED; } =20 -static struct rockchip_rga_version rga_get_version(struct rockchip_rga *rg= a) +static struct rockchip_rga_version rga_get_version(struct rga_core *core) { - u32 version =3D rga_read(rga, RGA_VERSION_INFO); + u32 version =3D rga_read(core, RGA_VERSION_INFO); =20 return (struct rockchip_rga_version) { .major =3D (version >> 24) & 0xFF, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index b8edd3596c919..15d095a1d1973 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -35,11 +36,12 @@ static void device_run(void *prv) { struct rga_ctx *ctx =3D prv; struct rockchip_rga *rga =3D ctx->rga; + struct rga_core *core =3D rga->cores[0]; struct vb2_v4l2_buffer *src, *dst; unsigned long flags; int ret; =20 - ret =3D pm_runtime_resume_and_get(rga->dev); + ret =3D pm_runtime_resume_and_get(core->dev); if (ret < 0) { v4l2_m2m_buf_done_and_job_finish(rga->m2m_dev, ctx->fh.m2m_ctx, VB2_BUF_STATE_ERROR); @@ -54,27 +56,28 @@ static void device_run(void *prv) } spin_unlock_irqrestore(&rga->ctrl_lock, flags); =20 - rga->curr =3D ctx; + core->curr =3D ctx; =20 src =3D v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); src->sequence =3D ctx->osequence++; =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(core, vb_to_rga(src), vb_to_rga(dst)); } =20 static irqreturn_t rga_isr(int irq, void *prv) { - struct rockchip_rga *rga =3D prv; + struct rga_core *core =3D prv; + struct rockchip_rga *rga =3D core->rga; =20 - if (rga->hw->handle_irq(rga)) { + if (rga->hw->handle_irq(core)) { struct vb2_v4l2_buffer *src, *dst; - struct rga_ctx *ctx =3D rga->curr; + struct rga_ctx *ctx =3D core->curr; =20 WARN_ON(!ctx); =20 - rga->curr =3D NULL; + core->curr =3D NULL; =20 src =3D v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); dst =3D v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); @@ -90,7 +93,7 @@ static irqreturn_t rga_isr(int irq, void *prv) v4l2_m2m_buf_done(dst, VB2_BUF_STATE_DONE); v4l2_m2m_job_finish(rga->m2m_dev, ctx->fh.m2m_ctx); =20 - pm_runtime_put_autosuspend(rga->dev); + pm_runtime_put_autosuspend(core->dev); } =20 return IRQ_HANDLED; @@ -118,7 +121,7 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct= vb2_queue *dst_vq) 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; + src_vq->dev =3D ctx->rga->cores[0]->dev; =20 ret =3D vb2_queue_init(src_vq); if (ret) @@ -136,7 +139,7 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct= vb2_queue *dst_vq) 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; + dst_vq->dev =3D ctx->rga->cores[0]->dev; =20 return vb2_queue_init(dst_vq); } @@ -275,7 +278,7 @@ static int rga_open(struct file *file) return -ENOMEM; =20 /* Create CMD buffer */ - ctx->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, rga->hw->cmdbuf_size, + ctx->cmdbuf_virt =3D dma_alloc_attrs(rga->cores[0]->dev, rga->hw->cmdbuf_= size, &ctx->cmdbuf_phy, GFP_KERNEL, DMA_ATTR_WRITE_COMBINE); if (!ctx->cmdbuf_virt) { @@ -322,7 +325,7 @@ static int rga_open(struct file *file) unlock_mutex: mutex_unlock(&rga->mutex); rel_cmdbuf: - dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, ctx->cmdbuf_virt, + dma_free_attrs(rga->cores[0]->dev, rga->hw->cmdbuf_size, ctx->cmdbuf_virt, ctx->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); rel_ctx: kfree(ctx); @@ -342,7 +345,7 @@ static int rga_release(struct file *file) v4l2_fh_del(&ctx->fh, file); v4l2_fh_exit(&ctx->fh); =20 - dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, ctx->cmdbuf_virt, + dma_free_attrs(rga->cores[0]->dev, rga->hw->cmdbuf_size, ctx->cmdbuf_virt, ctx->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); =20 kfree(ctx); @@ -689,26 +692,26 @@ static const struct video_device rga_videodev =3D { .device_caps =3D V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING, }; =20 -static int rga_parse_dt(struct rockchip_rga *rga) +static int rga_parse_dt(struct rga_core *core) { struct reset_control *core_rst, *axi_rst, *ahb_rst; int ret; =20 - core_rst =3D devm_reset_control_get(rga->dev, "core"); + core_rst =3D devm_reset_control_get(core->dev, "core"); if (IS_ERR(core_rst)) { - dev_err(rga->dev, "failed to get core reset controller\n"); + dev_err(core->dev, "failed to get core reset controller\n"); return PTR_ERR(core_rst); } =20 - axi_rst =3D devm_reset_control_get(rga->dev, "axi"); + axi_rst =3D devm_reset_control_get(core->dev, "axi"); if (IS_ERR(axi_rst)) { - dev_err(rga->dev, "failed to get axi reset controller\n"); + dev_err(core->dev, "failed to get axi reset controller\n"); return PTR_ERR(axi_rst); } =20 - ahb_rst =3D devm_reset_control_get(rga->dev, "ahb"); + ahb_rst =3D devm_reset_control_get(core->dev, "ahb"); if (IS_ERR(ahb_rst)) { - dev_err(rga->dev, "failed to get ahb reset controller\n"); + dev_err(core->dev, "failed to get ahb reset controller\n"); return PTR_ERR(ahb_rst); } =20 @@ -724,12 +727,12 @@ static int rga_parse_dt(struct rockchip_rga *rga) udelay(1); reset_control_deassert(ahb_rst); =20 - ret =3D devm_clk_bulk_get_all(rga->dev, &rga->clks); + ret =3D devm_clk_bulk_get_all(core->dev, &core->clks); if (ret < 0) { - dev_err(rga->dev, "failed to get clocks\n"); + dev_err(core->dev, "failed to get clocks\n"); return ret; } - rga->num_clks =3D ret; + core->num_clks =3D ret; =20 return 0; } @@ -780,6 +783,7 @@ static int rga_disable_multicore(struct device *dev) static int rga_probe(struct platform_device *pdev) { struct rockchip_rga *rga; + struct rga_core *core; struct video_device *vfd; int ret =3D 0; int irq; @@ -791,7 +795,7 @@ static int rga_probe(struct platform_device *pdev) if (ret) return ret; =20 - rga =3D devm_kzalloc(&pdev->dev, sizeof(*rga), GFP_KERNEL); + rga =3D devm_kzalloc(&pdev->dev, sizeof(*rga) + 1 * sizeof(*rga->cores), = GFP_KERNEL); if (!rga) return -ENOMEM; =20 @@ -799,20 +803,25 @@ static int rga_probe(struct platform_device *pdev) if (!rga->hw) return dev_err_probe(&pdev->dev, -ENODEV, "failed to get match data\n"); =20 - rga->dev =3D &pdev->dev; spin_lock_init(&rga->ctrl_lock); mutex_init(&rga->mutex); =20 - ret =3D rga_parse_dt(rga); + core =3D devm_kzalloc(&pdev->dev, sizeof(*core), GFP_KERNEL); + core->rga =3D rga; + core->dev =3D &pdev->dev; + + rga->cores[0] =3D core; + + ret =3D rga_parse_dt(core); if (ret) return dev_err_probe(&pdev->dev, ret, "Unable to parse OF data\n"); =20 - pm_runtime_set_autosuspend_delay(rga->dev, 50); - pm_runtime_enable(rga->dev); + pm_runtime_set_autosuspend_delay(core->dev, 50); + pm_runtime_enable(core->dev); =20 - rga->regs =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(rga->regs)) { - ret =3D PTR_ERR(rga->regs); + core->regs =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(core->regs)) { + ret =3D PTR_ERR(core->regs); goto err_put_clk; } =20 @@ -822,17 +831,17 @@ static int rga_probe(struct platform_device *pdev) goto err_put_clk; } =20 - ret =3D devm_request_irq(rga->dev, irq, rga_isr, + ret =3D devm_request_irq(core->dev, irq, rga_isr, rga_has_internal_iommu(rga) ? 0 : IRQF_SHARED, - dev_name(rga->dev), rga); + dev_name(core->dev), core); if (ret < 0) { - dev_err(rga->dev, "failed to request irq\n"); + dev_err(core->dev, "failed to request irq\n"); goto err_put_clk; } =20 - ret =3D dma_set_mask_and_coherent(rga->dev, DMA_BIT_MASK(32)); + ret =3D dma_set_mask_and_coherent(core->dev, DMA_BIT_MASK(32)); if (ret) { - dev_err(rga->dev, "32-bit DMA not supported"); + dev_err(core->dev, "32-bit DMA not supported"); goto err_put_clk; } =20 @@ -852,7 +861,7 @@ static int rga_probe(struct platform_device *pdev) video_set_drvdata(vfd, rga); rga->vfd =3D vfd; =20 - platform_set_drvdata(pdev, rga); + platform_set_drvdata(pdev, core); rga->m2m_dev =3D v4l2_m2m_init(&rga_m2m_ops); if (IS_ERR(rga->m2m_dev)) { v4l2_err(&rga->v4l2_dev, "Failed to init mem2mem device\n"); @@ -860,16 +869,16 @@ static int rga_probe(struct platform_device *pdev) goto rel_vdev; } =20 - ret =3D pm_runtime_resume_and_get(rga->dev); + ret =3D pm_runtime_resume_and_get(core->dev); if (ret < 0) goto rel_m2m; =20 - rga->version =3D rga->hw->get_version(rga); + rga->version =3D rga->hw->get_version(core); =20 v4l2_info(&rga->v4l2_dev, "HW Version: 0x%02x.%02x\n", rga->version.major, rga->version.minor); =20 - pm_runtime_put(rga->dev); + pm_runtime_put(core->dev); =20 ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { @@ -889,14 +898,15 @@ static int rga_probe(struct platform_device *pdev) unreg_v4l2_dev: v4l2_device_unregister(&rga->v4l2_dev); err_put_clk: - pm_runtime_disable(rga->dev); + pm_runtime_disable(core->dev); =20 return ret; } =20 static void rga_remove(struct platform_device *pdev) { - struct rockchip_rga *rga =3D platform_get_drvdata(pdev); + struct rga_core *core =3D platform_get_drvdata(pdev); + struct rockchip_rga *rga =3D core->rga; =20 v4l2_info(&rga->v4l2_dev, "Removing\n"); =20 @@ -904,23 +914,23 @@ static void rga_remove(struct platform_device *pdev) video_unregister_device(rga->vfd); v4l2_device_unregister(&rga->v4l2_dev); =20 - pm_runtime_disable(rga->dev); + pm_runtime_disable(core->dev); } =20 static int __maybe_unused rga_runtime_suspend(struct device *dev) { - struct rockchip_rga *rga =3D dev_get_drvdata(dev); + struct rga_core *core =3D dev_get_drvdata(dev); =20 - clk_bulk_disable_unprepare(rga->num_clks, rga->clks); + clk_bulk_disable_unprepare(core->num_clks, core->clks); =20 return 0; } =20 static int __maybe_unused rga_runtime_resume(struct device *dev) { - struct rockchip_rga *rga =3D dev_get_drvdata(dev); + struct rga_core *core =3D dev_get_drvdata(dev); =20 - return clk_bulk_prepare_enable(rga->num_clks, rga->clks); + return clk_bulk_prepare_enable(core->num_clks, core->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 0e854cdf739f4..fcf1ef7d2029f 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -14,7 +14,6 @@ #include =20 #define RGA_NAME "rockchip-rga" - #define DEFAULT_WIDTH 100 #define DEFAULT_HEIGHT 100 =20 @@ -36,6 +35,16 @@ struct rockchip_rga_version { u32 minor; }; =20 +struct rga_core { + struct device *dev; + void __iomem *regs; + struct clk_bulk_data *clks; + int num_clks; + + struct rockchip_rga *rga; + struct rga_ctx *curr; +}; + struct rga_ctx { struct v4l2_fh fh; struct rockchip_rga *rga; @@ -70,10 +79,6 @@ struct rockchip_rga { struct v4l2_m2m_dev *m2m_dev; struct video_device *vfd; =20 - struct device *dev; - void __iomem *regs; - struct clk_bulk_data *clks; - int num_clks; struct rockchip_rga_version version; =20 /* vfd lock */ @@ -81,9 +86,9 @@ struct rockchip_rga { /* ctrl parm lock */ spinlock_t ctrl_lock; =20 - struct rga_ctx *curr; - const struct rga_hw *hw; + + struct rga_core *cores[]; }; =20 struct rga_addrs { @@ -119,22 +124,22 @@ int rga_check_scaling(const struct rga_hw *hw, const = struct v4l2_rect *crop_in, extern const struct vb2_ops rga_qops; =20 /* RGA Hardware */ -static inline void rga_write(struct rockchip_rga *rga, u32 reg, u32 value) +static inline void rga_write(struct rga_core *core, u32 reg, u32 value) { - writel(value, rga->regs + reg); + writel(value, core->regs + reg); }; =20 -static inline u32 rga_read(struct rockchip_rga *rga, u32 reg) +static inline u32 rga_read(struct rga_core *core, u32 reg) { - return readl(rga->regs + reg); + return readl(core->regs + reg); }; =20 -static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32= mask) +static inline void rga_mod(struct rga_core *core, u32 reg, u32 val, u32 ma= sk) { - u32 temp =3D rga_read(rga, reg) & ~(mask); + u32 temp =3D rga_read(core, reg) & ~(mask); =20 temp |=3D val & mask; - rga_write(rga, reg, temp); + rga_write(core, reg, temp); }; =20 #define RGA_FEATURE_FLIP BIT(0) @@ -155,10 +160,10 @@ struct rga_hw { * Requires that the cmdbuf is already zeroed. */ void (*setup_cmdbuf)(struct rga_ctx *ctx); - void (*start)(struct rockchip_rga *rga, + void (*start)(struct rga_core *core, struct rga_vb_buffer *src, struct rga_vb_buffer *dst); - bool (*handle_irq)(struct rockchip_rga *rga); - struct rockchip_rga_version (*get_version)(struct rockchip_rga *rga); + bool (*handle_irq)(struct rga_core *core); + struct rockchip_rga_version (*get_version)(struct rga_core *core); void *(*adjust_and_map_format)(struct rga_ctx *ctx, struct v4l2_pix_format_mplane *format, bool is_output); diff --git a/drivers/media/platform/rockchip/rga/rga3-hw.c b/drivers/media/= platform/rockchip/rga/rga3-hw.c index 3469523a5ecad..f7e4bc8c6ff21 100644 --- a/drivers/media/platform/rockchip/rga/rga3-hw.c +++ b/drivers/media/platform/rockchip/rga/rga3-hw.c @@ -266,42 +266,42 @@ static void rga3_hw_setup_cmdbuf(struct rga_ctx *ctx) rga3_cmd_set_wr_format(ctx); } =20 -static void rga3_hw_start(struct rockchip_rga *rga, +static void rga3_hw_start(struct rga_core *core, struct rga_vb_buffer *src, struct rga_vb_buffer *dst) { - struct rga_ctx *ctx =3D rga->curr; + struct rga_ctx *ctx =3D core->curr; =20 rga3_cmd_set_win0_addr(ctx, &src->dma_addrs); rga3_cmd_set_wr_addr(ctx, &dst->dma_addrs); =20 - rga_write(rga, RGA3_CMD_ADDR, ctx->cmdbuf_phy); + rga_write(core, RGA3_CMD_ADDR, ctx->cmdbuf_phy); =20 /* sync CMD buf for RGA */ - dma_sync_single_for_device(rga->dev, ctx->cmdbuf_phy, + dma_sync_single_for_device(core->rga->cores[0]->dev, ctx->cmdbuf_phy, PAGE_SIZE, DMA_BIDIRECTIONAL); =20 /* set to master mode and start the conversion */ - rga_write(rga, RGA3_SYS_CTRL, + rga_write(core, 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, + rga_write(core, RGA3_INT_EN, FIELD_PREP(RGA3_INT_FRM_DONE, 1)); + rga_write(core, RGA3_CMD_CTRL, FIELD_PREP(RGA3_CMD_LINE_START_PULSE, 1)); } =20 -static bool rga3_handle_irq(struct rockchip_rga *rga) +static bool rga3_handle_irq(struct rga_core *core) { u32 intr; =20 - intr =3D rga_read(rga, RGA3_INT_RAW); + intr =3D rga_read(core, RGA3_INT_RAW); /* clear all interrupts */ - rga_write(rga, RGA3_INT_CLR, intr); + rga_write(core, RGA3_INT_CLR, intr); =20 return FIELD_GET(RGA3_INT_FRM_DONE, intr); } =20 -static struct rockchip_rga_version rga3_get_version(struct rockchip_rga *r= ga) +static struct rockchip_rga_version rga3_get_version(struct rga_core *core) { - u32 version =3D rga_read(rga, RGA3_VERSION_NUM); + u32 version =3D rga_read(core, RGA3_VERSION_NUM); =20 return (struct rockchip_rga_version) { .major =3D FIELD_GET(RGA3_VERSION_NUM_MAJOR, version), --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 31E1B3D7D65 for ; Fri, 5 Jun 2026 22:08:29 +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=1780697311; cv=none; b=gKpZK+vb7aM5YfmbM5V1xvNGl1h1RD4/Nzi/EkzrXKfe+Rcb3HefPH/154Tn5GswtZ9NTxolJV02lcSjHrbUf7Ng+V8Vqt2KKEl0nOpP7M+6UbX6/fX48w+Tryif40zwiFqqJtkSlDgET7OxuJVs5NKtiEe8EcrYtE2IkyINP1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697311; c=relaxed/simple; bh=SIEys4+eownKsgBmW53TpZ11fhPms2+OoEtZzVfVLKo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QjL4LE2pAYi7Jw6ZaIePACLcv8htxVJFrx3fdHxTABqG4fdbcS5RQpIa5eBloE/abCNHBtgJJ8+ylaayHDEXCY7wQbA7aDomPTf8mfReylrEX5xi9H4EaUv9bY6Ve7s1xNUo1LSAFjvBelRlRu8gMr6baKPATTU/+8l/ZoKNzuQ= 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 1wVci8-0000LW-Ed; Sat, 06 Jun 2026 00:08:16 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:55 +0200 Subject: [PATCH 09/17] media: rockchip: rga: use components to manage multiple cores 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: <20260606-spu-rga3multicore-v1-9-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 component helpers to manage multiple cores and aggregate them into a central master device. This gives us a dedicated master device and ensures that all cores (components) are properly set up before creating the video device. This commit only sets up a basic component device. Instead of the rga_disable_multicore function only the first core is added to the master device. To avoid the secondary core creating an additional video device the whole core probe implementation is moved to the bind method, which is only called when the core is bound to a master device. The implementation is based on the etnaviv gpu driver, which also groups multiple gpu cores under a single etnaviv master device. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 256 +++++++++++++++++++++++---= ---- 1 file changed, 202 insertions(+), 54 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 15d095a1d1973..178f45b8da940 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -5,6 +5,7 @@ */ =20 #include +#include #include #include #include @@ -737,51 +738,9 @@ static int rga_parse_dt(struct rga_core *core) return 0; } =20 -/* - * Some SoCs, like RK3588 have multiple identical RGA3 cores, but the - * kernel is currently missing support for multi-core handling. Exposing - * separate devices for each core to userspace is bad, since that does - * not allow scheduling tasks properly (and creates ABI). With this workar= ound - * the driver will only probe for the first core and early exit for the ot= her - * cores. Once the driver gains multi-core support, the same technique - * for detecting the main core can be used to cluster all cores together. - */ -static int rga_disable_multicore(struct device *dev) -{ - struct device_node *node =3D NULL; - const char *compatible; - bool is_main_core; - int ret; - - /* Intentionally ignores the fallback strings */ - ret =3D of_property_read_string(dev->of_node, "compatible", &compatible); - if (ret) - return ret; - - /* The first compatible and available node found is considered the main c= ore */ - do { - node =3D of_find_compatible_node(node, NULL, compatible); - if (of_device_is_available(node)) - break; - } while (node); - - if (!node) - return -EINVAL; - - is_main_core =3D (dev->of_node =3D=3D node); - - of_node_put(node); - - if (!is_main_core) { - dev_info(dev, "missing multi-core support, ignoring this instance\n"); - return -ENODEV; - } - - return 0; -} - -static int rga_probe(struct platform_device *pdev) +static int rga_core_bind(struct device *dev, struct device *master, void *= data) { + struct platform_device *pdev =3D to_platform_device(dev); struct rockchip_rga *rga; struct rga_core *core; struct video_device *vfd; @@ -791,10 +750,6 @@ 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) + 1 * sizeof(*rga->cores), = GFP_KERNEL); if (!rga) return -ENOMEM; @@ -903,9 +858,10 @@ static int rga_probe(struct platform_device *pdev) return ret; } =20 -static void rga_remove(struct platform_device *pdev) +static void rga_core_unbind(struct device *dev, struct device *master, + void *data) { - struct rga_core *core =3D platform_get_drvdata(pdev); + struct rga_core *core =3D dev_get_drvdata(dev); struct rockchip_rga *rga =3D core->rga; =20 v4l2_info(&rga->v4l2_dev, "Removing\n"); @@ -917,6 +873,29 @@ static void rga_remove(struct platform_device *pdev) pm_runtime_disable(core->dev); } =20 +static const struct component_ops rga_core_ops =3D { + .bind =3D rga_core_bind, + .unbind =3D rga_core_unbind, +}; + +static int rga_core_probe(struct platform_device *pdev) +{ + int ret =3D 0; + + ret =3D component_add(&pdev->dev, &rga_core_ops); + if (ret < 0) { + dev_err(&pdev->dev, "failed to register component: %d", ret); + return ret; + } + + return 0; +} + +static void rga_core_remove(struct platform_device *pdev) +{ + component_del(&pdev->dev, &rga_core_ops); +} + static int __maybe_unused rga_runtime_suspend(struct device *dev) { struct rga_core *core =3D dev_get_drvdata(dev); @@ -933,7 +912,7 @@ static int __maybe_unused rga_runtime_resume(struct dev= ice *dev) return clk_bulk_prepare_enable(core->num_clks, core->clks); } =20 -static const struct dev_pm_ops rga_pm =3D { +static const struct dev_pm_ops rga_core_pm =3D { SET_RUNTIME_PM_OPS(rga_runtime_suspend, rga_runtime_resume, NULL) }; @@ -956,17 +935,186 @@ static const struct of_device_id rockchip_rga_match[= ] =3D { =20 MODULE_DEVICE_TABLE(of, rockchip_rga_match); =20 +static struct platform_driver rga_core_pdrv =3D { + .probe =3D rga_core_probe, + .remove =3D rga_core_remove, + .driver =3D { + .name =3D RGA_NAME "-core", + .pm =3D &rga_core_pm, + .of_match_table =3D rockchip_rga_match, + }, +}; + +static int rga_bind(struct device *dev) +{ + int ret; + + ret =3D component_bind_all(dev, NULL); + if (ret) { + dev_err(dev, "component bind failed\n"); + return ret; + } + + return 0; +} + +static void rga_unbind(struct device *dev) +{ + component_unbind_all(dev, NULL); +} + +struct component_master_ops rga_master_ops =3D { + .bind =3D rga_bind, + .unbind =3D rga_unbind, +}; + +static int rga_probe(struct platform_device *pdev) +{ + const struct of_device_id *match_desc =3D pdev->dev.platform_data; + struct device *dev =3D &pdev->dev; + struct component_match *match =3D NULL; + struct device_node *core_node; + + if (!match_desc) + return dev_err_probe(dev, -ENODEV, "missing platform data\n"); + + for_each_compatible_node(core_node, NULL, match_desc->compatible) { + if (!of_device_is_available(core_node)) + continue; + + of_node_get(core_node); + component_match_add_release(dev, &match, component_release_of, + component_compare_of, core_node); + + /* + * As multi core is not implemented yet, + * break out of the loop to only have one core per rockchip_rga struct. + * Also put the node, which otherwise would've been done by the loop ite= ration. + */ + of_node_put(core_node); + break; + } + + if (!match) + return dev_err_probe( + dev, -ENODEV, + "no matching available component devices found\n"); + + return component_master_add_with_match(dev, &rga_master_ops, match); +} + +static void rga_remove(struct platform_device *pdev) +{ + component_master_del(&pdev->dev, &rga_master_ops); +} + static struct platform_driver rga_pdrv =3D { .probe =3D rga_probe, .remove =3D rga_remove, .driver =3D { .name =3D RGA_NAME, - .pm =3D &rga_pm, - .of_match_table =3D rockchip_rga_match, }, }; =20 -module_platform_driver(rga_pdrv); +static bool rga_of_has_available_node(const char *compat) +{ + struct device_node *node; + + for_each_compatible_node(node, NULL, compat) { + if (of_device_is_available(node)) { + of_node_put(node); + return true; + } + } + + return false; +} + +static int rga_create_platform_device(struct platform_device **ppdev, + const struct of_device_id *match) +{ + struct platform_device *pdev; + int ret; + + pdev =3D platform_device_alloc(match->compatible, PLATFORM_DEVID_NONE); + if (!pdev) + return -ENOMEM; + + ret =3D platform_device_add_data(pdev, match, sizeof(*match)); + if (ret) + goto free_platform_device; + + ret =3D platform_device_add(pdev); + if (ret) + goto free_platform_device; + + ret =3D device_driver_attach(&rga_pdrv.driver, &pdev->dev); + if (ret) + goto del_platform_device; + + *ppdev =3D pdev; + + return 0; + +del_platform_device: + platform_device_del(pdev); +free_platform_device: + platform_device_put(pdev); + return ret; +} + +static struct platform_device *master_pdevs[ARRAY_SIZE(rockchip_rga_match)= - 1]; + +static int __init rga_init(void) +{ + int ret; + unsigned int i; + + ret =3D platform_driver_register(&rga_core_pdrv); + if (ret !=3D 0) + return ret; + + ret =3D platform_driver_register(&rga_pdrv); + if (ret !=3D 0) + goto unregister_core_driver; + + for (i =3D 0; i < ARRAY_SIZE(master_pdevs); i++) { + if (!rga_of_has_available_node( + rockchip_rga_match[i].compatible)) + continue; + + ret =3D rga_create_platform_device(&master_pdevs[i], + &rockchip_rga_match[i]); + if (ret) + goto unregister_platform_devices; + } + + return 0; + +unregister_platform_devices: + for (i =3D 0; i < ARRAY_SIZE(master_pdevs); i++) { + platform_device_unregister(master_pdevs[i]); + master_pdevs[i] =3D NULL; + } + platform_driver_unregister(&rga_pdrv); +unregister_core_driver: + platform_driver_unregister(&rga_core_pdrv); + return ret; +} +module_init(rga_init); + +static void __exit rga_exit(void) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(master_pdevs); i++) { + platform_device_unregister(master_pdevs[i]); + master_pdevs[i] =3D NULL; + } + platform_driver_unregister(&rga_pdrv); + platform_driver_unregister(&rga_core_pdrv); +} +module_exit(rga_exit); =20 MODULE_AUTHOR("Jacob Chen "); MODULE_DESCRIPTION("Rockchip Raster 2d Graphic Acceleration Unit"); --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 814AF4657FE for ; Fri, 5 Jun 2026 22:08:39 +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=1780697320; cv=none; b=kVIfOuI7+Wr4orU9igxG7nzcn5nEIe7yalk4Fl1XxvDiy6jjl2PIn3ME3iI2uF/wJphaez3DVkepXnWNV3Zc+71CwZ9hGLvgnO3LMOvEvLrnDK2Rtqw8vWL2ho0LQP85arEWfz1xy81+D7M8vJl4mGoyNHBEfEJVVySysfjzcDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697320; c=relaxed/simple; bh=916SlS7hxt/WUsc+c1C0gXblrc3pxUP/yNEdXxo1EC4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZM2b4plEvUPc6eodbmytNjA9BYrP5tymcU8hQsXETtS9MWBY3wWMA8pKVu/wAA8XXgmzf2nsXGvERWibj8Vznplrq4rO4p0vSj4P37C8T/0basDPJBSCMFL4cYV+O1kX+YImufs5spuxEKmJa8pP573Ru9vLtuO9SSsP4RorCus= 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 1wVci9-0000LW-EE; Sat, 06 Jun 2026 00:08:17 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:56 +0200 Subject: [PATCH 10/17] media: rockchip: rga: move rockchip_rga allocation to master probe 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: <20260606-spu-rga3multicore-v1-10-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 rockchip_rga struct allocation to the master component probe function in preparation of enabling all cores. This also adjusts the allocation to use the actual number of cores found in the of tree instead of being fixed to one core. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 32 ++++++++++++++++++---------= ---- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 178f45b8da940..11912bf5b6906 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -741,7 +741,7 @@ static int rga_parse_dt(struct rga_core *core) static int rga_core_bind(struct device *dev, struct device *master, void *= data) { struct platform_device *pdev =3D to_platform_device(dev); - struct rockchip_rga *rga; + struct rockchip_rga *rga =3D data; struct rga_core *core; struct video_device *vfd; int ret =3D 0; @@ -750,17 +750,6 @@ static int rga_core_bind(struct device *dev, struct de= vice *master, void *data) if (!pdev->dev.of_node) return -ENODEV; =20 - rga =3D devm_kzalloc(&pdev->dev, sizeof(*rga) + 1 * sizeof(*rga->cores), = GFP_KERNEL); - if (!rga) - return -ENOMEM; - - 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"); - - spin_lock_init(&rga->ctrl_lock); - mutex_init(&rga->mutex); - core =3D devm_kzalloc(&pdev->dev, sizeof(*core), GFP_KERNEL); core->rga =3D rga; core->dev =3D &pdev->dev; @@ -947,9 +936,10 @@ static struct platform_driver rga_core_pdrv =3D { =20 static int rga_bind(struct device *dev) { + struct rockchip_rga *rga =3D dev_get_drvdata(dev); int ret; =20 - ret =3D component_bind_all(dev, NULL); + ret =3D component_bind_all(dev, rga); if (ret) { dev_err(dev, "component bind failed\n"); return ret; @@ -974,6 +964,8 @@ static int rga_probe(struct platform_device *pdev) struct device *dev =3D &pdev->dev; struct component_match *match =3D NULL; struct device_node *core_node; + struct rockchip_rga *rga; + u8 num_cores =3D 0; =20 if (!match_desc) return dev_err_probe(dev, -ENODEV, "missing platform data\n"); @@ -985,6 +977,7 @@ static int rga_probe(struct platform_device *pdev) of_node_get(core_node); component_match_add_release(dev, &match, component_release_of, component_compare_of, core_node); + num_cores++; =20 /* * As multi core is not implemented yet, @@ -1000,6 +993,19 @@ static int rga_probe(struct platform_device *pdev) dev, -ENODEV, "no matching available component devices found\n"); =20 + rga =3D devm_kzalloc(dev, sizeof(*rga) + num_cores * sizeof(*rga->cores),= GFP_KERNEL); + if (!rga) + return -ENOMEM; + + rga->hw =3D match_desc->data; + if (!rga->hw) + return dev_err_probe(dev, -ENODEV, "failed to get match data\n"); + + spin_lock_init(&rga->ctrl_lock); + mutex_init(&rga->mutex); + + dev_set_drvdata(dev, rga); + return component_master_add_with_match(dev, &rga_master_ops, match); } =20 --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 717923D333B for ; Fri, 5 Jun 2026 22:08:26 +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=1780697307; cv=none; b=EFN1U2kRcq+7XdxHBaYRk48raF1wM4cf3Snk5tHbAwg0KpbX4npFb3kItq1eioWSGq1245mrN5++UZ9isgZISWMC5fMbL3GFgtl+urUxj5rBPahEXcbH97XYyTxlR6potv4Vwtal+ljiCsVYI30vrs9N/8dB9LkNuD7AT5uzKjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697307; c=relaxed/simple; bh=XwN3H/WKKx/hGJtxMoOnjRz+1bUtNM/m1v1dgCK0DMM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E8nuCgConHTda+28OUb4YS8HVf0Ww4Pr9jZN0SZoR/acz6tb9mMLh6eIPPDQGuy4IhxoLfBxbgA/XvJHqQMaPEoIxe7AY/qlxiCDU7KtBqYC2SighvuH2ltM0UPOUug/Nb/Wg69aWKkUVqYtMARgeitXD65tJu0bHccJXqF6Iz8= 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 1wVciA-0000LW-Cf; Sat, 06 Jun 2026 00:08:18 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:57 +0200 Subject: [PATCH 11/17] media: rockchip: rga: move video device to the master 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: <20260606-spu-rga3multicore-v1-11-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 video device allocation and registration to the master component bind function in preparation for binding multiple cores to the master. Moving it to the master bind function allows to only register the v4l2 device when all cores have been successfully bound to the master device. This also causes the video device to be bound against the master platform device instead of a specific core. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 96 ++++++++++++++++-----------= ---- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 11912bf5b6906..952377ae467f5 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -743,7 +743,6 @@ static int rga_core_bind(struct device *dev, struct dev= ice *master, void *data) struct platform_device *pdev =3D to_platform_device(dev); struct rockchip_rga *rga =3D data; struct rga_core *core; - struct video_device *vfd; int ret =3D 0; int irq; =20 @@ -789,33 +788,11 @@ static int rga_core_bind(struct device *dev, struct d= evice *master, void *data) goto err_put_clk; } =20 - ret =3D v4l2_device_register(&pdev->dev, &rga->v4l2_dev); - if (ret) - goto err_put_clk; - vfd =3D video_device_alloc(); - if (!vfd) { - v4l2_err(&rga->v4l2_dev, "Failed to allocate video device\n"); - ret =3D -ENOMEM; - goto unreg_v4l2_dev; - } - *vfd =3D rga_videodev; - vfd->lock =3D &rga->mutex; - vfd->v4l2_dev =3D &rga->v4l2_dev; - - video_set_drvdata(vfd, rga); - rga->vfd =3D vfd; - platform_set_drvdata(pdev, core); - rga->m2m_dev =3D v4l2_m2m_init(&rga_m2m_ops); - if (IS_ERR(rga->m2m_dev)) { - v4l2_err(&rga->v4l2_dev, "Failed to init mem2mem device\n"); - ret =3D PTR_ERR(rga->m2m_dev); - goto rel_vdev; - } =20 ret =3D pm_runtime_resume_and_get(core->dev); if (ret < 0) - goto rel_m2m; + goto err_put_clk; =20 rga->version =3D rga->hw->get_version(core); =20 @@ -824,23 +801,8 @@ static int rga_core_bind(struct device *dev, struct de= vice *master, void *data) =20 pm_runtime_put(core->dev); =20 - ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); - if (ret) { - v4l2_err(&rga->v4l2_dev, "Failed to register video device\n"); - goto rel_m2m; - } - - v4l2_info(&rga->v4l2_dev, "Registered %s as /dev/%s\n", - vfd->name, video_device_node_name(vfd)); - return 0; =20 -rel_m2m: - v4l2_m2m_release(rga->m2m_dev); -rel_vdev: - video_device_release(vfd); -unreg_v4l2_dev: - v4l2_device_unregister(&rga->v4l2_dev); err_put_clk: pm_runtime_disable(core->dev); =20 @@ -851,13 +813,6 @@ static void rga_core_unbind(struct device *dev, struct= device *master, void *data) { struct rga_core *core =3D dev_get_drvdata(dev); - struct rockchip_rga *rga =3D core->rga; - - v4l2_info(&rga->v4l2_dev, "Removing\n"); - - v4l2_m2m_release(rga->m2m_dev); - video_unregister_device(rga->vfd); - v4l2_device_unregister(&rga->v4l2_dev); =20 pm_runtime_disable(core->dev); } @@ -937,6 +892,7 @@ static struct platform_driver rga_core_pdrv =3D { static int rga_bind(struct device *dev) { struct rockchip_rga *rga =3D dev_get_drvdata(dev); + struct video_device *vfd; int ret; =20 ret =3D component_bind_all(dev, rga); @@ -945,11 +901,59 @@ static int rga_bind(struct device *dev) return ret; } =20 + ret =3D v4l2_device_register(dev, &rga->v4l2_dev); + if (ret) + return ret; + vfd =3D video_device_alloc(); + if (!vfd) { + v4l2_err(&rga->v4l2_dev, "Failed to allocate video device\n"); + ret =3D -ENOMEM; + goto unreg_v4l2_dev; + } + *vfd =3D rga_videodev; + vfd->lock =3D &rga->mutex; + vfd->v4l2_dev =3D &rga->v4l2_dev; + + video_set_drvdata(vfd, rga); + rga->vfd =3D vfd; + + rga->m2m_dev =3D v4l2_m2m_init(&rga_m2m_ops); + if (IS_ERR(rga->m2m_dev)) { + v4l2_err(&rga->v4l2_dev, "Failed to init mem2mem device\n"); + ret =3D PTR_ERR(rga->m2m_dev); + goto rel_vdev; + } + + ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); + if (ret) { + v4l2_err(&rga->v4l2_dev, "Failed to register video device\n"); + goto rel_m2m; + } + + v4l2_info(&rga->v4l2_dev, "Registered %s as /dev/%s\n", + vfd->name, video_device_node_name(vfd)); + return 0; + +rel_m2m: + v4l2_m2m_release(rga->m2m_dev); +rel_vdev: + video_device_release(vfd); +unreg_v4l2_dev: + v4l2_device_unregister(&rga->v4l2_dev); + return ret; } =20 static void rga_unbind(struct device *dev) { + struct rockchip_rga *rga =3D dev_get_drvdata(dev); + + v4l2_info(&rga->v4l2_dev, "Removing\n"); + + v4l2_m2m_release(rga->m2m_dev); + video_unregister_device(rga->vfd); + v4l2_device_unregister(&rga->v4l2_dev); + component_unbind_all(dev, NULL); } =20 --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 CA5753D348C for ; Fri, 5 Jun 2026 22:08:26 +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=1780697310; cv=none; b=ErwWxwK4gtyWwJKyOjfSNpJuqmniPG0FtQZtHWPMWzaF321ygCmzwfp4hMWCCSXJ62VrdGM/nzOr051HQCVWCB4yorGhYSMTEKLoSp752HxLZkFwJ0HqUg9wETJQw/DhVhiplHzD4PyffdtNn+ubTdSQ8QDlo9GJrJg4r+vz9QQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697310; c=relaxed/simple; bh=eU0m7fiQeNWxnmH4Hq8GssGuaAxqRHYPTDmZYHnQ4SU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nTBZa6u/vmqU1loCLqk7Xkj/L5ibF3pcmg8kqJDoc4A1KzlmrsH5IIbZ7ZfLFb5Ldhn5+IB3LfZT9Wysq1pSe4CVdSG3KoQyOI/+ee3FA827tiT8bBAeFpy8PuVSWfQELpCYti76O9DDQ0fSRyM6k03ql4oHdAfMZOtaFyhvFwI= 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 1wVciB-0000LW-DK; Sat, 06 Jun 2026 00:08:19 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:58 +0200 Subject: [PATCH 12/17] media: rockchip: rga: move core initialization from bind to probe 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: <20260606-spu-rga3multicore-v1-12-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 core initialization from the core binding function to the core probing function. This better matches the actual sequence, where the core probe initializes most things and the bind function just binds the core to the actual rga struct from the master device. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 83 ++++++++++++++++-----------= ---- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 952377ae467f5..0413b8518dfc8 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -740,21 +740,49 @@ static int rga_parse_dt(struct rga_core *core) =20 static int rga_core_bind(struct device *dev, struct device *master, void *= data) { - struct platform_device *pdev =3D to_platform_device(dev); struct rockchip_rga *rga =3D data; + struct rga_core *core =3D dev_get_drvdata(dev); + int ret =3D 0; + + core->rga =3D rga; + + ret =3D pm_runtime_resume_and_get(core->dev); + if (ret < 0) + return ret; + + rga->version =3D rga->hw->get_version(core); + + v4l2_info(&rga->v4l2_dev, "HW Version: 0x%02x.%02x\n", + rga->version.major, rga->version.minor); + + pm_runtime_put(core->dev); + + rga->cores[0] =3D core; + + return 0; +} + +static const struct component_ops rga_core_ops =3D { + .bind =3D rga_core_bind, +}; + +static int rga_core_probe(struct platform_device *pdev) +{ struct rga_core *core; + const struct rga_hw *hw; int ret =3D 0; int irq; =20 if (!pdev->dev.of_node) return -ENODEV; =20 + hw =3D of_device_get_match_data(&pdev->dev); + if (!hw) + return dev_err_probe(&pdev->dev, -ENODEV, "failed to get match data\n"); + core =3D devm_kzalloc(&pdev->dev, sizeof(*core), GFP_KERNEL); - core->rga =3D rga; core->dev =3D &pdev->dev; =20 - rga->cores[0] =3D core; - ret =3D rga_parse_dt(core); if (ret) return dev_err_probe(&pdev->dev, ret, "Unable to parse OF data\n"); @@ -775,7 +803,7 @@ static int rga_core_bind(struct device *dev, struct dev= ice *master, void *data) } =20 ret =3D devm_request_irq(core->dev, irq, rga_isr, - rga_has_internal_iommu(rga) ? 0 : IRQF_SHARED, + hw->has_internal_iommu ? 0 : IRQF_SHARED, dev_name(core->dev), core); if (ret < 0) { dev_err(core->dev, "failed to request irq\n"); @@ -790,42 +818,6 @@ static int rga_core_bind(struct device *dev, struct de= vice *master, void *data) =20 platform_set_drvdata(pdev, core); =20 - ret =3D pm_runtime_resume_and_get(core->dev); - if (ret < 0) - goto err_put_clk; - - rga->version =3D rga->hw->get_version(core); - - v4l2_info(&rga->v4l2_dev, "HW Version: 0x%02x.%02x\n", - rga->version.major, rga->version.minor); - - pm_runtime_put(core->dev); - - return 0; - -err_put_clk: - pm_runtime_disable(core->dev); - - return ret; -} - -static void rga_core_unbind(struct device *dev, struct device *master, - void *data) -{ - struct rga_core *core =3D dev_get_drvdata(dev); - - pm_runtime_disable(core->dev); -} - -static const struct component_ops rga_core_ops =3D { - .bind =3D rga_core_bind, - .unbind =3D rga_core_unbind, -}; - -static int rga_core_probe(struct platform_device *pdev) -{ - int ret =3D 0; - ret =3D component_add(&pdev->dev, &rga_core_ops); if (ret < 0) { dev_err(&pdev->dev, "failed to register component: %d", ret); @@ -833,11 +825,20 @@ static int rga_core_probe(struct platform_device *pde= v) } =20 return 0; + +err_put_clk: + pm_runtime_disable(core->dev); + + return ret; } =20 static void rga_core_remove(struct platform_device *pdev) { + struct rga_core *core =3D platform_get_drvdata(pdev); + component_del(&pdev->dev, &rga_core_ops); + + pm_runtime_disable(core->dev); } =20 static int __maybe_unused rga_runtime_suspend(struct device *dev) --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 C175F390CA9 for ; Fri, 5 Jun 2026 22:08:27 +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=1780697309; cv=none; b=as8r5fzSc2cg7ek7H6QNdDptIxnrbPJSxUa/sPjD0cWFskluaVzFaG3SYPp3jIio2oPT65u6vU7Rpkk7uaqTZnYpMXqQvBbfT4jsLLfhWXOg8fJnsaqy8z0NbG39EW2R2vTiu3KN577FOAcHnBTw2n4hJ4UWofTSLJKyZ6IY6ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697309; c=relaxed/simple; bh=gJA/HNE8SboWhVfvAKSjBG7JCLIGhqPaqgZuymsJ7Ro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pTdym4jJ9YTLQ9Lg4yFBPMkXknRumRumIRq1B1iLsSm6GU3yt4xkCxRHViEjRqLex/1ua1uTZ25zOuZbFJ0kLS8636CnCURuxHm53+gjFCCaoVcZkz/S1MGWxORdd1szAeRWBOq7EDWQwmi3EvMixeqvjioGDW96M56qpA/xcRU= 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 1wVciC-0000LW-G9; Sat, 06 Jun 2026 00:08:20 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:06:59 +0200 Subject: [PATCH 13/17] media: rockchip: rga: bind all cores to the master 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: <20260606-spu-rga3multicore-v1-13-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 Bind all core components to the master component. Previously only the first core has been added to the master device to avoid creating multiple video devices. As the video device creation has been moved to the master component, it allows us to bind all cores without creating additional video devices. We expect that all cores to report the same version number, as we only add cores with the same compatible value. This is important, as we setup the command buffer before actually scheduling the work to a specific core. Therefore adjusting command buffers depending on the version register only works when all cores have the same value. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 22 +++++++++++----------- drivers/media/platform/rockchip/rga/rga.h | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 0413b8518dfc8..6add6c510c127 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -742,6 +742,7 @@ static int rga_core_bind(struct device *dev, struct dev= ice *master, void *data) { struct rockchip_rga *rga =3D data; struct rga_core *core =3D dev_get_drvdata(dev); + struct rockchip_rga_version version; int ret =3D 0; =20 core->rga =3D rga; @@ -750,14 +751,21 @@ static int rga_core_bind(struct device *dev, struct d= evice *master, void *data) if (ret < 0) return ret; =20 - rga->version =3D rga->hw->get_version(core); + version =3D rga->hw->get_version(core); =20 v4l2_info(&rga->v4l2_dev, "HW Version: 0x%02x.%02x\n", - rga->version.major, rga->version.minor); + version.major, version.minor); + + if (rga->num_cores) { + /* we are not the first core, expect that we have the same version */ + if (rga->version.major !=3D version.major || rga->version.minor !=3D ver= sion.minor) + v4l2_warn(&rga->v4l2_dev, "Detected multi-core setup with different cor= e versions!\n"); + } else + rga->version =3D version; =20 pm_runtime_put(core->dev); =20 - rga->cores[0] =3D core; + rga->cores[rga->num_cores++] =3D core; =20 return 0; } @@ -983,14 +991,6 @@ static int rga_probe(struct platform_device *pdev) component_match_add_release(dev, &match, component_release_of, component_compare_of, core_node); num_cores++; - - /* - * As multi core is not implemented yet, - * break out of the loop to only have one core per rockchip_rga struct. - * Also put the node, which otherwise would've been done by the loop ite= ration. - */ - of_node_put(core_node); - break; } =20 if (!match) diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index fcf1ef7d2029f..6237436b984eb 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -88,6 +88,7 @@ struct rockchip_rga { =20 const struct rga_hw *hw; =20 + u8 num_cores; struct rga_core *cores[]; }; =20 --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 C0CFB3D5C2C for ; Fri, 5 Jun 2026 22:08: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=1780697310; cv=none; b=oJulvJ4GCJ/z/HIdj6luQjYoM4AOGSygZ6hyIUZ5Bx9xpbq8mmMdlkiBS/mnICbu8SX8qV/zJSuqNoKptEQCFIvhiEPVZbWUPznmqnfUh6vFJsv9+fCO0dEKJaPxjEUiwCDjhpQEQVn6MKBndT0BzGrA+05vrxzaLL+h3DEjaBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697310; c=relaxed/simple; bh=3lB6SIc4z983gdFSSBdDF3XCzDGtkT4zgcI9V2ZTIHo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nTonxiHVFgQgGezVGCwcG4jZrZy9JsmOVY6RUJJVJFSFHkuoB+1FpFnLMxoMKiej5ZCrd0UCgVrkLcZ2EPi1tNgtHIhPG/nGAV6IMmbC4Ldg223eq+vc+7ro6psA640zqnIER31CIPuyup2vceTVEW8LQ1tNnHUOU7xhS58m6U0= 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 1wVciD-0000LW-Ii; Sat, 06 Jun 2026 00:08:21 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:07:00 +0200 Subject: [PATCH 14/17] media: rockchip: rga: put all cores into first core iommu domain 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: <20260606-spu-rga3multicore-v1-14-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 Put all cores into the iommu domain of the first core to allow them to be used by any core. All buffers accessed by the hardware are allocated on the first core, as the scheduling to a specific core is done after the allocation. Therefore put all cores into the same domain to have the same iommu mapping on all cores. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 6add6c510c127..9cebb461b3fd2 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -757,6 +758,19 @@ static int rga_core_bind(struct device *dev, struct de= vice *master, void *data) version.major, version.minor); =20 if (rga->num_cores) { + /* Attach to the first cores iommu */ + struct iommu_domain *domain =3D iommu_get_domain_for_dev(rga->cores[0]->= dev); + + if (IS_ERR(domain)) { + dev_err(core->dev, "Couldn't get domain of the first core\n"); + return PTR_ERR(domain); + } + ret =3D iommu_attach_device(domain, core->dev); + if (ret) { + dev_err(core->dev, "Couldn't attach to the domain of the first core\n"); + return ret; + } + /* we are not the first core, expect that we have the same version */ if (rga->version.major !=3D version.major || rga->version.minor !=3D ver= sion.minor) v4l2_warn(&rga->v4l2_dev, "Detected multi-core setup with different cor= e versions!\n"); --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 08F633D45E7 for ; Fri, 5 Jun 2026 22:08:40 +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=1780697322; cv=none; b=lRvkAONSjYTKXuaKVpp5Juaz7ZUJ1BSq2RQDllz7rc5gygCFqNq4QnDjXCaILVLt2QN8vemAoiQh5rJAPAdTuyIi2C2m83DQwlwpn81rUWFiv/YR9CtkhpIRG51D63JRxe1v6cWV9CO/4shN53NeqDgXQ2QCl7Qwe1zpAm7KfKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697322; c=relaxed/simple; bh=aYVEjN1rEfisX14ck7CgX63sQqs4Zlqr8t4WnrE6Qps=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XVIDcee3lnBYxv2BGWw8wf1ymHbwM9UyiHaAkvzgZIyGxF+9SdleUusyNTmOIb6Aj7ZOBQ/U9J6mawtmzt3M+VLMYfbBmvaWBS5CEKAsej56g/nZ9RuD/DNohuDvIO6pVW8TPTHyQ3DdgF6zGAiBP2CB/IlTuVlZXucAj5GVP6U= 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 1wVciE-0000LW-Ht; Sat, 06 Jun 2026 00:08:22 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:07:01 +0200 Subject: [PATCH 15/17] media: rockchip: rga: schedule jobs to multiple cores 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: <20260606-spu-rga3multicore-v1-15-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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 Schedule jobs to multiple cores to utilize all RGA cores. To avoid race conditions when selecting the next free core a dedicated spinlock is added. Note that this doesn't increase the max frame rate of a single stream, as a context will wait for the job to finish before starting the next device_run call. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 22 +++++++++++++++++++--- drivers/media/platform/rockchip/rga/rga.h | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 9cebb461b3fd2..f00b7f99f2521 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -38,15 +38,31 @@ static void device_run(void *prv) { struct rga_ctx *ctx =3D prv; struct rockchip_rga *rga =3D ctx->rga; - struct rga_core *core =3D rga->cores[0]; + struct rga_core *core =3D NULL; struct vb2_v4l2_buffer *src, *dst; unsigned long flags; int ret; + unsigned int i; + + spin_lock_irqsave(&rga->cores_lock, flags); + for (i =3D 0; i < rga->num_cores; i++) { + if (!rga->cores[i]->curr) { + core =3D rga->cores[i]; + core->curr =3D ctx; + break; + } + } + spin_unlock_irqrestore(&rga->cores_lock, flags); + + WARN_ONCE(!core, "No free core although max parallel jobs matches the cor= e count!\n"); + if (!core) + return; =20 ret =3D pm_runtime_resume_and_get(core->dev); if (ret < 0) { v4l2_m2m_buf_done_and_job_finish(rga->m2m_dev, ctx->fh.m2m_ctx, VB2_BUF_STATE_ERROR); + core->curr =3D NULL; return; } =20 @@ -58,8 +74,6 @@ static void device_run(void *prv) } spin_unlock_irqrestore(&rga->ctrl_lock, flags); =20 - core->curr =3D ctx; - src =3D v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); src->sequence =3D ctx->osequence++; =20 @@ -946,6 +960,7 @@ static int rga_bind(struct device *dev) ret =3D PTR_ERR(rga->m2m_dev); goto rel_vdev; } + v4l2_m2m_set_max_parallel_jobs(rga->m2m_dev, rga->num_cores); =20 ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { @@ -1021,6 +1036,7 @@ static int rga_probe(struct platform_device *pdev) return dev_err_probe(dev, -ENODEV, "failed to get match data\n"); =20 spin_lock_init(&rga->ctrl_lock); + spin_lock_init(&rga->cores_lock); mutex_init(&rga->mutex); =20 dev_set_drvdata(dev, rga); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 6237436b984eb..c0dfacdb6f212 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -85,6 +85,7 @@ struct rockchip_rga { struct mutex mutex; /* ctrl parm lock */ spinlock_t ctrl_lock; + spinlock_t cores_lock; =20 const struct rga_hw *hw; =20 --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 77C073D3309 for ; Fri, 5 Jun 2026 22:08:47 +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=1780697328; cv=none; b=cdiX+J4STcvZcVjXIueeVAasyOfJiTi/8OfMLqWShC6QTry8q/DJV6/Lx5tHKQg1lnvZGzK7sRquUB9o9oS7/xWTBiYeLvpK8/nE2BKZt/6NlR/QcPRViT5tJy0VhaLZEYsB9+RvlbgxFPVmP9icUfdMg9er6dX0lI9bwHR745Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697328; c=relaxed/simple; bh=ev79BuHXEJn4h7yl3ozR0VduqDmwYx4f4wrXnbku1xk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ExHZX17TLGBjIyjyRnIgtkVnp0fU9O3RY8TWoabKO5AvObNxnFuHDa9XSI6IoLUfTYdjhoAGNtYEyHji/iJvzzonJHRSPo1B7AH2fNdq+Y9XF15nVVJsi/Jcf2tZOrlv5FVKCcRoBVRMGmDFbV+DhfzkgB24dAHzpyvcFmcbYFs= 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 1wVciF-0000LW-J7; Sat, 06 Jun 2026 00:08:23 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:07:02 +0200 Subject: [PATCH 16/17] arm64: dts: rockchip: add rga3 dt nodes to rk3588 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: <20260606-spu-rga3multicore-v1-16-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.15.2 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-Enhanced peripheral. The RK3588 contains one RGA2-Enhanced 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 (RGA2 allows up to 16) Signed-off-by: Sven P=C3=BCschel Link: https://patch.msgid.link/20260521-spu-rga3-v7-28-3f33e8c7145f@pengutr= onix.de Signed-off-by: Heiko Stuebner --- (cherry picked from commit 25ee898961a2c661e4cd72bc98f0060f1cd11222) picked from linux-next to have the necessary RGA3 nodes available. --- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 44 +++++++++++++++++++++++= ++++ 1 file changed, 44 insertions(+) diff --git a/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi b/arch/arm64/boo= t/dts/rockchip/rk3588-base.dtsi index 4fb8888c281c8..a4f44af512375 100644 --- a/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +++ b/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi @@ -1262,6 +1262,50 @@ vpu121_mmu: iommu@fdb50800 { #iommu-cells =3D <0>; }; =20 + rga3_core0: rga@fdb60000 { + compatible =3D "rockchip,rk3588-rga3"; + reg =3D <0x0 0xfdb60000 0x0 0x200>; + interrupts =3D ; + 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 ; + 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>; + }; + rga: rga@fdb80000 { compatible =3D "rockchip,rk3588-rga", "rockchip,rk3288-rga"; reg =3D <0x0 0xfdb80000 0x0 0x180>; --=20 2.54.0 From nobody Mon Jun 8 06:38:19 2026 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 E277F47F2E5 for ; Fri, 5 Jun 2026 22:08:43 +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=1780697325; cv=none; b=DgMqRa/3ulgI/ygXM4cch1j/jhvnlRiBEZ9yi0E5GSCkRaYZ+mJz9Xy0j0LWvpPfXANVeumJIA8zdC9o10Bn7j+KYiNU8y6HxSPURDzBh2+ZrZhI4+zqr0KXQ4SAOfmdTU7BZvjDHXe6AACe38sk9yxsy/EEb/Y4K4QgSsCNJms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780697325; c=relaxed/simple; bh=jokZ9HIT0lQTeiUZfc/dC/sOfCnzr6DFkhp0cado/e4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lIm+34ZsCxdbNmGrnypl1WEtac+e1b5zYOQ7zevM83uWIagf+kUsx7tAkwlljnOiJnQlBucsfNjIIiDVJalXjs664Knkel23R8DIeac4o8aAHOdg0yTfvszMsYf0T/xR2FhgbOTHpIHq6840MVCC6UhCrG32oBIzeYx4RLNuors= 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 1wVciG-0000LW-Mz; Sat, 06 Jun 2026 00:08:24 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Sat, 06 Jun 2026 00:07:03 +0200 Subject: [PATCH 17/17] iommu/rockchip: disable fetch dte time limit 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: <20260606-spu-rga3multicore-v1-17-3ec2b15675f7@pengutronix.de> References: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> In-Reply-To: <20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Philipp Zabel Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Detlev Casanova , Michael Tretter , =?utf-8?q?Sven_P=C3=BCschel?= , Simon Xue , Joerg Roedel X-Mailer: b4 0.15.2 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: Simon Xue Disable the Bit 31 of the AUTO_GATING iommu register, as it causes hangups with the RGA3 (Raster Graphics Acceleration 3) peripheral. The RGA3 register description of the TRM already states that the bit must be set to 1. The vendor kernel sets the bit unconditionally to 1 to fix VOP (Video Output Processor) screen black issues. This patch squashes the 2 vendor kernel commits with the following commit messages: Master fetch data and cpu update page table may work in parallel, may have the following procedure: master cpu fetch dte update page tabl | | (make dte invalid) <- zap iotlb entry | | fetch dte again (make dte invalid) <- zap iotlb entry | | fetch dte again (make dte invalid) <- zap iotlb entry | | fetch dte again (make iommu block) <- zap iotlb entry New iommu version has the above bug, if fetch dte consecutively four times, then it will be blocked. Fortunately, we can set bit 31 of register MMU_AUTO_GATING to 1 to make it work as old version which does not have this issue. This issue only appears on RV1126 so far, so make a workaround dedicated to "rockchip,rv1126" machine type. iommu/rockchip: fix vop blocked and screen black on RK356X and RK3588 RK3568 and RK3588 has the same issue as RV1126/RV1109 that caused by dte fetch time limit, So we can set BIT(31) of register 0x24 default to 1 as a workaround. Signed-off-by: Simon Xue Signed-off-by: Sven P=C3=BCschel Acked-by: Heiko Stuebner Signed-off-by: Joerg Roedel --- (cherry picked from commit 8d4346ecd4950ae08cc76a6de327c264e846758c) picked from the next branch of https://git.kernel.org/pub/scm/linux/kernel/git/iommu/linux.git for a convenient usage of the patches. --- drivers/iommu/rockchip-iommu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 0013cf196c573..87ae036d64145 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -76,6 +76,8 @@ #define SPAGE_ORDER 12 #define SPAGE_SIZE (1 << SPAGE_ORDER) =20 +#define DISABLE_FETCH_DTE_TIME_LIMIT BIT(31) + /* * Support mapping any size that fits in one page table: * 4 KiB to 4 MiB @@ -930,6 +932,7 @@ static int rk_iommu_enable(struct rk_iommu *iommu) struct iommu_domain *domain =3D iommu->domain; struct rk_iommu_domain *rk_domain =3D to_rk_domain(domain); int ret, i; + u32 auto_gate; =20 ret =3D clk_bulk_enable(iommu->num_clocks, iommu->clocks); if (ret) @@ -948,6 +951,11 @@ static int rk_iommu_enable(struct rk_iommu *iommu) rk_ops->mk_dtentries(rk_domain->dt_dma)); rk_iommu_base_command(iommu->bases[i], RK_MMU_CMD_ZAP_CACHE); rk_iommu_write(iommu->bases[i], RK_MMU_INT_MASK, RK_MMU_IRQ_MASK); + + /* Workaround for iommu blocked, BIT(31) default to 1 */ + auto_gate =3D rk_iommu_read(iommu->bases[i], RK_MMU_AUTO_GATING); + auto_gate |=3D DISABLE_FETCH_DTE_TIME_LIMIT; + rk_iommu_write(iommu->bases[i], RK_MMU_AUTO_GATING, auto_gate); } =20 ret =3D rk_iommu_enable_paging(iommu); --=20 2.54.0