From patchwork Tue Nov 8 13:29:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9417379 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8F2DA60585 for ; Tue, 8 Nov 2016 13:31:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80B3229114 for ; Tue, 8 Nov 2016 13:31:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7521829122; Tue, 8 Nov 2016 13:31:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0BAD29114 for ; Tue, 8 Nov 2016 13:31:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751554AbcKHNbN (ORCPT ); Tue, 8 Nov 2016 08:31:13 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:11982 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752028AbcKHNa1 (ORCPT ); Tue, 8 Nov 2016 08:30:27 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OGB003UBS6HXQ30@mailout1.w1.samsung.com>; Tue, 08 Nov 2016 13:30:17 +0000 (GMT) Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20161108133017eucas1p2a5041ad634a5861b23e59d3bb1982124~FFZ0ToHR-0273202732eucas1p2B; Tue, 8 Nov 2016 13:30:17 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges5.samsung.com (EUCPMTA) with SMTP id 12.E9.19540.863D1285; Tue, 8 Nov 2016 13:30:16 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20161108133016eucas1p27a25afd3a49bfc1e3e41c5a32e022f07~FFZzpFQUu0080000800eucas1p2M; Tue, 8 Nov 2016 13:30:16 +0000 (GMT) X-AuditID: cbfec7f5-f79ce6d000004c54-78-5821d368cb64 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 3A.97.07726.763D1285; Tue, 8 Nov 2016 13:30:15 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OGB005BFS5J9G30@eusync1.samsung.com>; Tue, 08 Nov 2016 13:30:16 +0000 (GMT) From: Marek Szyprowski To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, Joerg Roedel Cc: Marek Szyprowski , Inki Dae , Kukjin Kim , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , "Rafael J. Wysocki" , Mark Brown , "Luis R. Rodriguez" , Greg Kroah-Hartman , Tomeu Vizoso , Lukas Wunner , Kevin Hilman , Tobias Jakobi , Tomasz Figa Subject: [PATCH v6 3/7] iommu/exynos: Simplify internal enable/disable functions Date: Tue, 08 Nov 2016 14:29:20 +0100 Message-id: <1478611764-6473-4-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1478611764-6473-1-git-send-email-m.szyprowski@samsung.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KPExsVy+t/xy7rplxUjDM4skLfYOGM9q8XUh0/Y LJoXr2ezmHR/AovFgv3WFp2zN7Bb9D9+zWzxdPNjJovz54Hcy7vmsFl87j3CaDHj/D4mixfP pS3WHrnLbnFjwlNGizOnL7FatK3+wGqxatcfRou+tZfYHIQ9nhycx+Sx4+4SRo+ds+6ye2xa 1cnmsX/uGnaPyTeWM3r8O8buseVqO4tH35ZVjB6fN8l5zGjfxhrAHeVmk5GamJJapJCal5yf kpmXbqsUGuKma6GkkJeYm2qrFKHrGxKkpFCWmFMK5BkZoAEH5wD3YCV9uwS3jL1/DrEUbLWq aJu1gbWB8YBBFyMnh4SAicTMnctYIGwxiQv31rN1MXJxCAksYZS4eWkPI0hCSKCJSeJlUw2I zSZgKNH1tgusSERgMaNEw6EpjCAOs8AxFonFPQeZQaqEBQIkuudtBrNZBFQlTk59DraCV8Bd 4u+mbawQ6+QkTh6bDGZzCnhInFjxkAlim7vErw3P2Ccw8i5gZFjFKJJaWpybnltsqFecmFtc mpeul5yfu4kRGH3bjv3cvIPx0sbgQ4wCHIxKPLwv+hUihFgTy4orcw8xSnAwK4nwXj6nGCHE m5JYWZValB9fVJqTWnyI0RToqInMUqLJ+cDEkFcSb2hiaG5paGRsYWFuZKQkzlvy4Uq4kEB6 YklqdmpqQWoRTB8TB6dUA6Oq3/dLz3+H9RopbL/rm879RfrKsxL9nJfbE2bucThvfX17WeyG JQd+Trhxr+bjz55T/+o2dnuEL9x94WXRGvOFEvGztKsSg76tripS/Kw06YiLx5S5meJhyn17 tqm581ipPTl709Vkp09GVtx55tOJIn/nTNmUPdHt8aNpxVLT1iwLv7ZmAfMFJZbijERDLeai 4kQAeNa1q9QCAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161108133016eucas1p27a25afd3a49bfc1e3e41c5a32e022f07 X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRtT?= =?UTF-8?B?YW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161108133016eucas1p27a25afd3a49bfc1e3e41c5a32e022f07 X-RootMTR: 20161108133016eucas1p27a25afd3a49bfc1e3e41c5a32e022f07 References: <1478611764-6473-1-git-send-email-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove remaining leftovers of the ref-count related code in the __sysmmu_enable/disable functions inline __sysmmu_enable/disable_nocount to them. Suspend/resume callbacks now checks if master device is set for given SYSMMU controller instead of relying on the activation count. Signed-off-by: Marek Szyprowski --- drivers/iommu/exynos-iommu.c | 104 ++++++++++++------------------------------- 1 file changed, 29 insertions(+), 75 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 4056228..f45b274 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -237,8 +237,8 @@ struct sysmmu_drvdata { struct clk *aclk; /* SYSMMU's aclk clock */ struct clk *pclk; /* SYSMMU's pclk clock */ struct clk *clk_master; /* master's device clock */ - int activations; /* number of calls to sysmmu_enable */ spinlock_t lock; /* lock for modyfying state */ + int active; /* current status */ struct exynos_iommu_domain *domain; /* domain we belong to */ struct list_head domain_node; /* node for domain clients list */ struct list_head owner_node; /* node for owner controllers list */ @@ -251,25 +251,6 @@ static struct exynos_iommu_domain *to_exynos_domain(struct iommu_domain *dom) return container_of(dom, struct exynos_iommu_domain, domain); } -static bool set_sysmmu_active(struct sysmmu_drvdata *data) -{ - /* return true if the System MMU was not active previously - and it needs to be initialized */ - return ++data->activations == 1; -} - -static bool set_sysmmu_inactive(struct sysmmu_drvdata *data) -{ - /* return true if the System MMU is needed to be disabled */ - BUG_ON(data->activations < 1); - return --data->activations == 0; -} - -static bool is_sysmmu_active(struct sysmmu_drvdata *data) -{ - return data->activations > 0; -} - static void sysmmu_unblock(struct sysmmu_drvdata *data) { writel(CTRL_ENABLE, data->sfrbase + REG_MMU_CTRL); @@ -388,7 +369,7 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) unsigned short reg_status, reg_clear; int ret = -ENOSYS; - WARN_ON(!is_sysmmu_active(data)); + WARN_ON(!data->active); if (MMU_MAJ_VER(data->version) < 5) { reg_status = REG_INT_STATUS; @@ -434,37 +415,19 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) return IRQ_HANDLED; } -static void __sysmmu_disable_nocount(struct sysmmu_drvdata *data) +static void __sysmmu_disable(struct sysmmu_drvdata *data) { + unsigned long flags; + clk_enable(data->clk_master); + spin_lock_irqsave(&data->lock, flags); writel(CTRL_DISABLE, data->sfrbase + REG_MMU_CTRL); writel(0, data->sfrbase + REG_MMU_CFG); - - __sysmmu_disable_clocks(data); -} - -static bool __sysmmu_disable(struct sysmmu_drvdata *data) -{ - bool disabled; - unsigned long flags; - - spin_lock_irqsave(&data->lock, flags); - - disabled = set_sysmmu_inactive(data); - - if (disabled) { - data->pgtable = 0; - data->domain = NULL; - - __sysmmu_disable_nocount(data); - - dev_dbg(data->sysmmu, "Disabled\n"); - } - + data->active = false; spin_unlock_irqrestore(&data->lock, flags); - return disabled; + __sysmmu_disable_clocks(data); } static void __sysmmu_init_config(struct sysmmu_drvdata *data) @@ -481,17 +444,19 @@ static void __sysmmu_init_config(struct sysmmu_drvdata *data) writel(cfg, data->sfrbase + REG_MMU_CFG); } -static void __sysmmu_enable_nocount(struct sysmmu_drvdata *data) +static void __sysmmu_enable(struct sysmmu_drvdata *data) { + unsigned long flags; + __sysmmu_enable_clocks(data); + spin_lock_irqsave(&data->lock, flags); writel(CTRL_BLOCK, data->sfrbase + REG_MMU_CTRL); - __sysmmu_init_config(data); - __sysmmu_set_ptbase(data, data->pgtable); - writel(CTRL_ENABLE, data->sfrbase + REG_MMU_CTRL); + data->active = true; + spin_unlock_irqrestore(&data->lock, flags); /* * SYSMMU driver keeps master's clock enabled only for the short @@ -502,37 +467,18 @@ static void __sysmmu_enable_nocount(struct sysmmu_drvdata *data) clk_disable(data->clk_master); } -static int __sysmmu_enable(struct sysmmu_drvdata *data, phys_addr_t pgtable, - struct exynos_iommu_domain *domain) -{ - unsigned long flags; - - spin_lock_irqsave(&data->lock, flags); - if (set_sysmmu_active(data)) { - data->pgtable = pgtable; - data->domain = domain; - __sysmmu_enable_nocount(data); - dev_dbg(data->sysmmu, "Enabled\n"); - } - spin_unlock_irqrestore(&data->lock, flags); - - return 0; -} - static void sysmmu_tlb_invalidate_flpdcache(struct sysmmu_drvdata *data, sysmmu_iova_t iova) { unsigned long flags; - spin_lock_irqsave(&data->lock, flags); - if (is_sysmmu_active(data) && data->version >= MAKE_MMU_VER(3, 3)) { + if (data->active && data->version >= MAKE_MMU_VER(3, 3)) { clk_enable(data->clk_master); __sysmmu_tlb_invalidate_entry(data, iova, 1); clk_disable(data->clk_master); } spin_unlock_irqrestore(&data->lock, flags); - } static void sysmmu_tlb_invalidate_entry(struct sysmmu_drvdata *data, @@ -541,7 +487,7 @@ static void sysmmu_tlb_invalidate_entry(struct sysmmu_drvdata *data, unsigned long flags; spin_lock_irqsave(&data->lock, flags); - if (is_sysmmu_active(data)) { + if (data->active) { unsigned int num_inv = 1; clk_enable(data->clk_master); @@ -652,10 +598,11 @@ static int __init exynos_sysmmu_probe(struct platform_device *pdev) static int exynos_sysmmu_suspend(struct device *dev) { struct sysmmu_drvdata *data = dev_get_drvdata(dev); + struct device *master = data->master; dev_dbg(dev, "suspend\n"); - if (is_sysmmu_active(data)) { - __sysmmu_disable_nocount(data); + if (master) { + __sysmmu_disable(data); pm_runtime_put(dev); } return 0; @@ -664,11 +611,12 @@ static int exynos_sysmmu_suspend(struct device *dev) static int exynos_sysmmu_resume(struct device *dev) { struct sysmmu_drvdata *data = dev_get_drvdata(dev); + struct device *master = data->master; dev_dbg(dev, "resume\n"); - if (is_sysmmu_active(data)) { + if (master) { pm_runtime_get_sync(dev); - __sysmmu_enable_nocount(data); + __sysmmu_enable(data); } return 0; } @@ -780,6 +728,8 @@ static void exynos_iommu_domain_free(struct iommu_domain *iommu_domain) list_for_each_entry_safe(data, next, &domain->clients, domain_node) { __sysmmu_disable(data); + data->pgtable = 0; + data->domain = NULL; data->master = NULL; list_del_init(&data->domain_node); } @@ -823,6 +773,8 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain, list_for_each_entry_safe(data, next, &domain->clients, domain_node) { __sysmmu_disable(data); data->master = NULL; + data->pgtable = 0; + data->domain = NULL; list_del_init(&data->domain_node); pm_runtime_put(data->sysmmu); } @@ -850,8 +802,10 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, exynos_iommu_detach_device(owner->domain, dev); list_for_each_entry(data, &owner->controllers, owner_node) { + data->pgtable = pagetable; + data->domain = domain; pm_runtime_get_sync(data->sysmmu); - __sysmmu_enable(data, pagetable, domain); + __sysmmu_enable(data); data->master = dev; spin_lock_irqsave(&domain->lock, flags);