Received: by 10.223.185.116 with SMTP id b49csp4575487wrg; Tue, 6 Mar 2018 19:26:22 -0800 (PST) X-Google-Smtp-Source: AG47ELtI92/DLiTuyvm9vkHvEx3/4goE87XwyTs+VF2ZpOUYGxpheLJJVvzgTKDCInm9xfGjfb8b X-Received: by 10.99.133.193 with SMTP id u184mr16533301pgd.401.1520393182047; Tue, 06 Mar 2018 19:26:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520393182; cv=none; d=google.com; s=arc-20160816; b=d3Qu1gFDy86OEvVlpXgGrQpzyfmaELsepsMe/SGKfNpvObHysg0Ky2xn19vDcLu0+a mBYsMaCPMZ7hfRiTHPmKSeM22KWuy8pNcZMpxz+lmHK6Y7LYbU/hcLxW3e8/5FPUq2gw VTwKy1r/tsFCDLIgq1cc08+5oYNY574pSueaCuiiDJIN/LYuXOD14IcCkxv5nGBKGyIR M2NC1RxIJ13BaJdpnJywn9dckwwOei6YO7xjOXkIaULcZ3R6uZ02LuqeAqwrJS5bXBln kRJ/qWRKYjYv/69oNBCuyB9VoPACk+jdDQa5GPumSQwVIfFCsEhg9o7D2NmKCULjpNjq yk3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=0mp5Z/vq7/WHubSaGWUf9oAPKbLxlbEa8vpXtIUGbAs=; b=umHcVQTAJIY5rbGEbA0Up7FlbZ4KPHaz1ukCiIiTCsyAORp7FIzZtQmdUjHbbq/P6X Nr+tTDmqFvg/lHink/WKD9wljgTfQFs1KLDEV7k8DvfblPKgdlWcdZXpC5Og4OR75wvo EozFouVBQhSg7o9WOUVRECD2PQVOdCeqazqpN0BOjzmv8MCaiw1yRloz004TByV7jxf7 n+FKH029MmE4mL/YTr6mQBBZKCzsg7MxnRV74NRlUkfD18G8tB1gbnHGOE6HHqryLF0L JvUpvRhRCCgTUvY2AKvY5hN146nMqq0LEobmEjQz9Yx2ylcsiUEieloSYG/7EOyUrM7c e0Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Q9l1H/Pc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id k7si2338799pgo.509.2018.03.06.19.26.07; Tue, 06 Mar 2018 19:26:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Q9l1H/Pc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S933294AbeCGDYw (ORCPT + 99 others); Tue, 6 Mar 2018 22:24:52 -0500 Received: from mail-vk0-f66.google.com ([209.85.213.66]:35182 "EHLO mail-vk0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933198AbeCGDYu (ORCPT ); Tue, 6 Mar 2018 22:24:50 -0500 Received: by mail-vk0-f66.google.com with SMTP id b65so515246vka.2 for ; Tue, 06 Mar 2018 19:24:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=0mp5Z/vq7/WHubSaGWUf9oAPKbLxlbEa8vpXtIUGbAs=; b=Q9l1H/PchfLuFxwonmhWaJwVweyRFMByiJCf/xr5oIduYbpFqV7slrxtWn0qsFbcKP G69MTwTuNzLGto0MyUB4nCgb+l6GJCky8CIOK0MgPRMBUFK3Gavxul5syTSNpKRtJeXL aYYhPz0I7TLPoxNfBC71I4HHAV7dG2nTePVaw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=0mp5Z/vq7/WHubSaGWUf9oAPKbLxlbEa8vpXtIUGbAs=; b=bowV863Sr5MwCSKc00qAUyDnGh8iif7iFwh9jpF7wEdtIphomARemRWhhG5C8btdg/ 9dP7dHhZiLR7UZNEmjJ9x9Rz2dDsSRLY4KePcNB53GNSFnbvk9YpJ5DkLSvRjK979aXR InhFlfYvnB2wrR8RQjucX9BM+KZS3HedqZpjJPkxwVmULHD0aptoOA7nBLAK3kQWZLJm VCCc99vCgrXEac/2DsMT4InhKvT+a/7UT2ANjVGOBca+GwxcF7gLD/+VjYWuTS+LCOEW f7S8NyZrXeMg98Y4wZ1XD5ilrdbPY89EHHTDW7JcAFAJVxo53+UZqPz8Z5m4sXKNrPGx JNxg== X-Gm-Message-State: APf1xPCIT7SLZvyMqvO7Xj0T/19D8Io7Ix0AZCPLYhHMU5mCrbBS3J/e t5dBIYYTjPr2bl7UZ69SK00KdufbjKY= X-Received: by 10.31.229.132 with SMTP id c126mr14801651vkh.73.1520393089200; Tue, 06 Mar 2018 19:24:49 -0800 (PST) Received: from mail-vk0-f51.google.com (mail-vk0-f51.google.com. [209.85.213.51]) by smtp.gmail.com with ESMTPSA id k5sm5555161uab.38.2018.03.06.19.24.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Mar 2018 19:24:47 -0800 (PST) Received: by mail-vk0-f51.google.com with SMTP id f6so506762vkh.6 for ; Tue, 06 Mar 2018 19:24:46 -0800 (PST) X-Received: by 10.31.98.135 with SMTP id w129mr14467781vkb.183.1520393086253; Tue, 06 Mar 2018 19:24:46 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.0.99 with HTTP; Tue, 6 Mar 2018 19:24:25 -0800 (PST) In-Reply-To: References: <20180306030252.3197-1-jeffy.chen@rock-chips.com> <20180306032759.29069-1-jeffy.chen@rock-chips.com> <20180306032759.29069-4-jeffy.chen@rock-chips.com> From: Tomasz Figa Date: Wed, 7 Mar 2018 12:24:25 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 13/14] iommu/rockchip: Add runtime PM support To: Jeffy Chen Cc: Linux Kernel Mailing List , Ricky Liang , Robin Murphy , simon xue , Heiko Stuebner , "open list:ARM/Rockchip SoC..." , "open list:IOMMU DRIVERS" , Joerg Roedel , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 6, 2018 at 7:07 PM, Tomasz Figa wrote: > Hi Jeffy, > > It looks like I missed some details of how runtime PM enable works > before, so we might be able to simplify things. Sorry for not getting > things right earlier. > > On Tue, Mar 6, 2018 at 12:27 PM, Jeffy Chen wrote: >> When the power domain is powered off, the IOMMU cannot be accessed and >> register programming must be deferred until the power domain becomes >> enabled. >> >> Add runtime PM support, and use runtime PM device link from IOMMU to >> master to startup and shutdown IOMMU. >> >> Signed-off-by: Jeffy Chen >> --- >> >> Changes in v7: >> Add WARN_ON in irq isr, and modify iommu archdata comment. >> >> Changes in v6: None >> Changes in v5: >> Avoid race about pm_runtime_get_if_in_use() and pm_runtime_enabled(). >> >> Changes in v4: None >> Changes in v3: >> Only call startup() and shutdown() when iommu attached. >> Remove pm_mutex. >> Check runtime PM disabled. >> Check pm_runtime in rk_iommu_irq(). >> >> Changes in v2: None >> >> drivers/iommu/rockchip-iommu.c | 189 ++++++++++++++++++++++++++++++++--------- >> 1 file changed, 148 insertions(+), 41 deletions(-) >> >> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c >> index 2448a0528e39..db08978203f7 100644 >> --- a/drivers/iommu/rockchip-iommu.c >> +++ b/drivers/iommu/rockchip-iommu.c >> @@ -22,6 +22,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> >> @@ -105,7 +106,14 @@ struct rk_iommu { >> struct iommu_domain *domain; /* domain to which iommu is attached */ >> }; >> >> +/** >> + * struct rk_iommudata - iommu archdata of master device. >> + * @link: device link with runtime PM integration from the master >> + * (consumer) to the IOMMU (supplier). >> + * @iommu: IOMMU of the master device. >> + */ >> struct rk_iommudata { >> + struct device_link *link; >> struct rk_iommu *iommu; >> }; >> >> @@ -518,7 +526,13 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id) >> u32 int_status; >> dma_addr_t iova; >> irqreturn_t ret = IRQ_NONE; >> - int i; >> + bool need_runtime_put; >> + int i, err; >> + >> + err = pm_runtime_get_if_in_use(iommu->dev); >> + if (WARN_ON(err <= 0 && err != -EINVAL)) >> + return ret; >> + need_runtime_put = err > 0; > > Actually, for our purposes, we can assume that runtime PM enable > status can be only changed by the driver itself. Looking at the LXR, > PM core also calls __pm_runtime_disable() before calling > .suspend_late() callback and pm_runtime_enable() after calling > .resume_early() callback, but we should be able to ignore this, > because we handle things in .suspend() callback in this driver. > > With this assumption in mind, all we need to do here is: > > if (WARN_ON(!pm_runtime_get_if_in_use(iommu->dev))) > return 0; > >> >> WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks)); >> >> @@ -570,6 +584,9 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id) >> >> clk_bulk_disable(iommu->num_clocks, iommu->clocks); >> >> + if (need_runtime_put) >> + pm_runtime_put(iommu->dev); > > if (pm_runtime_enabled()) > pm_runtime_put(iommu->dev); Actually, we don't even need this pm_runtime_enabled() check and can always call pm_runtime_put(), because at this point we would be only in either of cases: 1) runtime PM compiled in and enabled, so we got the enable count and need to put it, 2) runtime PM not compiled in, so pm_runtime_put() is a no-op. > >> + >> return ret; >> } >> >> @@ -611,10 +628,20 @@ static void rk_iommu_zap_iova(struct rk_iommu_domain *rk_domain, >> spin_lock_irqsave(&rk_domain->iommus_lock, flags); >> list_for_each(pos, &rk_domain->iommus) { >> struct rk_iommu *iommu; >> + int ret; >> + >> iommu = list_entry(pos, struct rk_iommu, node); >> - WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks)); >> - rk_iommu_zap_lines(iommu, iova, size); >> - clk_bulk_disable(iommu->num_clocks, iommu->clocks); >> + >> + /* Only zap TLBs of IOMMUs that are powered on. */ >> + ret = pm_runtime_get_if_in_use(iommu->dev); >> + if (ret > 0 || ret == -EINVAL) { > > if (pm_runtime_get_if_in_use(iommu->dev)) { > >> + WARN_ON(clk_bulk_enable(iommu->num_clocks, >> + iommu->clocks)); >> + rk_iommu_zap_lines(iommu, iova, size); >> + clk_bulk_disable(iommu->num_clocks, iommu->clocks); > > if (pm_runtime_enabled(iommu->dev)) > pm_runtime_put(iommu->dev); Same here. Best regards, Tomasz