Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp222471rdb; Tue, 5 Dec 2023 03:50:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBeUcchUhUHvlee2jr2nOBXKIs9TLNmdrNTti6BO/8bHaOlLyKloZojMTo37OL0vO9m56h X-Received: by 2002:a05:6a21:7894:b0:187:c3db:8999 with SMTP id bf20-20020a056a21789400b00187c3db8999mr7160733pzc.45.1701777009685; Tue, 05 Dec 2023 03:50:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701777009; cv=none; d=google.com; s=arc-20160816; b=WjqRNyYf8Bu5wve7PTG+jot8c4zTaMzWBN6rlmcJg0irlnKDltcQAaD/EboHa3xCht vHCVUr/uUwFvie3dfqENcsKCT/k+nO7UvM0fWvosuo5f/1r2Z/1MCXw3uiaqoNdjryw8 X3uZRtgJHQzzb8erx8bh2VuQcGhcaoOZtYUc7wcyU1IaUjs7qVK/M/wG95Ep8EKAJ2gt I+nx3s8m++OYCNXVmnSbYQ5mx0rBgy0IAlM+7ugxYThPV7/XmDUHNaUwW8QybcebsLJ4 VqrK/GhSoHFdlQIevg2fbMfbxxRiX1bOFNnMVfF4Q+DGXR2fcXa9anMHTcDUXeunJWn2 W1UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=AZT8TEnCg17hGz9D9aoXrHaxFJW7dZSsSL0dlLW7alA=; fh=jYlGRFhaNj2qgjIC2EGovKn8iQv9lOtKB1PqfecCqrU=; b=r60sdbJx3xfen/vUPCRoLMamJpNGHtqo7zlDIJ5ZsySSWBX5BhlOfkCo0tolrgZtT0 s/CLCYGR2HUifK24h8VMuIySqg2PgON5zoJ67Es8FjhpUa3bidxXYz98191TyZeR4WBN FKTOJiYNfJS5G6QlKyLXR8Usy9NDe3Cwsy0h2r91/qRIpVVJlt0PbgV45f1JcYXgzZn7 560npmpHS6IgBejsAFxYt/HxpEBuvp+RhEXGlWJpkek+tvhosTkElj0gjeJSZmYLzPo3 RcUblI2zNtDNXNUY3bp2HMqJAVzcmgErkANPpSiTXiWZfg3zCtYWdcpw+080qg8M8TJV iiaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mFFwe97a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id g15-20020a17090a4b0f00b0027cf3fd376bsi8023130pjh.28.2023.12.05.03.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:50:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mFFwe97a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DA6948052BFA; Tue, 5 Dec 2023 03:50:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347033AbjLELtt (ORCPT + 99 others); Tue, 5 Dec 2023 06:49:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347104AbjLELth (ORCPT ); Tue, 5 Dec 2023 06:49:37 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60FF8197; Tue, 5 Dec 2023 03:49:42 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2866e4ac34bso3018067a91.1; Tue, 05 Dec 2023 03:49:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701776982; x=1702381782; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AZT8TEnCg17hGz9D9aoXrHaxFJW7dZSsSL0dlLW7alA=; b=mFFwe97aq+ILQKLPguySsTxa42fQPgD+JLNTuYiJBCZ6iNIXP6FGQ6zTXiiFX8vNAZ 14gBvXhNXodxkGavFwycVFP29RbVG+vMSLX1LDlaweIQQoexi+UYkbEjUzIIFf230Y26 A76FKUXhH2RCsrihsF6JJt6etSE9oJ0WJRiXi1L7eMjGWO4qMxDao5nuJ+rMM4C+Giz7 llmIP51ILndpuWl7Gz0EfhWKVpgpEOQ+qhocIzTehZMHJ2fXcCo6/Ash7YV06MFKrfek qt97ORB0Kg7oZ08mXm7M5O6/JZUdvC+0S8qsLFx/Huzz6lHhkq+rFZON0dVv4P6vw0Wq Lg/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701776982; x=1702381782; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AZT8TEnCg17hGz9D9aoXrHaxFJW7dZSsSL0dlLW7alA=; b=EN9AGwhtYb1WrcIl42OlvaidqwOkHmsP2K86ChRbDpa7/kZavo2B6bJhK9XFyztpyv 6SpQ83fOrwegtiIZj5XrDiwoErqnm//X9qNmljHb99jCpb20lnyHlNWy/xf+fagEonEq fii5cIIkj1fhB3AKH5P3lbQXUtQe767n6H4JNpDnj9FOwetECjPc6XZHm3ynN6EtxHc8 W7UsIkJXD9MGI0DbQgM8dow0gydU6NZIF1Y7Mh50tdH9pKQcbwoJHcp0fEoShocj46bX /foMu9k3oeg2tDLg+dempSbW1P9bDV6ZIu2opad1gWh0a6+tv+VjqIaX4rHY9R12cqNr iwhA== X-Gm-Message-State: AOJu0Yyr0nIReDhWzCr9i/CtAcW2vgm8X+PQrY/LwFO0Q+pbB++gSx7e iUBaGyethzByVpexsZIESi4imGbTW2H2qyKFC8Y= X-Received: by 2002:a17:90b:3912:b0:285:fc67:6164 with SMTP id ob18-20020a17090b391200b00285fc676164mr1032342pjb.5.1701776981534; Tue, 05 Dec 2023 03:49:41 -0800 (PST) MIME-Version: 1.0 References: <20231205-rkisp-irq-fix-v1-0-f4045c74ba45@ideasonboard.com> <20231205-rkisp-irq-fix-v1-3-f4045c74ba45@ideasonboard.com> <20231205082016.GA17394@pendragon.ideasonboard.com> <9b28dcf7-c9a0-4d68-9197-cdcdd9f0393b@ideasonboard.com> In-Reply-To: <9b28dcf7-c9a0-4d68-9197-cdcdd9f0393b@ideasonboard.com> From: Adam Ford Date: Tue, 5 Dec 2023 05:49:30 -0600 Message-ID: Subject: Re: [PATCH 3/4] media: rkisp1: Fix IRQ handling due to shared interrupts To: Tomi Valkeinen Cc: Laurent Pinchart , Dafna Hirschfeld , Mauro Carvalho Chehab , Heiko Stuebner , Paul Elder , Alexander Stein , kieran.bingham@ideasonboard.com, umang.jain@ideasonboard.com, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 05 Dec 2023 03:50:05 -0800 (PST) On Tue, Dec 5, 2023 at 2:27=E2=80=AFAM Tomi Valkeinen 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 I= SP > >> 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 > >> --- > >> .../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 =3D 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/dri= vers/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 =3D dev_get_drvdata(dev); > >> u32 val, status; > >> > >> + if (!rkisp1->irqs_enabled) > >> + return IRQ_NONE; > >> + > >> status =3D rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); > >> if (!status) > >> return IRQ_NONE; > >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/dri= vers/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 =3D dev_get_drvdata(dev); > >> > >> + rkisp1->irqs_enabled =3D false; > >> + /* Make sure the IRQ handler will see the above */ > >> + mb(); > >> + > >> + /* > >> + * Wait until any running IRQ handler has returned. The IRQ handl= er > >> + * may get called even after this (as it's a shared interrupt lin= e) > >> + * but the 'irqs_enabled' flag will make the handler return immed= iately. > >> + */ > >> + for (unsigned int i =3D 0; i < RKISP1_NUM_IRQS; ++i) { > >> + if (rkisp1->irqs[i] =3D=3D -1) > >> + continue; > >> + > >> + if (i =3D=3D 0 || rkisp1->irqs[i - 1] !=3D 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(s= truct device *dev) > >> if (ret) > >> return ret; > >> > >> + rkisp1->irqs_enabled =3D 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/dri= vers/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 =3D dev_get_drvdata(dev); > >> u32 status, isp_err; > >> > >> + if (!rkisp1->irqs_enabled) > >> + return IRQ_NONE; > >> + > >> status =3D rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); > >> if (!status) > >> return IRQ_NONE; > > >