From patchwork Thu Mar 26 12:43:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 6098921 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 6119FBF90F for ; Thu, 26 Mar 2015 12:54:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A253020212 for ; Thu, 26 Mar 2015 12:54:23 +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 AE8B7203AD for ; Thu, 26 Mar 2015 12:54:22 +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 1Yb7FT-0005R4-59; Thu, 26 Mar 2015 12:50:59 +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 1Yb79E-0007Hy-9T; Thu, 26 Mar 2015 12:44:41 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id E44DD3F6; 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=1427373823; bh=S6RYsyIpWY5YpP6H+n59BGWTZ3fo/5bS64V+8YWL9D4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A15tKME36mm0ZHhTaa3O5IylfyMm0SCvXXGoXVU1lmAkHFv0JFOqPZf4FFvtNniNt P6Wu3xBlvVVhzvJMx4QWrv7I4ppaf617ZPb90Z1FXzVGyExB1Pi8ayOND7W4n0tXGT QTAt8EHiCDH+9duzUVx/ecsNve4fSVYDT+TyQqLkkpDmGAczOnOKxrAqYQYcNjilBn CfAZHK8bWWDBaaxwirNIWUoiyKjbUIdxw6+kSj2GetqtJ2/miPM6n5DeAVjxW12L2o 9i0/AjDnUg3ZLpJNEPSky861vrD/+QtlFWyE+UDsWJ8szxqynicfEYHbHx2rmGuAJt 2B7x1/6hsX1tw== From: Joerg Roedel To: iommu@lists.linux-foundation.org Subject: [PATCH 12/16] iommu/shmobile: Make use of domain_alloc and domain_free Date: Thu, 26 Mar 2015 13:43:15 +0100 Message-Id: <1427373799-18662-13-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_054432_756984_3EEC664B X-CRM114-Status: GOOD ( 14.46 ) 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/shmobile-iommu.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/shmobile-iommu.c b/drivers/iommu/shmobile-iommu.c index f1b0077..a028751 100644 --- a/drivers/iommu/shmobile-iommu.c +++ b/drivers/iommu/shmobile-iommu.c @@ -42,11 +42,17 @@ struct shmobile_iommu_domain { spinlock_t map_lock; spinlock_t attached_list_lock; struct list_head attached_list; + struct iommu_domain domain; }; static struct shmobile_iommu_archdata *ipmmu_archdata; static struct kmem_cache *l1cache, *l2cache; +static struct shmobile_iommu_domain *to_sh_domain(struct iommu_domain *dom) +{ + return container_of(dom, struct shmobile_iommu_domain, domain); +} + static int pgtable_alloc(struct shmobile_iommu_domain_pgtable *pgtable, struct kmem_cache *cache, size_t size) { @@ -82,31 +88,33 @@ static void pgtable_write(struct shmobile_iommu_domain_pgtable *pgtable, sizeof(val) * count, DMA_TO_DEVICE); } -static int shmobile_iommu_domain_init(struct iommu_domain *domain) +static struct iommu_domain *shmobile_iommu_domain_alloc(unsigned type) { struct shmobile_iommu_domain *sh_domain; int i, ret; - sh_domain = kmalloc(sizeof(*sh_domain), GFP_KERNEL); + if (type != IOMMU_DOMAIN_UNMANAGED) + return NULL; + + sh_domain = kzalloc(sizeof(*sh_domain), GFP_KERNEL); if (!sh_domain) - return -ENOMEM; + return NULL; ret = pgtable_alloc(&sh_domain->l1, l1cache, L1_SIZE); if (ret < 0) { kfree(sh_domain); - return ret; + return NULL; } for (i = 0; i < L1_LEN; i++) sh_domain->l2[i].pgtable = NULL; spin_lock_init(&sh_domain->map_lock); spin_lock_init(&sh_domain->attached_list_lock); INIT_LIST_HEAD(&sh_domain->attached_list); - domain->priv = sh_domain; - return 0; + return &sh_domain->domain; } -static void shmobile_iommu_domain_destroy(struct iommu_domain *domain) +static void shmobile_iommu_domain_free(struct iommu_domain *domain) { - struct shmobile_iommu_domain *sh_domain = domain->priv; + struct shmobile_iommu_domain *sh_domain = to_sh_domain(domain); int i; for (i = 0; i < L1_LEN; i++) { @@ -115,14 +123,13 @@ static void shmobile_iommu_domain_destroy(struct iommu_domain *domain) } pgtable_free(&sh_domain->l1, l1cache, L1_SIZE); kfree(sh_domain); - domain->priv = NULL; } static int shmobile_iommu_attach_device(struct iommu_domain *domain, struct device *dev) { struct shmobile_iommu_archdata *archdata = dev->archdata.iommu; - struct shmobile_iommu_domain *sh_domain = domain->priv; + struct shmobile_iommu_domain *sh_domain = to_sh_domain(domain); int ret = -EBUSY; if (!archdata) @@ -151,7 +158,7 @@ static void shmobile_iommu_detach_device(struct iommu_domain *domain, struct device *dev) { struct shmobile_iommu_archdata *archdata = dev->archdata.iommu; - struct shmobile_iommu_domain *sh_domain = domain->priv; + struct shmobile_iommu_domain *sh_domain = to_sh_domain(domain); if (!archdata) return; @@ -214,7 +221,7 @@ static int shmobile_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL }; - struct shmobile_iommu_domain *sh_domain = domain->priv; + struct shmobile_iommu_domain *sh_domain = to_sh_domain(domain); unsigned int l1index, l2index; int ret; @@ -258,7 +265,7 @@ static size_t shmobile_iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) { struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL }; - struct shmobile_iommu_domain *sh_domain = domain->priv; + struct shmobile_iommu_domain *sh_domain = to_sh_domain(domain); unsigned int l1index, l2index; uint32_t l2entry = 0; size_t ret = 0; @@ -298,7 +305,7 @@ done: static phys_addr_t shmobile_iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) { - struct shmobile_iommu_domain *sh_domain = domain->priv; + struct shmobile_iommu_domain *sh_domain = to_sh_domain(domain); uint32_t l1entry = 0, l2entry = 0; unsigned int l1index, l2index; @@ -355,8 +362,8 @@ static int shmobile_iommu_add_device(struct device *dev) } static const struct iommu_ops shmobile_iommu_ops = { - .domain_init = shmobile_iommu_domain_init, - .domain_destroy = shmobile_iommu_domain_destroy, + .domain_alloc = shmobile_iommu_domain_alloc, + .domain_free = shmobile_iommu_domain_free, .attach_dev = shmobile_iommu_attach_device, .detach_dev = shmobile_iommu_detach_device, .map = shmobile_iommu_map,