From patchwork Sun Dec 16 17:25:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1885241 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 3CAE6DFAC4 for ; Sun, 16 Dec 2012 17:31:15 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TkI04-0006IO-O1; Sun, 16 Dec 2012 17:27:41 +0000 Received: from perceval.ideasonboard.com ([95.142.166.194]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TkHxe-00059F-P1 for linux-arm-kernel@lists.infradead.org; Sun, 16 Dec 2012 17:25:13 +0000 Received: from avalon.quadriga.com (unknown [194.136.87.226]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AB64D359A8; Sun, 16 Dec 2012 18:24:58 +0100 (CET) From: Laurent Pinchart To: Hideki EIRAKU Subject: [PATCH/WIP/RFC 10/14] shmobile-ipmmu: Pass a struct shmobile_ipmmu to IPMMU functions Date: Sun, 16 Dec 2012 18:25:56 +0100 Message-Id: <1355678760-27357-11-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1355678760-27357-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1350290093-998-1-git-send-email-hdk@igel.co.jp> <1355678760-27357-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121216_122511_140424_70B8DFF3 X-CRM114-Status: GOOD ( 13.02 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Katsuya MATSUBARA , Simon Horman , linux-sh@vger.kernel.org, Magnus Damm , linux-kernel@vger.kernel.org, Paul Mundt , Damian Hobson-Garcia , linux-arm-kernel@lists.infradead.org, Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Signed-off-by: Laurent Pinchart --- drivers/iommu/shmobile-iommu.c | 12 +++--- drivers/iommu/shmobile-ipmmu.c | 90 +++++++++++++++++++-------------------- drivers/iommu/shmobile-ipmmu.h | 9 ++-- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/drivers/iommu/shmobile-iommu.c b/drivers/iommu/shmobile-iommu.c index 1a37be2..423993c 100644 --- a/drivers/iommu/shmobile-iommu.c +++ b/drivers/iommu/shmobile-iommu.c @@ -53,7 +53,7 @@ static spinlock_t lock; static DEFINE_SPINLOCK(lock_add); static struct shmobile_iommu_domain *attached; static int num_attached_devices; -static struct device *ipmmu_access_device; +static struct shmobile_ipmmu *ipmmu_access_device; static int shmobile_iommu_domain_init(struct iommu_domain *domain) { @@ -329,20 +329,20 @@ void ipmmu_add_device(struct device *dev) spin_unlock(&lock_add); } -int ipmmu_iommu_init(struct device *dev) +int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu) { - dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); - l1pool = dma_pool_create("shmobile-iommu-pgtable1", dev, + dma_set_coherent_mask(ipmmu->dev, DMA_BIT_MASK(32)); + l1pool = dma_pool_create("shmobile-iommu-pgtable1", ipmmu->dev, L1_SIZE, L1_ALIGN, 0); if (!l1pool) goto nomem_pool1; - l2pool = dma_pool_create("shmobile-iommu-pgtable2", dev, + l2pool = dma_pool_create("shmobile-iommu-pgtable2", ipmmu->dev, L2_SIZE, L2_ALIGN, 0); if (!l2pool) goto nomem_pool2; spin_lock_init(&lock); attached = NULL; - ipmmu_access_device = dev; + ipmmu_access_device = ipmmu; bus_set_iommu(&platform_bus_type, &shmobile_iommu_ops); if (shmobile_iommu_attach_all_devices()) pr_err("shmobile_iommu_attach_all_devices failed\n"); diff --git a/drivers/iommu/shmobile-ipmmu.c b/drivers/iommu/shmobile-ipmmu.c index b308292..9858c91 100644 --- a/drivers/iommu/shmobile-ipmmu.c +++ b/drivers/iommu/shmobile-ipmmu.c @@ -34,99 +34,97 @@ #define IMCTR1_TLBEN (1 << 0) #define IMCTR1_FLUSH (1 << 1) -static void ipmmu_reg_write(struct shmobile_ipmmu *priv, unsigned long reg_off, +static void ipmmu_reg_write(struct shmobile_ipmmu *ipmmu, unsigned long reg_off, unsigned long data) { - iowrite32(data, priv->ipmmu_base + reg_off); + iowrite32(data, ipmmu->ipmmu_base + reg_off); } -void ipmmu_tlb_flush(struct device *dev) +void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu) { - struct shmobile_ipmmu *priv; - - if (!dev) + if (!ipmmu) return; - priv = dev_get_drvdata(dev); - mutex_lock(&priv->flush_lock); - if (priv->tlb_enabled) - ipmmu_reg_write(priv, IMCTR1, IMCTR1_FLUSH | IMCTR1_TLBEN); + + mutex_lock(&ipmmu->flush_lock); + if (ipmmu->tlb_enabled) + ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH | IMCTR1_TLBEN); else - ipmmu_reg_write(priv, IMCTR1, IMCTR1_FLUSH); - mutex_unlock(&priv->flush_lock); + ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH); + mutex_unlock(&ipmmu->flush_lock); } -void ipmmu_tlb_set(struct device *dev, unsigned long phys, int size, int asid) +void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size, + int asid) { - struct shmobile_ipmmu *priv; - - if (!dev) + if (!ipmmu) return; - priv = dev_get_drvdata(dev); - mutex_lock(&priv->flush_lock); + + mutex_lock(&ipmmu->flush_lock); switch (size) { default: - priv->tlb_enabled = 0; + ipmmu->tlb_enabled = 0; break; case 0x2000: - ipmmu_reg_write(priv, IMTTBCR, 1); - priv->tlb_enabled = 1; + ipmmu_reg_write(ipmmu, IMTTBCR, 1); + ipmmu->tlb_enabled = 1; break; case 0x1000: - ipmmu_reg_write(priv, IMTTBCR, 2); - priv->tlb_enabled = 1; + ipmmu_reg_write(ipmmu, IMTTBCR, 2); + ipmmu->tlb_enabled = 1; break; case 0x800: - ipmmu_reg_write(priv, IMTTBCR, 3); - priv->tlb_enabled = 1; + ipmmu_reg_write(ipmmu, IMTTBCR, 3); + ipmmu->tlb_enabled = 1; break; case 0x400: - ipmmu_reg_write(priv, IMTTBCR, 4); - priv->tlb_enabled = 1; + ipmmu_reg_write(ipmmu, IMTTBCR, 4); + ipmmu->tlb_enabled = 1; break; case 0x200: - ipmmu_reg_write(priv, IMTTBCR, 5); - priv->tlb_enabled = 1; + ipmmu_reg_write(ipmmu, IMTTBCR, 5); + ipmmu->tlb_enabled = 1; break; case 0x100: - ipmmu_reg_write(priv, IMTTBCR, 6); - priv->tlb_enabled = 1; + ipmmu_reg_write(ipmmu, IMTTBCR, 6); + ipmmu->tlb_enabled = 1; break; case 0x80: - ipmmu_reg_write(priv, IMTTBCR, 7); - priv->tlb_enabled = 1; + ipmmu_reg_write(ipmmu, IMTTBCR, 7); + ipmmu->tlb_enabled = 1; break; } - ipmmu_reg_write(priv, IMTTBR, phys); - ipmmu_reg_write(priv, IMASID, asid); - mutex_unlock(&priv->flush_lock); + ipmmu_reg_write(ipmmu, IMTTBR, phys); + ipmmu_reg_write(ipmmu, IMASID, asid); + mutex_unlock(&ipmmu->flush_lock); } static int ipmmu_probe(struct platform_device *pdev) { + struct shmobile_ipmmu *ipmmu; struct resource *res; - struct shmobile_ipmmu *priv; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "cannot get platform resources\n"); return -ENOENT; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) { + ipmmu = devm_kzalloc(&pdev->dev, sizeof(*ipmmu), GFP_KERNEL); + if (!ipmmu) { dev_err(&pdev->dev, "cannot allocate device data\n"); return -ENOMEM; } - mutex_init(&priv->flush_lock); - priv->ipmmu_base = devm_ioremap_nocache(&pdev->dev, res->start, + mutex_init(&ipmmu->flush_lock); + ipmmu->dev = &pdev->dev; + ipmmu->ipmmu_base = devm_ioremap_nocache(&pdev->dev, res->start, resource_size(res)); - if (!priv->ipmmu_base) { + if (!ipmmu->ipmmu_base) { dev_err(&pdev->dev, "ioremap_nocache failed\n"); return -ENOMEM; } - platform_set_drvdata(pdev, priv); - ipmmu_reg_write(priv, IMCTR1, 0x0); /* disable TLB */ - ipmmu_reg_write(priv, IMCTR2, 0x0); /* disable PMB */ - ipmmu_iommu_init(&pdev->dev); + platform_set_drvdata(pdev, ipmmu); + ipmmu_reg_write(ipmmu, IMCTR1, 0x0); /* disable TLB */ + ipmmu_reg_write(ipmmu, IMCTR2, 0x0); /* disable PMB */ + ipmmu_iommu_init(ipmmu); return 0; } diff --git a/drivers/iommu/shmobile-ipmmu.h b/drivers/iommu/shmobile-ipmmu.h index 5c17a46..1458a97 100644 --- a/drivers/iommu/shmobile-ipmmu.h +++ b/drivers/iommu/shmobile-ipmmu.h @@ -2,18 +2,19 @@ #define __SHMOBILE_IPMMU_H__ struct shmobile_ipmmu { + struct device *dev; void __iomem *ipmmu_base; int tlb_enabled; struct mutex flush_lock; }; #ifdef CONFIG_SHMOBILE_IPMMU_TLB -void ipmmu_tlb_flush(struct device *ipmmu_dev); -void ipmmu_tlb_set(struct device *ipmmu_dev, unsigned long phys, int size, +void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu); +void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size, int asid); -int ipmmu_iommu_init(struct device *dev); +int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu); #else -static int ipmmu_iommu_init(struct device *dev) +static int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu) { return -EINVAL; }