From patchwork Thu Mar 26 12:43:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 6098751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6F4BBBF90F for ; Thu, 26 Mar 2015 12:49:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EEB8203AA for ; Thu, 26 Mar 2015 12:49:52 +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 8DA00203A1 for ; Thu, 26 Mar 2015 12:49:51 +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 1Yb7Bv-0001X1-KL; Thu, 26 Mar 2015 12:47:19 +0000 Received: from 8bytes.org ([2a01:238:4383:600:38bc:a715:4b6d:a889] helo=theia.8bytes.org) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yb799-0007Fh-BC; Thu, 26 Mar 2015 12:44:29 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id 32FCC3EF; Thu, 26 Mar 2015 13:43:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1427373823; bh=SzTmqiRVKMa6I3e6KnKKMqBru/NVI4dl9MOq3Yc4fnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WWcaA/3+djItRT7+CNwomKvUX3D1NS06EBbzndla44p4Im/DrHgFx3VFTJTeJMRct r0BJMQsh/on98JLcq7vdxO+S32i1XSNPcZlXpSUtovzzau59eYjjwbyQSXYu2M5qfx vkEV16XvGb+izqJCML1woZKXKj4m4KI8xw1ALhDspII+sM6+COoFpKdjbNy/lmdJeJ mraEZObKQuuiu2tLpeuZjXLT3s/TGOdp3CuIgUVhfVoltxWpQ7YoU4dHmNvPZXBQyV pxQtOJUQN9QaPsGIug7W3me5IF3eV3lZ6TLgPbOROMR1g5l7347qewJK71D++WaylI y930yBRWH2lFw== From: Joerg Roedel To: iommu@lists.linux-foundation.org Subject: [PATCH 09/16] iommu/tegra-smmu: Make use of domain_alloc and domain_free Date: Thu, 26 Mar 2015 13:43:12 +0100 Message-Id: <1427373799-18662-10-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427373799-18662-1-git-send-email-joro@8bytes.org> References: <1427373799-18662-1-git-send-email-joro@8bytes.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150326_054427_883793_3FFBE446 X-CRM114-Status: GOOD ( 14.64 ) X-Spam-Score: -0.1 (/) 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, Yingjoe Chen , 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 Acked-by: Thierry Reding --- drivers/iommu/tegra-smmu.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 6e134c7..7208297 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -31,7 +31,7 @@ struct tegra_smmu { }; struct tegra_smmu_as { - struct iommu_domain *domain; + struct iommu_domain domain; struct tegra_smmu *smmu; unsigned int use_count; struct page *count; @@ -40,6 +40,11 @@ struct tegra_smmu_as { u32 attr; }; +static struct tegra_smmu_as *to_smmu_as(struct iommu_domain *dom) +{ + return container_of(dom, struct tegra_smmu_as, domain); +} + static inline void smmu_writel(struct tegra_smmu *smmu, u32 value, unsigned long offset) { @@ -224,30 +229,32 @@ static bool tegra_smmu_capable(enum iommu_cap cap) return false; } -static int tegra_smmu_domain_init(struct iommu_domain *domain) +static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) { struct tegra_smmu_as *as; unsigned int i; uint32_t *pd; + if (type != IOMMU_DOMAIN_UNMANAGED) + return NULL; + as = kzalloc(sizeof(*as), GFP_KERNEL); if (!as) - return -ENOMEM; + return NULL; as->attr = SMMU_PD_READABLE | SMMU_PD_WRITABLE | SMMU_PD_NONSECURE; - as->domain = domain; as->pd = alloc_page(GFP_KERNEL | __GFP_DMA); if (!as->pd) { kfree(as); - return -ENOMEM; + return NULL; } as->count = alloc_page(GFP_KERNEL); if (!as->count) { __free_page(as->pd); kfree(as); - return -ENOMEM; + return NULL; } /* clear PDEs */ @@ -264,14 +271,12 @@ static int tegra_smmu_domain_init(struct iommu_domain *domain) for (i = 0; i < SMMU_NUM_PDE; i++) pd[i] = 0; - domain->priv = as; - - return 0; + return &as->domain; } -static void tegra_smmu_domain_destroy(struct iommu_domain *domain) +static void tegra_smmu_domain_free(struct iommu_domain *domain) { - struct tegra_smmu_as *as = domain->priv; + struct tegra_smmu_as *as = to_smmu_as(domain); /* TODO: free page directory and page tables */ ClearPageReserved(as->pd); @@ -395,7 +400,7 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { struct tegra_smmu *smmu = dev->archdata.iommu; - struct tegra_smmu_as *as = domain->priv; + struct tegra_smmu_as *as = to_smmu_as(domain); struct device_node *np = dev->of_node; struct of_phandle_args args; unsigned int index = 0; @@ -428,7 +433,7 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain, static void tegra_smmu_detach_dev(struct iommu_domain *domain, struct device *dev) { - struct tegra_smmu_as *as = domain->priv; + struct tegra_smmu_as *as = to_smmu_as(domain); struct device_node *np = dev->of_node; struct tegra_smmu *smmu = as->smmu; struct of_phandle_args args; @@ -524,7 +529,7 @@ static void as_put_pte(struct tegra_smmu_as *as, dma_addr_t iova) static int tegra_smmu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { - struct tegra_smmu_as *as = domain->priv; + struct tegra_smmu_as *as = to_smmu_as(domain); struct tegra_smmu *smmu = as->smmu; unsigned long offset; struct page *page; @@ -548,7 +553,7 @@ static int tegra_smmu_map(struct iommu_domain *domain, unsigned long iova, static size_t tegra_smmu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) { - struct tegra_smmu_as *as = domain->priv; + struct tegra_smmu_as *as = to_smmu_as(domain); struct tegra_smmu *smmu = as->smmu; unsigned long offset; struct page *page; @@ -572,7 +577,7 @@ static size_t tegra_smmu_unmap(struct iommu_domain *domain, unsigned long iova, static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) { - struct tegra_smmu_as *as = domain->priv; + struct tegra_smmu_as *as = to_smmu_as(domain); struct page *page; unsigned long pfn; u32 *pte; @@ -633,8 +638,8 @@ static void tegra_smmu_remove_device(struct device *dev) static const struct iommu_ops tegra_smmu_ops = { .capable = tegra_smmu_capable, - .domain_init = tegra_smmu_domain_init, - .domain_destroy = tegra_smmu_domain_destroy, + .domain_alloc = tegra_smmu_domain_alloc, + .domain_free = tegra_smmu_domain_free, .attach_dev = tegra_smmu_attach_dev, .detach_dev = tegra_smmu_detach_dev, .add_device = tegra_smmu_add_device,