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=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 36423C433E0 for ; Fri, 8 Jan 2021 10:04:55 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 BBC2A23447 for ; Fri, 8 Jan 2021 10:04:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBC2A23447 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+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=merlin.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=0o6dEwonL+k0uB5GESZFKT48ygOzvKEgIBZC0iFBDUo=; b=rAVdhMxiRHBgKX4vM28IsANNt VJVK1V8eFllT2TNYnCzr6IqZbm/gXqZRA6wTuslv9E9Y18KeykXwbsy3vUxHe7YvR8UKs+dKbURCX 4JeZ3ZlE2QMVNMb+Pd7hhsNmsKxZ4ChqRDiQs3y8THHNaFf13smdaGNG2iWO1CukiRwEuUHZICFNW MvEGJKgBVC6xAVnwNwF7Zf/1wq7HffSw7QV+92lf8YdAt9E1lMIQzsW3AtFUt3XmLLA1z1Bbo70M7 yplsGmPUoQ52YNgp/Y0I9wVZdHWfSwQAJNgTds5UAsT3z5A2eMO7nAYq8tt+V0Ke7Yk0DtxDkOszE WLFoR+0Vw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kxobb-0003AL-Gy; Fri, 08 Jan 2021 10:02:51 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kxobZ-00039U-4M for linux-arm-kernel@lists.infradead.org; Fri, 08 Jan 2021 10:02:49 +0000 Received: by mail-ed1-x531.google.com with SMTP id dk8so10690949edb.1 for ; Fri, 08 Jan 2021 02:02:44 -0800 (PST) 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=IK+44CzzfVfOGuAwRFDtWTWEbsmnaUyfEbndc+LLII0=; b=g5gIR+DZeDOkUgh3bwbifA/QvR8Xca1KXNdDaE6fShDjJgoMxK33BxMUJ56GfRGQUu 0RBWDEtQW/NL3kY1bH/fXuGS2/yEn8TdrlH9B+UIBprw0cgqUonLVtCVSQrCRz4P6+XY pDUnYebAcRC+MTAkyoyGQBgZxuGydzUdulvgo= 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=IK+44CzzfVfOGuAwRFDtWTWEbsmnaUyfEbndc+LLII0=; b=ps5kyusMovu/gsVqsT5rDPLMxQVNlZGMA/sS9hl/cocGNScBT+aoxj7Uw3Z5a0wSQl 6J5DkG/QIgYd1Icx97BfWmboO+fMxGe0o0yU0TDJwirOtIvre0Hp1WbE8DAIfZJyOgit J/pr7MEvpLNOfyL84g/uy6sFPqr0nupc4FgGFY3tLZKMl14HGH9sztKjMgQ6gRnbnjuc re3m2597ht7BAXp5sO0FeG92GUp7dnJEir7pT7rjeYzhDlDrI2DqP+6HuzDpccxsAq2g SNkG955JyvY+wXRcNV43XULh/J/FUhBZIsuNnW+gt5hOgTwbp3CJXoTR/CFwFlU08CMe K7qQ== X-Gm-Message-State: AOAM532uV08BaUNSuKQvgu1qBGIfZyL6xoXL06y8P91us/bgHxYpIQDR L+DHvGAYgjC+YhUKh060ldZnjjjzf7bFyQ== X-Google-Smtp-Source: ABdhPJycTjb5rArkpSWtgq50MqYK1FR5WsRe7CpMGlMydgiChMxFQmHvVW54cBmSRBw0Hv+jrnOo7A== X-Received: by 2002:aa7:c5d6:: with SMTP id h22mr4616358eds.82.1610100163575; Fri, 08 Jan 2021 02:02:43 -0800 (PST) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com. [209.85.128.42]) by smtp.gmail.com with ESMTPSA id lz17sm3354119ejb.19.2021.01.08.02.02.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Jan 2021 02:02:43 -0800 (PST) Received: by mail-wm1-f42.google.com with SMTP id y23so7903125wmi.1 for ; Fri, 08 Jan 2021 02:02:43 -0800 (PST) X-Received: by 2002:a7b:c92b:: with SMTP id h11mr2296894wml.99.1610099693765; Fri, 08 Jan 2021 01:54:53 -0800 (PST) MIME-Version: 1.0 References: <20201209080102.26626-1-yong.wu@mediatek.com> <1609239977.26323.292.camel@mhfsdcap03> In-Reply-To: <1609239977.26323.292.camel@mhfsdcap03> From: Tomasz Figa Date: Fri, 8 Jan 2021 18:54:41 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 18/27] iommu/mediatek: Add power-domain operation To: Yong Wu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210108_050249_195813_3070B4A4 X-CRM114-Status: GOOD ( 35.91 ) 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: youlin.pei@mediatek.com, linux-devicetree , Nicolas Boichat , srv_heupstream , Will Deacon , Joerg Roedel , Linux Kernel Mailing List , Evan Green , chao.hao@mediatek.com, "list@263.net:IOMMU DRIVERS , Joerg Roedel , " , Rob Herring , "moderated list:ARM/Mediatek SoC support" , Krzysztof Kozlowski , Matthias Brugger , anan.sun@mediatek.com, Robin Murphy , "list@263.net:IOMMU DRIVERS , Joerg Roedel , " Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Dec 29, 2020 at 8:06 PM Yong Wu wrote: > > On Wed, 2020-12-23 at 17:36 +0900, Tomasz Figa wrote: > > On Wed, Dec 09, 2020 at 04:00:53PM +0800, Yong Wu wrote: > > > In the previous SoC, the M4U HW is in the EMI power domain which is > > > always on. the latest M4U is in the display power domain which may be > > > turned on/off, thus we have to add pm_runtime interface for it. > > > > > > When the engine work, the engine always enable the power and clocks for > > > smi-larb/smi-common, then the M4U's power will always be powered on > > > automatically via the device link with smi-common. > > > > > > Note: we don't enable the M4U power in iommu_map/unmap for tlb flush. > > > If its power already is on, of course it is ok. if the power is off, > > > the main tlb will be reset while M4U power on, thus the tlb flush while > > > m4u power off is unnecessary, just skip it. > > > > > > There will be one case that pm runctime status is not expected when tlb > > > flush. After boot, the display may call dma_alloc_attrs before it call > > > pm_runtime_get(disp-dev), then the m4u's pm status is not active inside > > > the dma_alloc_attrs. Since it only happens after boot, the tlb is clean > > > at that time, I also think this is ok. > > > > > > Signed-off-by: Yong Wu > > > --- > > > drivers/iommu/mtk_iommu.c | 41 +++++++++++++++++++++++++++++++++------ > > > 1 file changed, 35 insertions(+), 6 deletions(-) > > > > > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > > > index 6fe3ee2b2bf5..0e9c03cbab32 100644 > > > --- a/drivers/iommu/mtk_iommu.c > > > +++ b/drivers/iommu/mtk_iommu.c > > > @@ -184,6 +184,8 @@ static void mtk_iommu_tlb_flush_all(void *cookie) > > > struct mtk_iommu_data *data = cookie; > > > > > > for_each_m4u(data) { > > > + if (!pm_runtime_active(data->dev)) > > > + continue; > > > > Is it guaranteed that the status is active in the check above, but then > > the process is preempted and it goes down here? > > > > Shouldn't we do something like below? > > > > ret = pm_runtime_get_if_active(); > > if (!ret) > > continue; > > if (ret < 0) > > // handle error > > > > // Flush > > > > pm_runtime_put(); > > Make sense. Thanks. There is a comment in arm_smmu.c "avoid touching > dev->power.lock in fastpaths". To avoid this here too(we have many SoC > don't have power-domain). then the code will be like: > > bool has_pm = !!data->dev->pm_domain; > > if (has_pm) { > if (pm_runtime_get_if_in_use(data->dev) <= 0) > continue; > } > > xxxx > > if (has_pm) > pm_runtime_put(data->dev); Looks good to me, thanks. > > > > Similar comment to the other places being changed by this patch. > > > > > writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, > > > data->base + data->plat_data->inv_sel_reg); > > > writel_relaxed(F_ALL_INVLD, data->base + REG_MMU_INVALIDATE); > > > @@ -200,6 +202,10 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size, > > > u32 tmp; > > > > > > for_each_m4u(data) { > > > + /* skip tlb flush when pm is not active. */ > > > + if (!pm_runtime_active(data->dev)) > > > + continue; > > > + > > > spin_lock_irqsave(&data->tlb_lock, flags); > > > writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, > > > data->base + data->plat_data->inv_sel_reg); > [snip] _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel