Message ID | 20231205-rkisp-irq-fix-v1-3-f4045c74ba45@ideasonboard.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3278780vqy; Tue, 5 Dec 2023 00:10:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/KZp/rfF7xFOQhDpw53d8oIBGPsvhSRGdUiOpX0WOV85wRZ9SKcuydiLoex3bvhigISRG X-Received: by 2002:a05:6a21:1c87:b0:18f:97c:5b96 with SMTP id sf7-20020a056a211c8700b0018f097c5b96mr1910970pzb.100.1701763838685; Tue, 05 Dec 2023 00:10:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701763838; cv=none; d=google.com; s=arc-20160816; b=Q6sEbxuxgipxeGFiKoVnHqdrCsLseyD6u7fk14rV0c0rBDnBmMIVlDC3D0lSptnwWK 8abeT3KYzRloz1XxbcL3BC2NsUr0z9ZLEuxPqAIrszlUoerL4+yrKxVwtrnNysby7vQk qUTuhvLi/M6E7ZechXRwVcbqj2uiWd7s6+QIsZuWHOJGAXLQmhTDzWScm+gMdNGQk9EE hL6Qafx+/e1pCfxh2W+SbswRzUWR6h5v0FAMEa6FnpWcW1LG5oYIoYidsElR+f/rkH4S CQ0xbX1Z/k3HmEt84VaykjPnto6VBAf5NNhwAJ4Uvh7CU75RyoRB5YVddU1HjNk8iftK HZ6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=8WwSkMS39/oxqZxHk27zafxIEbJrYyyjYw5MqxH7f2s=; fh=6fL1NhFCGI+wAVvsHH1pL+P1muGn2uwGLcwd3RTuFww=; b=VoBSKb9O8cMSLsurRD3R6jouNceyMdBkZwRS42QW/3LMM9h/uHUw8ViQZ59CdFVpv3 09UHQu+32EQ7uBrmNvtazro+XU70mCyrbaWpuvkZjJMPHQdRVmyObRIJSfXUgFzeOGH+ JV5aoX527gzoWYDfprQs+y+2auXNdN/9Z0Efecu3PyI+ZksQW9+rNsuGyZAeDwiyWPup LXJTnQDWI9h/5QoTb6HiTvAvkaxUtC3mJ+hMZDUCjbFKYJ2g5LSjdjyIhncj6C3WtFVT I8qOxW0PADNSh8BqFrQ18ENn1mNaMVQ9Kt1H2/I4QzVfcui+ia3wsydNK3wbxLXPXMUe p34A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=T2B8z+EF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id ha12-20020a17090af3cc00b00286a3123c72si3445033pjb.56.2023.12.05.00.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 00:10:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=T2B8z+EF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9895B80A18F5; Tue, 5 Dec 2023 00:10:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376492AbjLEIKJ (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Tue, 5 Dec 2023 03:10:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbjLEIKC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 5 Dec 2023 03:10:02 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 199FFD3; Tue, 5 Dec 2023 00:10:09 -0800 (PST) Received: from [127.0.1.1] (91-158-149-209.elisa-laajakaista.fi [91.158.149.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 243E31010; Tue, 5 Dec 2023 09:09:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1701763765; bh=mZtjLUcwPurRjWrqxlSCj4xDyOLWjQrMwEJHqEedGrc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=T2B8z+EFK7yLMReLZkqX9uLlblAixwWFtW4w9OrUtqDvnIfnZV28/DB3CAz3fRJPM sDpUXFmHqK4sK6+zKXch5KJE1mZSLXmMaEI1NcnsP9PePDIOqzP2ZpkaRIa6XILfGv 5QqCugz8PlXWX2F8ueVztEMk5bYQKK38SVtYbquQ= From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Date: Tue, 05 Dec 2023 10:09:34 +0200 Subject: [PATCH 3/4] media: rkisp1: Fix IRQ handling due to shared interrupts MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231205-rkisp-irq-fix-v1-3-f4045c74ba45@ideasonboard.com> References: <20231205-rkisp-irq-fix-v1-0-f4045c74ba45@ideasonboard.com> In-Reply-To: <20231205-rkisp-irq-fix-v1-0-f4045c74ba45@ideasonboard.com> To: Dafna Hirschfeld <dafna@fastmail.com>, Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, Heiko Stuebner <heiko@sntech.de>, Paul Elder <paul.elder@ideasonboard.com> Cc: Alexander Stein <alexander.stein@ew.tq-group.com>, kieran.bingham@ideasonboard.com, umang.jain@ideasonboard.com, aford173@gmail.com, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=4620; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=mZtjLUcwPurRjWrqxlSCj4xDyOLWjQrMwEJHqEedGrc=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBlbtrY0ag5xyx3Lvv6lltmY2X9cTNDItBEJueE1 /dtr4OCXaCJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZW7a2AAKCRD6PaqMvJYe 9QsvD/wKjXWKvhIraBeIDihoS0XIIVMphsqF9AQl4NGzoX0MehHO9SgTNjNmA95+ILO2R6MMuHx vXG7j3tLwF1O0WOjQzRXl2p9DHvtsySnQFHlSp8SEx0DXoVWwRbRGQ92tF6kYnQOUXeznJQOnG4 idNHblxE3f7pfvwLmkpWTDfHVfKRJN76QNAt+pVEFCSTB+DtB2TBWXGrBazlPRBW0hbx414AmYA wI41GEvlDfpoACZxYjaKpb+/4UruMRASpZOd3Ksg4E92AFDNB+4RcecVwb4DTeFHX1m4JinRnlG t9S3D+AJS0qZg9ECDt3S3Fv4DAL4vuHModMlHZ/hPp4GGC9kVtqTMZUY4NMslb4uTpt/q0Tif1y Bth3uhcsXEb6XQ+P+mqBI8l88Z/RZffcH1i7DhH81oEtU0qORJpnEj8To8x4Va44Uj4Ai0vC3Z2 OpMebdT+709zFSwVkUokuQUkSZ1I0ZRZ6NaycdrjCpR6/cuXE2bjcHdXq5UuuyOnUJpiDnAG3R2 +AXqoxw0Zv9+rbSUEPOPtvJIbteqela88/Dao13K6GeJMLJTO5J6yNZC4+UrqN6zB1/w49H3dTB IUdwVTItp2jXk9prOm5FI7nFB/ujHNuruPx8svnd/huQPuuJAM6AnxSYSah7DaZsTdn/+UuXWnV 558PKJn7Z9WAgVg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 05 Dec 2023 00:10:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784428719002245021 X-GMAIL-MSGID: 1784428719002245021 |
Series |
media: rkisp1: Fix IRQ related issues
|
|
Commit Message
Tomi Valkeinen
Dec. 5, 2023, 8:09 a.m. UTC
The driver requests the interrupts as IRQF_SHARED, so the interrupt
handlers can be called at any time. If such a call happens while the ISP
is powered down, the SoC will hang as the driver tries to access the
ISP registers.
Fix this by adding a new field, 'irqs_enabled', which is used to bail
out from the interrupt handler when the ISP is not operational.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
.../media/platform/rockchip/rkisp1/rkisp1-capture.c | 3 +++
.../media/platform/rockchip/rkisp1/rkisp1-common.h | 2 ++
drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c | 3 +++
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 21 +++++++++++++++++++++
drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c | 3 +++
5 files changed, 32 insertions(+)
Comments
Hi Tomi, Thank you for the patch. On Tue, Dec 05, 2023 at 10:09:34AM +0200, Tomi Valkeinen wrote: > The driver requests the interrupts as IRQF_SHARED, so the interrupt > handlers can be called at any time. If such a call happens while the ISP > is powered down, the SoC will hang as the driver tries to access the > ISP registers. Is IRQF_SHARED actually needed ? > Fix this by adding a new field, 'irqs_enabled', which is used to bail > out from the interrupt handler when the ISP is not operational. > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > --- > .../media/platform/rockchip/rkisp1/rkisp1-capture.c | 3 +++ > .../media/platform/rockchip/rkisp1/rkisp1-common.h | 2 ++ > drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c | 3 +++ > drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 21 +++++++++++++++++++++ > drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c | 3 +++ > 5 files changed, 32 insertions(+) > > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > index b50b044d22af..e92067897f28 100644 > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > @@ -779,6 +779,9 @@ irqreturn_t rkisp1_capture_isr(int irq, void *ctx) > unsigned int i; > u32 status; > > + if (!rkisp1->irqs_enabled) > + return IRQ_NONE; > + > status = rkisp1_read(rkisp1, RKISP1_CIF_MI_MIS); > if (!status) > return IRQ_NONE; > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > index ec28907d978e..7f97fdf6e24c 100644 > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > @@ -465,6 +465,7 @@ struct rkisp1_debug { > * @debug: debug params to be exposed on debugfs > * @info: version-specific ISP information > * @irqs: IRQ line numbers > + * @irqs_enabled: the hardware is enabled and can cause interrupts > */ > struct rkisp1_device { > void __iomem *base_addr; > @@ -488,6 +489,7 @@ struct rkisp1_device { > struct rkisp1_debug debug; > const struct rkisp1_info *info; > int irqs[RKISP1_NUM_IRQS]; > + bool irqs_enabled; > }; > > /* > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > index 47f4353a1784..f6b54654b435 100644 > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > @@ -184,6 +184,9 @@ irqreturn_t rkisp1_csi_isr(int irq, void *ctx) > struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > u32 val, status; > > + if (!rkisp1->irqs_enabled) > + return IRQ_NONE; > + > status = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); > if (!status) > return IRQ_NONE; > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > index 1d60f4b8bd09..fbe03f7864e3 100644 > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > @@ -306,6 +306,23 @@ static int __maybe_unused rkisp1_runtime_suspend(struct device *dev) > { > struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > > + rkisp1->irqs_enabled = false; > + /* Make sure the IRQ handler will see the above */ > + mb(); > + > + /* > + * Wait until any running IRQ handler has returned. The IRQ handler > + * may get called even after this (as it's a shared interrupt line) > + * but the 'irqs_enabled' flag will make the handler return immediately. > + */ > + for (unsigned int i = 0; i < RKISP1_NUM_IRQS; ++i) { > + if (rkisp1->irqs[i] == -1) > + continue; > + > + if (i == 0 || rkisp1->irqs[i - 1] != rkisp1->irqs[i]) > + synchronize_irq(rkisp1->irqs[i]); > + } > + > clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks); > return pinctrl_pm_select_sleep_state(dev); > } > @@ -322,6 +339,10 @@ static int __maybe_unused rkisp1_runtime_resume(struct device *dev) > if (ret) > return ret; > > + rkisp1->irqs_enabled = true; > + /* Make sure the IRQ handler will see the above */ > + mb(); > + > return 0; > } > > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > index dafbfd230542..d6b8786661ad 100644 > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > @@ -1082,6 +1082,9 @@ irqreturn_t rkisp1_isp_isr(int irq, void *ctx) > struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > u32 status, isp_err; > > + if (!rkisp1->irqs_enabled) > + return IRQ_NONE; > + > status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); > if (!status) > return IRQ_NONE;
On 05/12/2023 10:20, Laurent Pinchart wrote: > Hi Tomi, > > Thank you for the patch. > > On Tue, Dec 05, 2023 at 10:09:34AM +0200, Tomi Valkeinen wrote: >> The driver requests the interrupts as IRQF_SHARED, so the interrupt >> handlers can be called at any time. If such a call happens while the ISP >> is powered down, the SoC will hang as the driver tries to access the >> ISP registers. > > Is IRQF_SHARED actually needed ? I don't have any answer to that, but it seems to have always been there. Dropping it would simplify the code, but we can only do that if we are sure all the platforms the ISP is used on or will be used on won't share the interrupt. Tomi >> Fix this by adding a new field, 'irqs_enabled', which is used to bail >> out from the interrupt handler when the ISP is not operational. >> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> >> --- >> .../media/platform/rockchip/rkisp1/rkisp1-capture.c | 3 +++ >> .../media/platform/rockchip/rkisp1/rkisp1-common.h | 2 ++ >> drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c | 3 +++ >> drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 21 +++++++++++++++++++++ >> drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c | 3 +++ >> 5 files changed, 32 insertions(+) >> >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c >> index b50b044d22af..e92067897f28 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c >> @@ -779,6 +779,9 @@ irqreturn_t rkisp1_capture_isr(int irq, void *ctx) >> unsigned int i; >> u32 status; >> >> + if (!rkisp1->irqs_enabled) >> + return IRQ_NONE; >> + >> status = rkisp1_read(rkisp1, RKISP1_CIF_MI_MIS); >> if (!status) >> return IRQ_NONE; >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h >> index ec28907d978e..7f97fdf6e24c 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h >> @@ -465,6 +465,7 @@ struct rkisp1_debug { >> * @debug: debug params to be exposed on debugfs >> * @info: version-specific ISP information >> * @irqs: IRQ line numbers >> + * @irqs_enabled: the hardware is enabled and can cause interrupts >> */ >> struct rkisp1_device { >> void __iomem *base_addr; >> @@ -488,6 +489,7 @@ struct rkisp1_device { >> struct rkisp1_debug debug; >> const struct rkisp1_info *info; >> int irqs[RKISP1_NUM_IRQS]; >> + bool irqs_enabled; >> }; >> >> /* >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c >> index 47f4353a1784..f6b54654b435 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c >> @@ -184,6 +184,9 @@ irqreturn_t rkisp1_csi_isr(int irq, void *ctx) >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); >> u32 val, status; >> >> + if (!rkisp1->irqs_enabled) >> + return IRQ_NONE; >> + >> status = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); >> if (!status) >> return IRQ_NONE; >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c >> index 1d60f4b8bd09..fbe03f7864e3 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c >> @@ -306,6 +306,23 @@ static int __maybe_unused rkisp1_runtime_suspend(struct device *dev) >> { >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); >> >> + rkisp1->irqs_enabled = false; >> + /* Make sure the IRQ handler will see the above */ >> + mb(); >> + >> + /* >> + * Wait until any running IRQ handler has returned. The IRQ handler >> + * may get called even after this (as it's a shared interrupt line) >> + * but the 'irqs_enabled' flag will make the handler return immediately. >> + */ >> + for (unsigned int i = 0; i < RKISP1_NUM_IRQS; ++i) { >> + if (rkisp1->irqs[i] == -1) >> + continue; >> + >> + if (i == 0 || rkisp1->irqs[i - 1] != rkisp1->irqs[i]) >> + synchronize_irq(rkisp1->irqs[i]); >> + } >> + >> clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks); >> return pinctrl_pm_select_sleep_state(dev); >> } >> @@ -322,6 +339,10 @@ static int __maybe_unused rkisp1_runtime_resume(struct device *dev) >> if (ret) >> return ret; >> >> + rkisp1->irqs_enabled = true; >> + /* Make sure the IRQ handler will see the above */ >> + mb(); >> + >> return 0; >> } >> >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c >> index dafbfd230542..d6b8786661ad 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c >> @@ -1082,6 +1082,9 @@ irqreturn_t rkisp1_isp_isr(int irq, void *ctx) >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); >> u32 status, isp_err; >> >> + if (!rkisp1->irqs_enabled) >> + return IRQ_NONE; >> + >> status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); >> if (!status) >> return IRQ_NONE; >
On Tue, Dec 5, 2023 at 2:27 AM Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> wrote: > > On 05/12/2023 10:20, Laurent Pinchart wrote: > > Hi Tomi, > > > > Thank you for the patch. > > > > On Tue, Dec 05, 2023 at 10:09:34AM +0200, Tomi Valkeinen wrote: > >> The driver requests the interrupts as IRQF_SHARED, so the interrupt > >> handlers can be called at any time. If such a call happens while the ISP > >> is powered down, the SoC will hang as the driver tries to access the > >> ISP registers. > > > > Is IRQF_SHARED actually needed ? > > I don't have any answer to that, but it seems to have always been there. > Dropping it would simplify the code, but we can only do that if we are > sure all the platforms the ISP is used on or will be used on won't share > the interrupt. I can't speak for the Rockchip, but from what I can see, the imx8mp has multiple causes for Interrupt 74 and 75, but they all appear to be ISP1 and ISP2 related. adam > > Tomi > > >> Fix this by adding a new field, 'irqs_enabled', which is used to bail > >> out from the interrupt handler when the ISP is not operational. > >> > >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > >> --- > >> .../media/platform/rockchip/rkisp1/rkisp1-capture.c | 3 +++ > >> .../media/platform/rockchip/rkisp1/rkisp1-common.h | 2 ++ > >> drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c | 3 +++ > >> drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 21 +++++++++++++++++++++ > >> drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c | 3 +++ > >> 5 files changed, 32 insertions(+) > >> > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > >> index b50b044d22af..e92067897f28 100644 > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > >> @@ -779,6 +779,9 @@ irqreturn_t rkisp1_capture_isr(int irq, void *ctx) > >> unsigned int i; > >> u32 status; > >> > >> + if (!rkisp1->irqs_enabled) > >> + return IRQ_NONE; > >> + > >> status = rkisp1_read(rkisp1, RKISP1_CIF_MI_MIS); > >> if (!status) > >> return IRQ_NONE; > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > >> index ec28907d978e..7f97fdf6e24c 100644 > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > >> @@ -465,6 +465,7 @@ struct rkisp1_debug { > >> * @debug: debug params to be exposed on debugfs > >> * @info: version-specific ISP information > >> * @irqs: IRQ line numbers > >> + * @irqs_enabled: the hardware is enabled and can cause interrupts > >> */ > >> struct rkisp1_device { > >> void __iomem *base_addr; > >> @@ -488,6 +489,7 @@ struct rkisp1_device { > >> struct rkisp1_debug debug; > >> const struct rkisp1_info *info; > >> int irqs[RKISP1_NUM_IRQS]; > >> + bool irqs_enabled; > >> }; > >> > >> /* > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > >> index 47f4353a1784..f6b54654b435 100644 > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > >> @@ -184,6 +184,9 @@ irqreturn_t rkisp1_csi_isr(int irq, void *ctx) > >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > >> u32 val, status; > >> > >> + if (!rkisp1->irqs_enabled) > >> + return IRQ_NONE; > >> + > >> status = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); > >> if (!status) > >> return IRQ_NONE; > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > >> index 1d60f4b8bd09..fbe03f7864e3 100644 > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > >> @@ -306,6 +306,23 @@ static int __maybe_unused rkisp1_runtime_suspend(struct device *dev) > >> { > >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > >> > >> + rkisp1->irqs_enabled = false; > >> + /* Make sure the IRQ handler will see the above */ > >> + mb(); > >> + > >> + /* > >> + * Wait until any running IRQ handler has returned. The IRQ handler > >> + * may get called even after this (as it's a shared interrupt line) > >> + * but the 'irqs_enabled' flag will make the handler return immediately. > >> + */ > >> + for (unsigned int i = 0; i < RKISP1_NUM_IRQS; ++i) { > >> + if (rkisp1->irqs[i] == -1) > >> + continue; > >> + > >> + if (i == 0 || rkisp1->irqs[i - 1] != rkisp1->irqs[i]) > >> + synchronize_irq(rkisp1->irqs[i]); > >> + } > >> + > >> clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks); > >> return pinctrl_pm_select_sleep_state(dev); > >> } > >> @@ -322,6 +339,10 @@ static int __maybe_unused rkisp1_runtime_resume(struct device *dev) > >> if (ret) > >> return ret; > >> > >> + rkisp1->irqs_enabled = true; > >> + /* Make sure the IRQ handler will see the above */ > >> + mb(); > >> + > >> return 0; > >> } > >> > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > >> index dafbfd230542..d6b8786661ad 100644 > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > >> @@ -1082,6 +1082,9 @@ irqreturn_t rkisp1_isp_isr(int irq, void *ctx) > >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > >> u32 status, isp_err; > >> > >> + if (!rkisp1->irqs_enabled) > >> + return IRQ_NONE; > >> + > >> status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); > >> if (!status) > >> return IRQ_NONE; > > >
On Tue, Dec 05, 2023 at 05:49:30AM -0600, Adam Ford wrote: > On Tue, Dec 5, 2023 at 2:27 AM Tomi Valkeinen wrote: > > On 05/12/2023 10:20, Laurent Pinchart wrote: > > > On Tue, Dec 05, 2023 at 10:09:34AM +0200, Tomi Valkeinen wrote: > > >> The driver requests the interrupts as IRQF_SHARED, so the interrupt > > >> handlers can be called at any time. If such a call happens while the ISP > > >> is powered down, the SoC will hang as the driver tries to access the > > >> ISP registers. > > > > > > Is IRQF_SHARED actually needed ? > > > > I don't have any answer to that, but it seems to have always been there. > > Dropping it would simplify the code, but we can only do that if we are > > sure all the platforms the ISP is used on or will be used on won't share > > the interrupt. > > I can't speak for the Rockchip, but from what I can see, the imx8mp > has multiple causes for Interrupt 74 and 75, but they all appear to > be ISP1 and ISP2 related. The ISP has multiple interrupt lines. In some SoCs, they're all wired to a single line of the IRQ controller (e.g. RK3399 and i.MX8MP), while other SoCs use separate interrupts (e.g. PX30). I have checked the PX30, RK3399 and i.MX8MP datasheets, and the ISP interrupts are not shared with any other peripheral. I think it's thus safe to drop IRQF_SHARED. > > >> Fix this by adding a new field, 'irqs_enabled', which is used to bail > > >> out from the interrupt handler when the ISP is not operational. > > >> > > >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > > >> --- > > >> .../media/platform/rockchip/rkisp1/rkisp1-capture.c | 3 +++ > > >> .../media/platform/rockchip/rkisp1/rkisp1-common.h | 2 ++ > > >> drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c | 3 +++ > > >> drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 21 +++++++++++++++++++++ > > >> drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c | 3 +++ > > >> 5 files changed, 32 insertions(+) > > >> > > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > > >> index b50b044d22af..e92067897f28 100644 > > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c > > >> @@ -779,6 +779,9 @@ irqreturn_t rkisp1_capture_isr(int irq, void *ctx) > > >> unsigned int i; > > >> u32 status; > > >> > > >> + if (!rkisp1->irqs_enabled) > > >> + return IRQ_NONE; > > >> + > > >> status = rkisp1_read(rkisp1, RKISP1_CIF_MI_MIS); > > >> if (!status) > > >> return IRQ_NONE; > > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > > >> index ec28907d978e..7f97fdf6e24c 100644 > > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > > >> @@ -465,6 +465,7 @@ struct rkisp1_debug { > > >> * @debug: debug params to be exposed on debugfs > > >> * @info: version-specific ISP information > > >> * @irqs: IRQ line numbers > > >> + * @irqs_enabled: the hardware is enabled and can cause interrupts > > >> */ > > >> struct rkisp1_device { > > >> void __iomem *base_addr; > > >> @@ -488,6 +489,7 @@ struct rkisp1_device { > > >> struct rkisp1_debug debug; > > >> const struct rkisp1_info *info; > > >> int irqs[RKISP1_NUM_IRQS]; > > >> + bool irqs_enabled; > > >> }; > > >> > > >> /* > > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > > >> index 47f4353a1784..f6b54654b435 100644 > > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > > >> @@ -184,6 +184,9 @@ irqreturn_t rkisp1_csi_isr(int irq, void *ctx) > > >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > > >> u32 val, status; > > >> > > >> + if (!rkisp1->irqs_enabled) > > >> + return IRQ_NONE; > > >> + > > >> status = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); > > >> if (!status) > > >> return IRQ_NONE; > > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > > >> index 1d60f4b8bd09..fbe03f7864e3 100644 > > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > > >> @@ -306,6 +306,23 @@ static int __maybe_unused rkisp1_runtime_suspend(struct device *dev) > > >> { > > >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > > >> > > >> + rkisp1->irqs_enabled = false; > > >> + /* Make sure the IRQ handler will see the above */ > > >> + mb(); > > >> + > > >> + /* > > >> + * Wait until any running IRQ handler has returned. The IRQ handler > > >> + * may get called even after this (as it's a shared interrupt line) > > >> + * but the 'irqs_enabled' flag will make the handler return immediately. > > >> + */ > > >> + for (unsigned int i = 0; i < RKISP1_NUM_IRQS; ++i) { > > >> + if (rkisp1->irqs[i] == -1) > > >> + continue; > > >> + > > >> + if (i == 0 || rkisp1->irqs[i - 1] != rkisp1->irqs[i]) > > >> + synchronize_irq(rkisp1->irqs[i]); > > >> + } > > >> + > > >> clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks); > > >> return pinctrl_pm_select_sleep_state(dev); > > >> } > > >> @@ -322,6 +339,10 @@ static int __maybe_unused rkisp1_runtime_resume(struct device *dev) > > >> if (ret) > > >> return ret; > > >> > > >> + rkisp1->irqs_enabled = true; > > >> + /* Make sure the IRQ handler will see the above */ > > >> + mb(); > > >> + > > >> return 0; > > >> } > > >> > > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > > >> index dafbfd230542..d6b8786661ad 100644 > > >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > > >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > > >> @@ -1082,6 +1082,9 @@ irqreturn_t rkisp1_isp_isr(int irq, void *ctx) > > >> struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); > > >> u32 status, isp_err; > > >> > > >> + if (!rkisp1->irqs_enabled) > > >> + return IRQ_NONE; > > >> + > > >> status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); > > >> if (!status) > > >> return IRQ_NONE;
diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c index b50b044d22af..e92067897f28 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c @@ -779,6 +779,9 @@ irqreturn_t rkisp1_capture_isr(int irq, void *ctx) unsigned int i; u32 status; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_MI_MIS); if (!status) return IRQ_NONE; diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h index ec28907d978e..7f97fdf6e24c 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h @@ -465,6 +465,7 @@ struct rkisp1_debug { * @debug: debug params to be exposed on debugfs * @info: version-specific ISP information * @irqs: IRQ line numbers + * @irqs_enabled: the hardware is enabled and can cause interrupts */ struct rkisp1_device { void __iomem *base_addr; @@ -488,6 +489,7 @@ struct rkisp1_device { struct rkisp1_debug debug; const struct rkisp1_info *info; int irqs[RKISP1_NUM_IRQS]; + bool irqs_enabled; }; /* diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c index 47f4353a1784..f6b54654b435 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c @@ -184,6 +184,9 @@ irqreturn_t rkisp1_csi_isr(int irq, void *ctx) struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); u32 val, status; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); if (!status) return IRQ_NONE; diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c index 1d60f4b8bd09..fbe03f7864e3 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c @@ -306,6 +306,23 @@ static int __maybe_unused rkisp1_runtime_suspend(struct device *dev) { struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); + rkisp1->irqs_enabled = false; + /* Make sure the IRQ handler will see the above */ + mb(); + + /* + * Wait until any running IRQ handler has returned. The IRQ handler + * may get called even after this (as it's a shared interrupt line) + * but the 'irqs_enabled' flag will make the handler return immediately. + */ + for (unsigned int i = 0; i < RKISP1_NUM_IRQS; ++i) { + if (rkisp1->irqs[i] == -1) + continue; + + if (i == 0 || rkisp1->irqs[i - 1] != rkisp1->irqs[i]) + synchronize_irq(rkisp1->irqs[i]); + } + clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks); return pinctrl_pm_select_sleep_state(dev); } @@ -322,6 +339,10 @@ static int __maybe_unused rkisp1_runtime_resume(struct device *dev) if (ret) return ret; + rkisp1->irqs_enabled = true; + /* Make sure the IRQ handler will see the above */ + mb(); + return 0; } diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c index dafbfd230542..d6b8786661ad 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c @@ -1082,6 +1082,9 @@ irqreturn_t rkisp1_isp_isr(int irq, void *ctx) struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); u32 status, isp_err; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); if (!status) return IRQ_NONE;