All of lore.kernel.org
 help / color / mirror / Atom feed
From: Biju Das <biju.das.jz@bp.renesas.com>
To: cip-dev@lists.cip-project.org,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>,
	Pavel Machek <pavel@denx.de>
Cc: Biju Das <biju.das.jz@bp.renesas.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Subject: [PATCH 5.10.y-cip 07/18] media: vsp1: mask interrupts before enabling
Date: Thu,  7 Dec 2023 13:46:46 +0000	[thread overview]
Message-ID: <20231207134657.371420-8-biju.das.jz@bp.renesas.com> (raw)
In-Reply-To: <20231207134657.371420-1-biju.das.jz@bp.renesas.com>

From: Nikita Yushchenko <nikita.yoush@cogentembedded.com>

commit c7cfc7b90e25468c98dfb1082474644f2a3e2df7 upstream.

VSP hardware could be used (e.g. by the bootloader) before driver load,
and some interrupts could be left in enabled and pending state. In this
case, setting up VSP interrupt handler without masking interrupts before
causes interrupt handler to be immediately called (and crash due to null
vsp->info dereference).

Fix that by explicitly masking all interrupts before setting the interrupt
handler. To do so, have to set the interrupt handler later, after hw
revision is already detected and number of interrupts to mask gets
known.

Based on patch by Koji Matsuoka <koji.matsuoka.xm@renesas.com> included
in the Renesas BSP kernel.

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/media/platform/vsp1/vsp1_drv.c | 37 ++++++++++++++++++++------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 936e01c6f752..c59cfd5498da 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -550,6 +550,16 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
 	return 0;
 }
 
+static void vsp1_mask_all_interrupts(struct vsp1_device *vsp1)
+{
+	unsigned int i;
+
+	for (i = 0; i < vsp1->info->lif_count; ++i)
+		vsp1_write(vsp1, VI6_DISP_IRQ_ENB(i), 0);
+	for (i = 0; i < vsp1->info->wpf_count; ++i)
+		vsp1_write(vsp1, VI6_WPF_IRQ_ENB(i), 0);
+}
+
 /*
  * vsp1_device_get - Acquire the VSP1 device
  *
@@ -807,13 +817,6 @@ static int vsp1_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	ret = devm_request_irq(&pdev->dev, irq, vsp1_irq_handler,
-			       IRQF_SHARED, dev_name(&pdev->dev), vsp1);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to request IRQ\n");
-		return ret;
-	}
-
 	/* FCP (optional). */
 	fcp_node = of_parse_phandle(pdev->dev.of_node, "renesas,fcp", 0);
 	if (fcp_node) {
@@ -843,7 +846,6 @@ static int vsp1_probe(struct platform_device *pdev)
 		goto done;
 
 	vsp1->version = vsp1_read(vsp1, VI6_IP_VERSION);
-	vsp1_device_put(vsp1);
 
 	for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
 		if ((vsp1->version & VI6_IP_VERSION_MODEL_MASK) ==
@@ -856,12 +858,31 @@ static int vsp1_probe(struct platform_device *pdev)
 	if (!vsp1->info) {
 		dev_err(&pdev->dev, "unsupported IP version 0x%08x\n",
 			vsp1->version);
+		vsp1_device_put(vsp1);
 		ret = -ENXIO;
 		goto done;
 	}
 
 	dev_dbg(&pdev->dev, "IP version 0x%08x\n", vsp1->version);
 
+	/*
+	 * Previous use of the hardware (e.g. by the bootloader) could leave
+	 * some interrupts enabled and pending.
+	 *
+	 * TODO: Investigate if this shouldn't be better handled by using the
+	 * device reset provided by the CPG.
+	 */
+	vsp1_mask_all_interrupts(vsp1);
+
+	vsp1_device_put(vsp1);
+
+	ret = devm_request_irq(&pdev->dev, irq, vsp1_irq_handler,
+			       IRQF_SHARED, dev_name(&pdev->dev), vsp1);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to request IRQ\n");
+		goto done;
+	}
+
 	/* Instantiate entities. */
 	ret = vsp1_create_entities(vsp1);
 	if (ret < 0) {
-- 
2.25.1



  parent reply	other threads:[~2023-12-07 13:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-07 13:46 [PATCH 5.10.y-cip 00/18] Add VSPD/FCPVD support Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 01/18] device property: Add const qualifier to device_get_match_data() parameter Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 02/18] media: vsp1: use pm_runtime_resume_and_get() Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 03/18] media: vsp1: Make use of the helper function devm_platform_ioremap_resource() Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 04/18] media: vsp1: Fix WPF macro names Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 05/18] media: vsp1: Simplify DRM UIF handling Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 06/18] media: vsp1: Use platform_get_irq() to get the interrupt Biju Das
2023-12-07 13:46 ` Biju Das [this message]
2023-12-07 13:46 ` [PATCH 5.10.y-cip 08/18] media: renesas: vsp1: Add support to deassert/assert reset line Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 09/18] media: renesas: vsp1: Add support for VSP software version Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 10/18] media: vsp1: Use BIT macro for feature identification Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 11/18] media: renesas: vsp1: Add VSP1_HAS_NON_ZERO_LBA feature bit Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 12/18] media: dt-bindings: media: renesas,vsp1: Document RZ/G2L VSPD bindings Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 13/18] media: dt-bindings: media: renesas,vsp1: Document RZ/V2L " Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 14/18] media: renesas: vsp1: Add support for RZ/G2L VSPD Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 15/18] arm64: dts: renesas: r9a07g044: Add fcpvd node Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 16/18] arm64: dts: renesas: r9a07g044: Add vspd node Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 17/18] arm64: dts: renesas: r9a07g054: Add fcpvd node Biju Das
2023-12-07 13:46 ` [PATCH 5.10.y-cip 18/18] arm64: dts: renesas: r9a07g054: Add vspd node Biju Das
2023-12-07 19:10 ` [PATCH 5.10.y-cip 00/18] Add VSPD/FCPVD support Pavel Machek
2023-12-07 19:18   ` Biju Das
2023-12-08 13:14 ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231207134657.371420-8-biju.das.jz@bp.renesas.com \
    --to=biju.das.jz@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=pavel@denx.de \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.