Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp180052pxb; Fri, 8 Jan 2021 01:57:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOUzoOElJy0aLBt0+pJSI6JXhjJplkZsW5g/g8E230Af+uayymrEB0+XNvKja5qpUKCNDs X-Received: by 2002:a05:6402:1714:: with SMTP id y20mr4553347edu.360.1610099821082; Fri, 08 Jan 2021 01:57:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610099821; cv=none; d=google.com; s=arc-20160816; b=CZIgJ9Kgd1jyTEsPBOL+ZFuBg3xgN8HoWVe1fyFMNDLFUpqn+S7vuq07xQP4SUU9rc OOdNI6jSXmRid7fdcdj3bwcKxlW6ldiiZ5PE6w7dblj2mwk0vk+MXK6hlB3WTMdOVqUw 0VMUIKUjl6ocPgq3JgsuT2JS+puX0YJ/b+50xCkbyFN3314+comzSKsEB5cAmSXHLGDg UbXy3ZGi2JKKzh1KCd6vfkFdaDo1uThx2UFuqH+uTIL32KjACZa+j+2v1yKcxUU3czH9 2arNWOJdgNkzumzoJbHMW7eILzIoxRMag5q9eiLFEVIl4SNxYu2z+FWuzwIomcI9fZRy Z9fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=IK+44CzzfVfOGuAwRFDtWTWEbsmnaUyfEbndc+LLII0=; b=bMV6aoYM9vB9mcEBA3eIxZf8yOYtOXKE1Z1HSVLS9CZN+jH2QLJ8Ta9JZpf3q4P+e/ QQtaJHnJs2fqwg3J64y5183QFcZR7tMHCjIQjXtpX9zCAnKUddfFmesuU8EV8ewWKAVC WuW6pxCf1x3LVox8hy3PgwpHJXvRYHaXhKIm+tqoHlgyTbg7gUGLda56v5XfrvMgtYqV fV0Onb2Dk4AWS1/NFXvFr6NIGtBv+QxBYdvLFZQZYXjttQrII/Q3KeUBMV+oE6MNJJFO 6Rdxlob9LQlkB6KayAgPtJAPZCLPeDcWQ7Gho4DudpotTq+EJSBh+PYsXipELF85konc 7esQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=g5gIR+DZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f26si3175551ejd.704.2021.01.08.01.56.37; Fri, 08 Jan 2021 01:57:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=g5gIR+DZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728448AbhAHJzi (ORCPT + 99 others); Fri, 8 Jan 2021 04:55:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728216AbhAHJzi (ORCPT ); Fri, 8 Jan 2021 04:55:38 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 720AFC0612F5 for ; Fri, 8 Jan 2021 01:54:57 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id v26so1640759eds.13 for ; Fri, 08 Jan 2021 01:54:57 -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=kElVIDkRtLQheu2L9ronHeG0LgMZxhMpMjhUfZN+hEbkcF0STabdsUPXGgxke4cp9K /3ImZ8A+2RGs+Q9TSkbJ9zFFgKX4lmf8FkIIb5FeeXbpId0TDRWdz9DRwPrgMcYcvBzZ 2fv4VqnCaGevkIK/D14YcSMkQRmezh21utJy7xlir92F7QAZPBE8DQjAng10Gv2qjfMI YyrQtqFPqI/O0kxxp0dA5s+5FMWjnjmzgBrqgxAGeeD0EQq95bU6DVCh58tWq3lBRYKT KBtxQS796HHGEphz6jTzW/3ElTG/M8RMjZwSEpH4Uq22lb8q/Anfl5nWyXEW+T2ZzS8p SBpw== X-Gm-Message-State: AOAM530D2LnqEoDwEvLvKH5GJCeQEVCOkUCQmWwu/Xt8DwigFy7M81jt rHfNkyw7EftKV8Q5y3lkJUVqCG3IDyxTmw== X-Received: by 2002:a05:6402:1352:: with SMTP id y18mr4688557edw.178.1610099695958; Fri, 08 Jan 2021 01:54:55 -0800 (PST) Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com. [209.85.128.53]) by smtp.gmail.com with ESMTPSA id g10sm3530623edu.97.2021.01.08.01.54.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Jan 2021 01:54:54 -0800 (PST) Received: by mail-wm1-f53.google.com with SMTP id c124so7279952wma.5 for ; Fri, 08 Jan 2021 01:54:54 -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 Cc: Joerg Roedel , Matthias Brugger , Rob Herring , Will Deacon , Robin Murphy , youlin.pei@mediatek.com, linux-devicetree , Nicolas Boichat , srv_heupstream , chao.hao@mediatek.com, Linux Kernel Mailing List , Evan Green , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , "moderated list:ARM/Mediatek SoC support" , Krzysztof Kozlowski , anan.sun@mediatek.com, "list@263.net:IOMMU DRIVERS , Joerg Roedel ," Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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]