From patchwork Mon Jan 26 23:51:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 5713581 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F64F9F1D6 for ; Mon, 26 Jan 2015 23:58:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A86882018E for ; Mon, 26 Jan 2015 23:58:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E0A22201BC for ; Mon, 26 Jan 2015 23:57:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YFtVK-00008w-Cs; Mon, 26 Jan 2015 23:55:38 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YFtSU-0002PS-Kt; Mon, 26 Jan 2015 23:52:42 +0000 Received: from 8bytes.org ([2a01:238:4383:600:38bc:a715:4b6d:a889] helo=theia.8bytes.org) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YFtSR-0000xB-Fp; Mon, 26 Jan 2015 23:52:41 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id ADBD83F0; Tue, 27 Jan 2015 00:51:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1422316307; bh=/PCbIiKsupm++27GObYy92paFQMyXKLRG9w30y0u9Go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DlHyJVb1LoHqh5dnmnkZdNCxB8CmdLQA+xJu8hKOfrmvVJyj/9rvP0f6N6gxRY5wE 7OETOqH3XvsXdpCjtUGvui/ExJ6PXbkuCE3JavIZvm8JORVOD6ud1OEjm4K7qgDs2I LAhL2dfhG7cfQHVd+lRXEWu2Xk2sTLw6ftoVqnLPg8nAaMfgwfw7/WwT54DamraDHJ USlcecSNcLlz80S8ZyXe2HXtNxQTAw9wVRe0po/8sdJzdCx39lVZLdliwYdU/frlon 5piJXaHsWrWcg6Iwd5SWjnAvyh0VMj8NZW9zbC122tuMoXR1Gg4ESACeti3JJU6/l/ bNOEbC43kefMQ== From: Joerg Roedel To: iommu@lists.linux-foundation.org Subject: [PATCH 10/15] iommu/msm: Make use of domain_alloc and domain_free Date: Tue, 27 Jan 2015 00:51:40 +0100 Message-Id: <1422316305-19216-11-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422316305-19216-1-git-send-email-joro@8bytes.org> References: <1422316305-19216-1-git-send-email-joro@8bytes.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150126_185239_997500_311A1A84 X-CRM114-Status: GOOD ( 15.63 ) X-Spam-Score: -2.0 (--) Cc: Alexandre Courbot , linux-samsung-soc@vger.kernel.org, Heiko Stuebner , Arnd Bergmann , Stephen Warren , Joerg Roedel , Will Deacon , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Alex Williamson , Kukjin Kim , Thierry Reding , jroedel@suse.de, linux-tegra@vger.kernel.org, David Woodhouse , linux-arm-kernel@lists.infradead.org, Hiroshi Doyu X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Joerg Roedel Implement domain_alloc and domain_free iommu-ops as a replacement for domain_init/domain_destroy. Signed-off-by: Joerg Roedel --- drivers/iommu/msm_iommu.c | 73 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index e1b0537..f023c7a 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -52,8 +52,14 @@ DEFINE_SPINLOCK(msm_iommu_lock); struct msm_priv { unsigned long *pgtable; struct list_head list_attached; + struct iommu_domain domain; }; +static struct msm_priv *to_msm_priv(struct iommu_domain *dom) +{ + return container_of(dom, struct msm_priv, domain); +} + static int __enable_clocks(struct msm_iommu_drvdata *drvdata) { int ret; @@ -79,7 +85,7 @@ static void __disable_clocks(struct msm_iommu_drvdata *drvdata) static int __flush_iotlb(struct iommu_domain *domain) { - struct msm_priv *priv = domain->priv; + struct msm_priv *priv = to_msm_priv(domain); struct msm_iommu_drvdata *iommu_drvdata; struct msm_iommu_ctx_drvdata *ctx_drvdata; int ret = 0; @@ -209,10 +215,14 @@ static void __program_context(void __iomem *base, int ctx, phys_addr_t pgtable) SET_M(base, ctx, 1); } -static int msm_iommu_domain_init(struct iommu_domain *domain) +static struct iommu_domain *msm_iommu_domain_alloc(enum iommu_domain_type type) { - struct msm_priv *priv = kzalloc(sizeof(*priv), GFP_KERNEL); + struct msm_priv *priv; + if (type != IOMMU_DOMAIN_UNMANAGED) + return NULL; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) goto fail_nomem; @@ -224,20 +234,19 @@ static int msm_iommu_domain_init(struct iommu_domain *domain) goto fail_nomem; memset(priv->pgtable, 0, SZ_16K); - domain->priv = priv; - domain->geometry.aperture_start = 0; - domain->geometry.aperture_end = (1ULL << 32) - 1; - domain->geometry.force_aperture = true; + priv->domain.geometry.aperture_start = 0; + priv->domain.geometry.aperture_end = (1ULL << 32) - 1; + priv->domain.geometry.force_aperture = true; - return 0; + return &priv->domain; fail_nomem: kfree(priv); - return -ENOMEM; + return NULL; } -static void msm_iommu_domain_destroy(struct iommu_domain *domain) +static void msm_iommu_domain_free(struct iommu_domain *domain) { struct msm_priv *priv; unsigned long flags; @@ -245,20 +254,17 @@ static void msm_iommu_domain_destroy(struct iommu_domain *domain) int i; spin_lock_irqsave(&msm_iommu_lock, flags); - priv = domain->priv; - domain->priv = NULL; + priv = to_msm_priv(domain); - if (priv) { - fl_table = priv->pgtable; + fl_table = priv->pgtable; - for (i = 0; i < NUM_FL_PTE; i++) - if ((fl_table[i] & 0x03) == FL_TYPE_TABLE) - free_page((unsigned long) __va(((fl_table[i]) & - FL_BASE_MASK))); + for (i = 0; i < NUM_FL_PTE; i++) + if ((fl_table[i] & 0x03) == FL_TYPE_TABLE) + free_page((unsigned long) __va(((fl_table[i]) & + FL_BASE_MASK))); - free_pages((unsigned long)priv->pgtable, get_order(SZ_16K)); - priv->pgtable = NULL; - } + free_pages((unsigned long)priv->pgtable, get_order(SZ_16K)); + priv->pgtable = NULL; kfree(priv); spin_unlock_irqrestore(&msm_iommu_lock, flags); @@ -276,9 +282,9 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) spin_lock_irqsave(&msm_iommu_lock, flags); - priv = domain->priv; + priv = to_msm_priv(domain); - if (!priv || !dev) { + if (!dev) { ret = -EINVAL; goto fail; } @@ -330,9 +336,9 @@ static void msm_iommu_detach_dev(struct iommu_domain *domain, int ret; spin_lock_irqsave(&msm_iommu_lock, flags); - priv = domain->priv; + priv = to_msm_priv(domain); - if (!priv || !dev) + if (!dev) goto fail; iommu_drvdata = dev_get_drvdata(dev->parent); @@ -382,11 +388,7 @@ static int msm_iommu_map(struct iommu_domain *domain, unsigned long va, goto fail; } - priv = domain->priv; - if (!priv) { - ret = -EINVAL; - goto fail; - } + priv = to_msm_priv(domain); fl_table = priv->pgtable; @@ -484,10 +486,7 @@ static size_t msm_iommu_unmap(struct iommu_domain *domain, unsigned long va, spin_lock_irqsave(&msm_iommu_lock, flags); - priv = domain->priv; - - if (!priv) - goto fail; + priv = to_msm_priv(domain); fl_table = priv->pgtable; @@ -566,7 +565,7 @@ static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain, spin_lock_irqsave(&msm_iommu_lock, flags); - priv = domain->priv; + priv = to_msm_priv(domain); if (list_empty(&priv->list_attached)) goto fail; @@ -674,8 +673,8 @@ fail: static const struct iommu_ops msm_iommu_ops = { .capable = msm_iommu_capable, - .domain_init = msm_iommu_domain_init, - .domain_destroy = msm_iommu_domain_destroy, + .domain_alloc = msm_iommu_domain_alloc, + .domain_free = msm_iommu_domain_free, .attach_dev = msm_iommu_attach_dev, .detach_dev = msm_iommu_detach_dev, .map = msm_iommu_map,