From patchwork Thu Mar 26 12:43:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 6098881 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 0F4AF9F350 for ; Thu, 26 Mar 2015 12:52:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B13D20212 for ; Thu, 26 Mar 2015 12:52:55 +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 0ECA8203AA for ; Thu, 26 Mar 2015 12:52:54 +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 1Yb7EF-0003IM-RI; Thu, 26 Mar 2015 12:49:43 +0000 Received: from 8bytes.org ([81.169.241.247] helo=theia.8bytes.org) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yb79B-0007Hq-Ki; Thu, 26 Mar 2015 12:44:39 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id 1A9EA3F3; Thu, 26 Mar 2015 13:43:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1427373824; bh=Gh5D7R5loiRTEpt191/9OQ4Tqx2zpNLMdwMWSxrWq9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xa5CzR3tKMwNF4/m/ehIf1yrMUXh8qrM5XODF5tXl++jxt+q3xm18SlvCZxpxkAzP yQCUueNzU6EigWOnUBw0wKJQDsvq6NAtYY8CjCa3RMnsu5V3X00PMnifDU3Rz1ghKB vGrKMbpeyXsVtncINFwa/vrdU9qxvmUxkCy2Z0YkFOwFCOvNCYEgoUsC+c5rDOJqEV W2Q/SGB5CciRHBHb48btW80m217k/ckrVIR8+paWFLotGfuBBMcNU2o3DepFlJvOQ4 wXPTeeKAUQ7EwBzS31ySsf8I4hfwOroDOxXFRkD7S3teUd+8Q0s3ycC3ZCN5s4Ec9r kDAlTVLz3zO1Q== From: Joerg Roedel To: iommu@lists.linux-foundation.org Subject: [PATCH 14/16] iommu/rockchip: Make use of domain_alloc and domain_free Date: Thu, 26 Mar 2015 13:43:17 +0100 Message-Id: <1427373799-18662-15-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_054430_099471_E24E8C77 X-CRM114-Status: GOOD ( 14.16 ) 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 --- drivers/iommu/rockchip-iommu.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 9f74fdd..4015560 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -80,6 +80,8 @@ struct rk_iommu_domain { u32 *dt; /* page directory table */ spinlock_t iommus_lock; /* lock for iommus list */ spinlock_t dt_lock; /* lock for modifying page directory table */ + + struct iommu_domain domain; }; struct rk_iommu { @@ -100,6 +102,11 @@ static inline void rk_table_flush(u32 *va, unsigned int count) outer_flush_range(pa_start, pa_end); } +static struct rk_iommu_domain *to_rk_domain(struct iommu_domain *dom) +{ + return container_of(dom, struct rk_iommu_domain, domain); +} + /** * Inspired by _wait_for in intel_drv.h * This is NOT safe for use in interrupt context. @@ -503,7 +510,7 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id) static phys_addr_t rk_iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) { - struct rk_iommu_domain *rk_domain = domain->priv; + struct rk_iommu_domain *rk_domain = to_rk_domain(domain); unsigned long flags; phys_addr_t pt_phys, phys = 0; u32 dte, pte; @@ -639,7 +646,7 @@ unwind: static int rk_iommu_map(struct iommu_domain *domain, unsigned long _iova, phys_addr_t paddr, size_t size, int prot) { - struct rk_iommu_domain *rk_domain = domain->priv; + struct rk_iommu_domain *rk_domain = to_rk_domain(domain); unsigned long flags; dma_addr_t iova = (dma_addr_t)_iova; u32 *page_table, *pte_addr; @@ -670,7 +677,7 @@ static int rk_iommu_map(struct iommu_domain *domain, unsigned long _iova, static size_t rk_iommu_unmap(struct iommu_domain *domain, unsigned long _iova, size_t size) { - struct rk_iommu_domain *rk_domain = domain->priv; + struct rk_iommu_domain *rk_domain = to_rk_domain(domain); unsigned long flags; dma_addr_t iova = (dma_addr_t)_iova; phys_addr_t pt_phys; @@ -726,7 +733,7 @@ static int rk_iommu_attach_device(struct iommu_domain *domain, struct device *dev) { struct rk_iommu *iommu; - struct rk_iommu_domain *rk_domain = domain->priv; + struct rk_iommu_domain *rk_domain = to_rk_domain(domain); unsigned long flags; int ret; phys_addr_t dte_addr; @@ -778,7 +785,7 @@ static void rk_iommu_detach_device(struct iommu_domain *domain, struct device *dev) { struct rk_iommu *iommu; - struct rk_iommu_domain *rk_domain = domain->priv; + struct rk_iommu_domain *rk_domain = to_rk_domain(domain); unsigned long flags; /* Allow 'virtual devices' (eg drm) to detach from domain */ @@ -804,13 +811,16 @@ static void rk_iommu_detach_device(struct iommu_domain *domain, dev_info(dev, "Detached from iommu domain\n"); } -static int rk_iommu_domain_init(struct iommu_domain *domain) +static struct iommu_domain *rk_iommu_domain_alloc(unsigned type) { struct rk_iommu_domain *rk_domain; + if (type != IOMMU_DOMAIN_UNMANAGED) + return NULL; + rk_domain = kzalloc(sizeof(*rk_domain), GFP_KERNEL); if (!rk_domain) - return -ENOMEM; + return NULL; /* * rk32xx iommus use a 2 level pagetable. @@ -827,17 +837,16 @@ static int rk_iommu_domain_init(struct iommu_domain *domain) spin_lock_init(&rk_domain->dt_lock); INIT_LIST_HEAD(&rk_domain->iommus); - domain->priv = rk_domain; + return &rk_domain->domain; - return 0; err_dt: kfree(rk_domain); - return -ENOMEM; + return NULL; } -static void rk_iommu_domain_destroy(struct iommu_domain *domain) +static void rk_iommu_domain_free(struct iommu_domain *domain) { - struct rk_iommu_domain *rk_domain = domain->priv; + struct rk_iommu_domain *rk_domain = to_rk_domain(domain); int i; WARN_ON(!list_empty(&rk_domain->iommus)); @@ -852,8 +861,7 @@ static void rk_iommu_domain_destroy(struct iommu_domain *domain) } free_page((unsigned long)rk_domain->dt); - kfree(domain->priv); - domain->priv = NULL; + kfree(rk_domain); } static bool rk_iommu_is_dev_iommu_master(struct device *dev) @@ -952,8 +960,8 @@ static void rk_iommu_remove_device(struct device *dev) } static const struct iommu_ops rk_iommu_ops = { - .domain_init = rk_iommu_domain_init, - .domain_destroy = rk_iommu_domain_destroy, + .domain_alloc = rk_iommu_domain_alloc, + .domain_free = rk_iommu_domain_free, .attach_dev = rk_iommu_attach_device, .detach_dev = rk_iommu_detach_device, .map = rk_iommu_map,