From: JeffyChen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
To: Tomasz Figa <tfiga-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>,
open-Y9sIeH5OGRo@public.gmane.org,
list-Y9sIeH5OGRo@public.gmane.org,
Linux Kernel Mailing List
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Ricky Liang <jcliang-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
"open list:ARM/Rockchip SoC..."
<linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
"list-Y9sIeH5OGRo@public.gmane.org:IOMMU DRIVERS"
<iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH v7 13/14] iommu/rockchip: Add runtime PM support
Date: Wed, 07 Mar 2018 11:16:30 +0800 [thread overview]
Message-ID: <5A9F598E.4020704@rock-chips.com> (raw)
In-Reply-To: <CAAFQd5DPewKda7ThqMGKRvnArZ0X8ChD10E06nLZaNa-SBNdwA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
Hi Tomasz,
Thanks for your reply.
On 03/06/2018 06: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
hmm, right, the enable state should be the same during those functions.
will do it in the next version.
.
>
> On Tue, Mar 6, 2018 at 12:27 PM, Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org> 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 <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
>> ---
>>
>> 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 <linux/of_iommu.h>
>> #include <linux/of_platform.h>
>> #include <linux/platform_device.h>
>> +#include <linux/pm_runtime.h>
>> #include <linux/slab.h>
>> #include <linux/spinlock.h>
>>
>> @@ -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);
>
>> +
>> 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);
>
> And so on, in other places.
>
> Really sorry for the confusion before.
>
> Best regards,
> Tomasz
>
>
>
next prev parent reply other threads:[~2018-03-07 3:16 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 3:02 [PATCH v7 00/14] iommu/rockchip: Use OF_IOMMU Jeffy Chen
[not found] ` <20180306030252.3197-1-jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2018-03-06 3:02 ` [PATCH v7 01/14] iommu/rockchip: Prohibit unbind and remove Jeffy Chen
2018-03-07 12:55 ` Robin Murphy
2018-03-06 3:02 ` [PATCH v7 02/14] iommu/rockchip: Fix error handling in probe Jeffy Chen
[not found] ` <20180306030252.3197-3-jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2018-03-07 12:59 ` Robin Murphy
2018-03-06 3:02 ` [PATCH v7 03/14] iommu/rockchip: Request irqs in rk_iommu_probe() Jeffy Chen
[not found] ` <20180306030252.3197-4-jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2018-03-07 13:00 ` Robin Murphy
2018-03-06 3:21 ` [PATCH v7 04/14] iommu/rockchip: Fix error handling in attach Jeffy Chen
[not found] ` <20180306032113.22247-1-jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2018-03-06 3:21 ` [PATCH v7 05/14] iommu/rockchip: Use iopoll helpers to wait for hardware Jeffy Chen
2018-03-06 3:21 ` [PATCH v7 06/14] iommu/rockchip: Fix TLB flush of secondary IOMMUs Jeffy Chen
2018-03-06 3:21 ` [PATCH v7 08/14] iommu/rockchip: Control clocks needed to access the IOMMU Jeffy Chen
2018-03-06 3:21 ` [PATCH v7 07/14] ARM: dts: rockchip: add clocks in iommu nodes Jeffy Chen
2018-03-06 3:21 ` [PATCH v7 09/14] dt-bindings: iommu/rockchip: Add clock property Jeffy Chen
[not found] ` <20180306032113.22247-6-jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2018-03-07 13:01 ` Robin Murphy
2018-03-06 3:27 ` [PATCH v7 10/14] iommu/rockchip: Use IOMMU device for dma mapping operations Jeffy Chen
[not found] ` <20180306032759.29069-1-jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2018-03-06 3:27 ` [PATCH v7 11/14] iommu/rockchip: Use OF_IOMMU to attach devices automatically Jeffy Chen
2018-03-06 3:27 ` [PATCH v7 12/14] iommu/rockchip: Fix error handling in init Jeffy Chen
2018-03-06 3:27 ` [PATCH v7 13/14] iommu/rockchip: Add runtime PM support Jeffy Chen
[not found] ` <20180306032759.29069-4-jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2018-03-06 10:07 ` Tomasz Figa
[not found] ` <CAAFQd5DPewKda7ThqMGKRvnArZ0X8ChD10E06nLZaNa-SBNdwA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-03-07 3:16 ` JeffyChen [this message]
2018-03-07 3:26 ` Tomasz Figa
2018-03-07 3:24 ` Tomasz Figa
2018-03-06 3:27 ` [PATCH v7 14/14] iommu/rockchip: Support sharing IOMMU between masters Jeffy Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5A9F598E.4020704@rock-chips.com \
--to=jeffy.chen-tnx95d0mmh7dzftrwevzcw@public.gmane.org \
--cc=heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=jcliang-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=list-Y9sIeH5OGRo@public.gmane.org \
--cc=open-Y9sIeH5OGRo@public.gmane.org \
--cc=tfiga-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox