From patchwork Tue Aug 5 10:47:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 34933 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DCD2820523 for ; Tue, 5 Aug 2014 10:50:49 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id eu11sf5085295pac.7 for ; Tue, 05 Aug 2014 03:50:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=dyekqNwqN4+cCOnviKzUDczj19xyquFF2fsivMKYRDo=; b=JSOmvCIhWxmYGqYyaZn/TAt/1jg97QRgDYRKzAspo+qe+4U57GciCvSGLubc9+VxNR odEFH94Ybf/ic4tKjgXgcwSk2XGJqOBPmqmS+NCRcCmk8fVPU/SGK5/0/6XrXlhvv+Gt OmmwSy6Q9uCmmPrV2HHo5og1rjmC8a+MpfEbgtM6sN1iDISNVOcxyfWAoDX+yw7D2mzL WM34C1X9g7VHcSWb6hMauIIuLOp08ykiwr5HDhJj8fDZxmTLBI9mLPK3EzyP1/IjVCsQ hKnrb/nLJFWqCEsJh8awKY3swXmrR1K8WoNtNlLiJHfHTTOlmRWZxhBdwjBgFQznGDfI kiQw== X-Gm-Message-State: ALoCoQl+w+bbiMzsG0/vt7X/NoW8VbETEz2L4lvZiKDYNkOiqM4MGssIJD6QJ/VPZ36nMiIbRCgS X-Received: by 10.66.145.129 with SMTP id su1mr1508029pab.17.1407235849115; Tue, 05 Aug 2014 03:50:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.18 with SMTP id z18ls216072qge.74.gmail; Tue, 05 Aug 2014 03:50:49 -0700 (PDT) X-Received: by 10.220.82.202 with SMTP id c10mr2299967vcl.31.1407235849003; Tue, 05 Aug 2014 03:50:49 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id uy6si788835vcb.23.2014.08.05.03.50.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Aug 2014 03:50:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id le20so1122977vcb.14 for ; Tue, 05 Aug 2014 03:50:48 -0700 (PDT) X-Received: by 10.220.7.131 with SMTP id d3mr996055vcd.49.1407235848870; Tue, 05 Aug 2014 03:50:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp374674vcb; Tue, 5 Aug 2014 03:50:48 -0700 (PDT) X-Received: by 10.68.132.42 with SMTP id or10mr3297627pbb.80.1407235847268; Tue, 05 Aug 2014 03:50:47 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zs3si1518068pac.90.2014.08.05.03.50.46 for ; Tue, 05 Aug 2014 03:50:47 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755599AbaHEKup (ORCPT + 21 others); Tue, 5 Aug 2014 06:50:45 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:9371 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754964AbaHEKtM (ORCPT ); Tue, 5 Aug 2014 06:49:12 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N9T00MLUY1GQI90@mailout2.w1.samsung.com>; Tue, 05 Aug 2014 11:48:52 +0100 (BST) X-AuditID: cbfec7f4-b7f156d0000063c7-e8-53e0b6a6e7db Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id E3.2C.25543.6A6B0E35; Tue, 05 Aug 2014 11:49:10 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N9T0057MY17SE80@eusync3.samsung.com>; Tue, 05 Aug 2014 11:49:10 +0100 (BST) From: Marek Szyprowski To: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , linaro-mm-sig@lists.linaro.org, Arnd Bergmann , Shaik Ameer Basha , Cho KyongHo , Joerg Roedel , Thierry Reding , Olof Johansson , Laurent Pinchart , Rob Herring , Greg Kroah-Hartman , "Rafael J. Wysocki" , Inki Dae , Kukjin Kim , Sylwester Nawrocki , Tomasz Figa , Kyungmin Park Subject: [PATCH 25/29] iommu: exynos: add support for runtime_pm Date: Tue, 05 Aug 2014 12:47:53 +0200 Message-id: <1407235677-26324-26-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> References: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBLMWRmVeSWpSXmKPExsVy+t/xq7rLtj0INphzVcvi76Rj7BbNi9ez WUy6P4HFYsF+a4vO2RvYLXoXXGWzONv0ht2ic+ISdosvVx4yWWx6fI3V4vKuOWwWM87vY7JY e+Quu8Wp65/ZLP71HmS0OHP6EqvF/z072C0Ov2lntTjycDe7xapdfxgtbv/mcxD1eHJwHpPH 71+TGD12zrrL7jG7Yyarx6ZVnWwe++euYffYvKTe4/a/x8wek28sZ/S4cqKJ1aO3+R2bx5ar 7SwefVtWMXp83iQXwBfFZZOSmpNZllqkb5fAlfHw1nLWgsNKFXsXHWZsYDwh08XIySEhYCJx vPk2C4QtJnHh3nq2LkYuDiGBpYwSpzbdYIJw+pgk3q7ewApSxSZgKNH1tgusSkSgl1Giv+kH WBWzwDpWif2918FmCQs4SDxZt5sRxGYRUJVoe/mVDcTmFfCUWHJhAivEPjmJ/y9XMIHYnEDx wzcPgMWFBDwkfm5Ywz6BkXcBI8MqRtHU0uSC4qT0XEO94sTc4tK8dL3k/NxNjJDY+bKDcfEx q0OMAhyMSjy8BqfvBguxJpYVV+YeYpTgYFYS4ZVY8yBYiDclsbIqtSg/vqg0J7X4ECMTB6dU A2Pj6gvX5f5kzPgmoXtm58+srkVKNm9esf7Y+PblYw7Z851Hbsaff35p/6k7RZNdjWZNjFNb tfnai6Wi0r7hq1hNF9RdfNu+OZ5pYeKUK5euur96eHDiR19RWYGeVbuy2Oa+PlWVUHrGz6P6 bK/A9p4roQtSrKp19aWty2uvVq+vElWI5gjdc6pUiaU4I9FQi7moOBEAL9euwnsCAAA= Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch enables support for runtime pm for SYSMMU controllers. State of each controller is saved before master's device power domain is turned off and restored after it has been turned on. exynos_iommu_attach_device() function might be called anytime, even when power domain for master's device has been turned off, so to let SYSMMU controllers to access its registers, a call to pm_runtime_get_sync() has to be done, which turns on the power domain, which SYSMMU belongs to. Later, once SYSMMU has been enabled, a call to pm_runtime_put() lets runtime pm to turn off the power domain if there are no other devices enabled. This way, the SYSMMU drivers get a genpd pm event and save its state with sysmmu_save_state() function. Signed-off-by: Marek Szyprowski --- drivers/iommu/exynos-iommu.c | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 336b2f8..5cd91b11 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -208,6 +209,7 @@ struct sysmmu_drvdata { struct clk *clk; struct clk *clk_master; int activations; + int suspended; spinlock_t lock; struct iommu_domain *domain; struct list_head domain_node; @@ -217,6 +219,7 @@ struct sysmmu_drvdata { const char *name; dma_addr_t base; size_t size; + struct notifier_block pm_notifier; }; static bool set_sysmmu_active(struct sysmmu_drvdata *data) @@ -235,7 +238,7 @@ static bool set_sysmmu_inactive(struct sysmmu_drvdata *data) static bool is_sysmmu_active(struct sysmmu_drvdata *data) { - return data->activations > 0; + return (!data->suspended && data->activations > 0); } static void sysmmu_unblock(void __iomem *sfrbase) @@ -528,6 +531,51 @@ static void sysmmu_tlb_invalidate_entry(struct sysmmu_drvdata *data, spin_unlock_irqrestore(&data->lock, flags); } +static void sysmmu_restore_state(struct sysmmu_drvdata *data) +{ + unsigned long flags; + + spin_lock_irqsave(&data->lock, flags); + if (data->activations > 0) { + data->suspended = false; + __sysmmu_enable_nocount(data); + dev_dbg(data->sysmmu, "restored state\n"); + } + spin_unlock_irqrestore(&data->lock, flags); +} + +static void sysmmu_save_state(struct sysmmu_drvdata *data) +{ + unsigned long flags; + + spin_lock_irqsave(&data->lock, flags); + if (data->activations > 0) { + __sysmmu_disable_nocount(data); + data->suspended = true; + dev_dbg(data->sysmmu, "saved state\n"); + } + spin_unlock_irqrestore(&data->lock, flags); +} + +static int sysmmu_runtime_genpd_event(struct notifier_block *this, + unsigned long event, void *ptr) +{ + struct sysmmu_drvdata *data; + + data = container_of(this, struct sysmmu_drvdata, pm_notifier); + + switch (event) { + case PM_GENPD_POST_POWER_ON: + sysmmu_restore_state(data); + break; + case PM_GENPD_POWER_OFF_PREPARE: + sysmmu_save_state(data); + break; + } + + return NOTIFY_DONE; +} + static int __init exynos_sysmmu_probe(struct platform_device *pdev) { int irq, ret; @@ -580,6 +628,7 @@ static int __init exynos_sysmmu_probe(struct platform_device *pdev) } data->sysmmu = dev; + data->pm_notifier.notifier_call = sysmmu_runtime_genpd_event; /* default io address space parameters */ data->base = SZ_1G; @@ -708,6 +757,7 @@ static int exynos_iommu_attach_device(struct iommu_domain *domain, return -ENODEV; list_for_each_entry(data, &owner->clients, owner_node) { + pm_runtime_get_sync(data->sysmmu); ret = __sysmmu_enable(data, pagetable, domain); if (ret >= 0) { data->master = dev; @@ -716,6 +766,7 @@ static int exynos_iommu_attach_device(struct iommu_domain *domain, list_add_tail(&data->domain_node, &priv->clients); spin_unlock_irqrestore(&priv->lock, flags); } + pm_runtime_put(data->sysmmu); } if (ret < 0) { @@ -1156,6 +1207,7 @@ static int __init_master_sysmmu(struct device *dev) } list_add_tail(&data->owner_node, &owner->clients); + pm_genpd_register_notifier(dev, &data->pm_notifier); i++; }