From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63560C433E1 for ; Wed, 27 May 2020 14:46:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32BFE208C3 for ; Wed, 27 May 2020 14:46:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tpgQe+d6"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VStnWt6j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32BFE208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iE/vWvrET5iLoyGhOyS85dbg9swbVkog30he+i+UYbE=; b=tpgQe+d6WxMjNs wfJotaVOwvmBm3tmY9Ht0jw5yNs5kMePYnoIQf1PneJkyZhsHKSuQhzOi0KdR808qQa90ywnhz2zl oVTScYUc1cqYY832NdTpbgEn4vig34VG/B+EePTpkFdo1FEY1s+BPzhYNA/T88i3E2XwQrdA60l7Y G/Vb6MnnQoBxPj4oKZ0PE4iHHl1ZucHsIohOrUrRyQQnlkRrXZ6kpEbDBDG3N0mUvxMNL1sHEH7lD 2t8LLjwEg26Dx5ZvKUZ612GJkJgm3gwnAEwBXCONKTiaF8fYhaXSX0LCNOSn8EgajDrkvAKFYI6Wj xDHPloEZhxxEYJE/L4nQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jdxKZ-0005V0-EH; Wed, 27 May 2020 14:46:55 +0000 Received: from mail-il1-x144.google.com ([2607:f8b0:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jdxKW-0005QR-2a for linux-arm-kernel@lists.infradead.org; Wed, 27 May 2020 14:46:53 +0000 Received: by mail-il1-x144.google.com with SMTP id 9so5787209ilg.12 for ; Wed, 27 May 2020 07:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AU7716CyemDmasYys+I/AcpiH3oj4x9jWwzzxX5tgKU=; b=VStnWt6jTjFgaMVpk3oAYnsncjATXU/wAutYtmJZxldXplcS0pQN70hvvNDVsOPkH4 vnpNBR2ZdymxIB23xtSA8Lf6Q+U1apKa27CyqmEcDbIor/6l6or9W2gJF5nwV4rqyhy5 zn5mI5nrRB5YSUzlGDB5NcEQTR9RL2pEiZTE8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AU7716CyemDmasYys+I/AcpiH3oj4x9jWwzzxX5tgKU=; b=H26LU9dY8aRS4xz6b1i0VREnHwJsnVeVdDrPnO6KR8CyUJEatUffIoMQB42eT9NbYV 1pv4sCK99LkjllFriESmzX4wu5RfJyZMCAdO7bn8YE+4Ty9MGQuWlqzPcf9GLKscEB+8 Nz7VuY2cKsFodtu4UdxJrkBrNZJ3rsK1JDfuunUAYQl4hErfCLh2ZK1y8IppnQb8d54O wXtr6xjA4yI7gDLAekXxDzALMvpQ98VW0FGKBQX+Tr6tf31bFoAmQkjgMq17vuhkL6Cx XxqICvGgTJw276X6/ubO64gU1sQMtbdq4P6DgB6ez0vioQ6uiliwOOxHuCqRRpAqszVF 17CA== X-Gm-Message-State: AOAM532XsSkyfDabjsX46MMUf7+nxXPwBPmg0N2tOX3qsyWtpPWXnihP j32WI4eFiBTlO/m1q5nLsznJPKg7wM58ZBIDBwaADXbgH6uKsQ== X-Google-Smtp-Source: ABdhPJzUVd1aHH7lzmeRjgv7wJnpzxeLVtfR5lAOrmZRujWuS3ksAZB8tphWnFf4uD7EhaGC6PT22n7EI0O6IBqmsk8= X-Received: by 2002:a92:d182:: with SMTP id z2mr6049581ilz.47.1590590811109; Wed, 27 May 2020 07:46:51 -0700 (PDT) MIME-Version: 1.0 References: <20200403094033.8288-1-xia.jiang@mediatek.com> <20200403094033.8288-7-xia.jiang@mediatek.com> <20200521153257.GF209565@chromium.org> <1590544320.12671.10.camel@mhfsdcap03> In-Reply-To: <1590544320.12671.10.camel@mhfsdcap03> From: Tomasz Figa Date: Wed, 27 May 2020 16:46:39 +0200 Message-ID: Subject: Re: [PATCH v8 06/14] media: platform: Improve the implementation of the system PM ops To: Xia Jiang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200527_074652_114396_024DEC5B X-CRM114-Status: GOOD ( 27.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicolas Boichat , linux-devicetree , Hsu Wei-Cheng , srv_heupstream , Rick Chang , Sergey Senozhatsky , Linux Kernel Mailing List , maoguang.meng@mediatek.com, Mauro Carvalho Chehab , Sj Huang , Rob Herring , Matthias Brugger , Hans Verkuil , "moderated list:ARM/Mediatek SoC support" , Marek Szyprowski , "list@263.net:IOMMU DRIVERS , Joerg Roedel , " , Linux Media Mailing List Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, May 27, 2020 at 3:58 AM Xia Jiang wrote: > > On Thu, 2020-05-21 at 15:32 +0000, Tomasz Figa wrote: > > Hi Xia, > > > > On Fri, Apr 03, 2020 at 05:40:25PM +0800, Xia Jiang wrote: > > > Cancel reset hw operation in suspend and resume function because this > > > will be done in device_run(). > > > > This and... > > > > > Add spin_lock and unlock operation in irq and resume function to make > > > sure that the current frame is processed completely before suspend. > > > > ...this are two separate changes. Please split. > > > > > > > > Signed-off-by: Xia Jiang > > > --- > > > drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 11 +++++++++-- > > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > > > index dd5cadd101ef..2fa3711fdc9b 100644 > > > --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > > > +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > > > @@ -911,6 +911,8 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv) > > > u32 dec_ret; > > > int i; > > > > > > + spin_lock(&jpeg->hw_lock); > > > + > > > > nit: For consistency, it is recommended to always use the same, i.e. the > > strongest, spin_(un)lock_ primitives when operating on the same spinlock. > > In this case it would be the irqsave(restore) variants. > > > > > dec_ret = mtk_jpeg_dec_get_int_status(jpeg->dec_reg_base); > > > dec_irq_ret = mtk_jpeg_dec_enum_result(dec_ret); > > > ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev); > > > @@ -941,6 +943,7 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv) > > > v4l2_m2m_buf_done(src_buf, buf_state); > > > v4l2_m2m_buf_done(dst_buf, buf_state); > > > v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); > > > + spin_unlock(&jpeg->hw_lock); > > > pm_runtime_put_sync(ctx->jpeg->dev); > > > return IRQ_HANDLED; > > > } > > > @@ -1191,7 +1194,6 @@ static __maybe_unused int mtk_jpeg_pm_suspend(struct device *dev) > > > { > > > struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev); > > > > > > - mtk_jpeg_dec_reset(jpeg->dec_reg_base); > > > mtk_jpeg_clk_off(jpeg); > > > > > > return 0; > > > @@ -1202,19 +1204,24 @@ static __maybe_unused int mtk_jpeg_pm_resume(struct device *dev) > > > struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev); > > > > > > mtk_jpeg_clk_on(jpeg); > > > - mtk_jpeg_dec_reset(jpeg->dec_reg_base); > > > > > > return 0; > > > } > > > > > > static __maybe_unused int mtk_jpeg_suspend(struct device *dev) > > > { > > > + struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev); > > > + unsigned long flags; > > > int ret; > > > > > > if (pm_runtime_suspended(dev)) > > > return 0; > > > > > > + spin_lock_irqsave(&jpeg->hw_lock, flags); > > > > What does this spinlock protect us from? I can see that it would prevent > > the interrupt handler from being called, but is it okay to suspend the > > system without handling the interrupt? > Dear Tomasz, > I mean that if current image is processed in irq handler,suspend > function can not get the lock(it was locked in irq handler).Should I > move the spin_lock_irqsave(&jpeg->hw_lock, flags) to the start location > of suspend function or Do we have any guarantee that the interrupt handler would be executed and acquire the spinlock before mtk_jpeg_suspend() is called? > use wait_event_timeout() to handle the interrupt > before suspend? Yes, that would indeed work better. :) However, please refer to the v4l2_m2m suspend/resume helpers [1] and the MTK FD driver [2] for how to implement this nicely. [1] https://patchwork.kernel.org/patch/11272917/ [2] https://patchwork.kernel.org/patch/11272903/ Best regards, Tomasz _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel