From patchwork Thu Mar 26 12:43:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 6099071 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 0C6529F399 for ; Thu, 26 Mar 2015 13:08:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ED3A5203B7 for ; Thu, 26 Mar 2015 13:08:43 +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 E5E64203AC for ; Thu, 26 Mar 2015 13:08:42 +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 1Yb7U9-0001hV-Lm; Thu, 26 Mar 2015 13:06:09 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yb7U4-0001fj-Un; Thu, 26 Mar 2015 13:06:05 +0000 Received: from 8bytes.org ([2a01:238:4383:600:38bc:a715:4b6d:a889] helo=theia.8bytes.org) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yb79D-00007F-MM; Thu, 26 Mar 2015 12:44:34 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id AD4D13F2; 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=/x2xqgV2+adygOb9JpnHKlZEVM50rwyS5S2dWDa44eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WpwmaER2vrAJ4o6tQKye3Zwhx9/PDsaFHan6D1hmW1j/aq0YwPtA4PSaLoXpOCUM0 8yHBoPajG9CYTw/U/7odtt+eDWeI1pOh6SSo10bYm6jV8bocmr9nfT7r8FiZdcFCWE OnSvc0GzC+rUdWzhP62iGOWQnMbsKAnumBnF6X9+5xhVvBt6ziX2J7uYsg+X0YmEgK r7YB4RZqHGXvBbJVOyZvhM7+gBTTz95rvNaum+Pe6Mn0sK9AcrZ0Q1tHlktHZxWEtf K3XPiDN9mP8EFg7d0aAy0QSCv0VmT/4uA5CAp4+B4oPFf8zHp3cxg1S0mNeD2qq9cJ fot2MxPBbzvuw== From: Joerg Roedel To: iommu@lists.linux-foundation.org Subject: [PATCH 13/16] iommu/ipmmu-vmsa: Make use of domain_alloc and domain_free Date: Thu, 26 Mar 2015 13:43:16 +0100 Message-Id: <1427373799-18662-14-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_124431_872916_5904E206 X-CRM114-Status: GOOD ( 18.49 ) 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, 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/ipmmu-vmsa.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 10186ca..274c08d 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -38,7 +38,7 @@ struct ipmmu_vmsa_device { struct ipmmu_vmsa_domain { struct ipmmu_vmsa_device *mmu; - struct iommu_domain *io_domain; + struct iommu_domain io_domain; struct io_pgtable_cfg cfg; struct io_pgtable_ops *iop; @@ -56,6 +56,11 @@ struct ipmmu_vmsa_archdata { static DEFINE_SPINLOCK(ipmmu_devices_lock); static LIST_HEAD(ipmmu_devices); +static struct ipmmu_vmsa_domain *to_vmsa_domain(struct iommu_domain *dom) +{ + return container_of(dom, struct ipmmu_vmsa_domain, io_domain); +} + #define TLB_LOOP_TIMEOUT 100 /* 100us */ /* ----------------------------------------------------------------------------- @@ -428,7 +433,7 @@ static irqreturn_t ipmmu_domain_irq(struct ipmmu_vmsa_domain *domain) * TODO: We need to look up the faulty device based on the I/O VA. Use * the IOMMU device for now. */ - if (!report_iommu_fault(domain->io_domain, mmu->dev, iova, 0)) + if (!report_iommu_fault(&domain->io_domain, mmu->dev, iova, 0)) return IRQ_HANDLED; dev_err_ratelimited(mmu->dev, @@ -448,7 +453,7 @@ static irqreturn_t ipmmu_irq(int irq, void *dev) return IRQ_NONE; io_domain = mmu->mapping->domain; - domain = io_domain->priv; + domain = to_vmsa_domain(io_domain); return ipmmu_domain_irq(domain); } @@ -457,25 +462,25 @@ static irqreturn_t ipmmu_irq(int irq, void *dev) * IOMMU Operations */ -static int ipmmu_domain_init(struct iommu_domain *io_domain) +static struct iommu_domain *ipmmu_domain_alloc(unsigned type) { struct ipmmu_vmsa_domain *domain; + if (type != IOMMU_DOMAIN_UNMANAGED) + return NULL; + domain = kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) - return -ENOMEM; + return NULL; spin_lock_init(&domain->lock); - io_domain->priv = domain; - domain->io_domain = io_domain; - - return 0; + return &domain->io_domain; } -static void ipmmu_domain_destroy(struct iommu_domain *io_domain) +static void ipmmu_domain_free(struct iommu_domain *io_domain) { - struct ipmmu_vmsa_domain *domain = io_domain->priv; + struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); /* * Free the domain resources. We assume that all devices have already @@ -491,7 +496,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, { struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; struct ipmmu_vmsa_device *mmu = archdata->mmu; - struct ipmmu_vmsa_domain *domain = io_domain->priv; + struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned long flags; unsigned int i; int ret = 0; @@ -532,7 +537,7 @@ static void ipmmu_detach_device(struct iommu_domain *io_domain, struct device *dev) { struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; - struct ipmmu_vmsa_domain *domain = io_domain->priv; + struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned int i; for (i = 0; i < archdata->num_utlbs; ++i) @@ -546,7 +551,7 @@ static void ipmmu_detach_device(struct iommu_domain *io_domain, static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { - struct ipmmu_vmsa_domain *domain = io_domain->priv; + struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); if (!domain) return -ENODEV; @@ -557,7 +562,7 @@ static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova, static size_t ipmmu_unmap(struct iommu_domain *io_domain, unsigned long iova, size_t size) { - struct ipmmu_vmsa_domain *domain = io_domain->priv; + struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); return domain->iop->unmap(domain->iop, iova, size); } @@ -565,7 +570,7 @@ static size_t ipmmu_unmap(struct iommu_domain *io_domain, unsigned long iova, static phys_addr_t ipmmu_iova_to_phys(struct iommu_domain *io_domain, dma_addr_t iova) { - struct ipmmu_vmsa_domain *domain = io_domain->priv; + struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); /* TODO: Is locking needed ? */ @@ -737,8 +742,8 @@ static void ipmmu_remove_device(struct device *dev) } static const struct iommu_ops ipmmu_ops = { - .domain_init = ipmmu_domain_init, - .domain_destroy = ipmmu_domain_destroy, + .domain_alloc = ipmmu_domain_alloc, + .domain_free = ipmmu_domain_free, .attach_dev = ipmmu_attach_device, .detach_dev = ipmmu_detach_device, .map = ipmmu_map,