From patchwork Tue Feb 25 12:42:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 3716451 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 775C8BF13A for ; Tue, 25 Feb 2014 12:44:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 52B89201DD for ; Tue, 25 Feb 2014 12:44:02 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (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 15D6F201D3 for ; Tue, 25 Feb 2014 12:44:01 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIHMD-0006BA-TM; Tue, 25 Feb 2014 12:43:34 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIHM5-0000ij-9D; Tue, 25 Feb 2014 12:43:25 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIHLo-0000eV-9a for linux-arm-kernel@lists.infradead.org; Tue, 25 Feb 2014 12:43:10 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1J00DRHXZ05850@mailout2.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 25 Feb 2014 12:42:37 +0000 (GMT) X-AuditID: cbfec7f4-b7f796d000005a13-07-530c8fc128f9 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 1E.13.23059.1CF8C035; Tue, 25 Feb 2014 12:42:41 +0000 (GMT) Received: from amdc1339.mshome.net ([106.116.147.30]) by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N1J00EGTXYWKEB0@eusync1.samsung.com>; Tue, 25 Feb 2014 12:42:41 +0000 (GMT) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, iommu@lists.linux-foundation.org Subject: [PATCH 2/2] arm: dma-mapping: remove order parameter from arm_iommu_create_mapping() Date: Tue, 25 Feb 2014 13:42:21 +0100 Message-id: <1393332141-17781-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1393332141-17781-1-git-send-email-m.szyprowski@samsung.com> References: <1393332141-17781-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDLMWRmVeSWpSXmKPExsVy+t/xy7oH+3mCDT4+ErP4eHk2s8XZ31uY LRbst7bonL2B3eLLlYdMFpseX2O1uH2Z12LtkbvsFp+e/WO3ePnxBIsDl8eTg/OYPNbMW8Po 0dLcw+bxdMJkdo871/aweWxeUu9x+99jZo/JN5YzevQ2v2Pz6NuyijGAK4rLJiU1J7MstUjf LoErY/vJrcwFCxwqTj89z9TA+Naki5GTQ0LARKLteRczhC0mceHeerYuRi4OIYGljBJrtvyE crqZJHr3T2ICqWITMJToetvFBmKLCORITJp2hx2kiFlgIZPE+gX7wUYJC8RLdJw/xA5iswio SjyZfRbM5hXwkPh9sZmli5EDaJ2CxJxJNiBhTgFPifVbH4LNFAIqmfDyEvsERt4FjAyrGEVT S5MLipPScw31ihNzi0vz0vWS83M3MUJC9MsOxsXHrA4xCnAwKvHwPijlDhZiTSwrrsw9xCjB wawkwmvdyhMsxJuSWFmVWpQfX1Sak1p8iJGJg1OqgbF9e2zAX/61sgddduTVihzXW9D0tM9g 3s+ryRd9hWwcLBLm7ed56/JtTmRV1Lu7fMtlzgqmTVSRan77OuB6p+dyG91uXea6Bxz9c9z8 vB1q/n9xDvW9+KF39QzTqnM5jzntfPWeepe5sqT0eiiul2JY9Zj33cb3XffX7THeK386cH2R qtljdyWW4oxEQy3mouJEAPzI6vYvAgAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140225_074308_444706_FE3111A3 X-CRM114-Status: GOOD ( 18.89 ) X-Spam-Score: -6.9 (------) Cc: Nicolas Pitre , Russell King , Andreas Herrmann , Joerg Roedel , Will Deacon , Marek Szyprowski , Hiroshi Doyu X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 The 'order' parameter for IOMMU-aware dma-mapping implementation was introduced mainly as a hack to reduce size of the bitmap used for tracking IO virtual address space. Since now it is possible to dynamically resize the bitmap, this hack is not needed and can be removed without any impact on the client devices. This way the parameters for arm_iommu_create_mapping() becomes much easier to understand. 'size' parameter now means the maximum supported IO address space size. The code will allocate (resize) bitmap in chunks, ensuring that a single chunk is not larger than a single memory page to avoid unreliable allocations of size larger than PAGE_SIZE in atomic context. Signed-off-by: Marek Szyprowski --- arch/arm/include/asm/dma-iommu.h | 4 +-- arch/arm/mm/dma-mapping.c | 43 ++++++++++++++--------------- drivers/gpu/drm/exynos/exynos_drm_drv.h | 2 -- drivers/gpu/drm/exynos/exynos_drm_iommu.c | 6 ++-- drivers/gpu/drm/exynos/exynos_drm_iommu.h | 1 - drivers/iommu/shmobile-iommu.c | 2 +- 6 files changed, 25 insertions(+), 33 deletions(-) diff --git a/arch/arm/include/asm/dma-iommu.h b/arch/arm/include/asm/dma-iommu.h index 686797c..eec0a12 100644 --- a/arch/arm/include/asm/dma-iommu.h +++ b/arch/arm/include/asm/dma-iommu.h @@ -19,7 +19,6 @@ struct dma_iommu_mapping { size_t bitmap_size; /* size of a single bitmap */ size_t bits; /* per bitmap */ unsigned int size; /* per bitmap */ - unsigned int order; dma_addr_t base; spinlock_t lock; @@ -27,8 +26,7 @@ struct dma_iommu_mapping { }; struct dma_iommu_mapping * -arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size, - int order); +arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size); void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping); diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index cc42bc2..f62aa06 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1081,11 +1081,8 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping, if (order > CONFIG_ARM_DMA_IOMMU_ALIGNMENT) order = CONFIG_ARM_DMA_IOMMU_ALIGNMENT; - count = ((PAGE_ALIGN(size) >> PAGE_SHIFT) + - (1 << mapping->order) - 1) >> mapping->order; - - if (order > mapping->order) - align = (1 << (order - mapping->order)) - 1; + count = PAGE_ALIGN(size) >> PAGE_SHIFT; + align = (1 << order) - 1; spin_lock_irqsave(&mapping->lock, flags); for (i = 0; i < mapping->nr_bitmaps; i++) { @@ -1123,7 +1120,7 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping, spin_unlock_irqrestore(&mapping->lock, flags); iova = mapping->base + (mapping->size * i); - iova += start << (mapping->order + PAGE_SHIFT); + iova += start << PAGE_SHIFT; return iova; } @@ -1144,7 +1141,7 @@ static inline void __free_iova(struct dma_iommu_mapping *mapping, bitmap_base = mapping->base + mapping->size * bitmap_index; - start = (addr - bitmap_base) >> (mapping->order + PAGE_SHIFT); + start = (addr - bitmap_base) >> PAGE_SHIFT; if (addr + size > bitmap_base + mapping->size) { /* @@ -1155,8 +1152,7 @@ static inline void __free_iova(struct dma_iommu_mapping *mapping, */ BUG(); } else - count = ((size >> PAGE_SHIFT) + - (1 << mapping->order) - 1) >> mapping->order; + count = size >> PAGE_SHIFT; spin_lock_irqsave(&mapping->lock, flags); bitmap_clear(mapping->bitmaps[bitmap_index], start, count); @@ -1924,8 +1920,7 @@ struct dma_map_ops iommu_coherent_ops = { * arm_iommu_create_mapping * @bus: pointer to the bus holding the client device (for IOMMU calls) * @base: start address of the valid IO address space - * @size: size of the valid IO address space - * @order: accuracy of the IO addresses allocations + * @size: maximum size of the valid IO address space * * Creates a mapping structure which holds information about used/unused * IO address ranges, which is required to perform memory allocation and @@ -1935,37 +1930,41 @@ struct dma_map_ops iommu_coherent_ops = { * arm_iommu_attach_device function. */ struct dma_iommu_mapping * -arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size, - int order) +arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size) { - unsigned int count = size >> (PAGE_SHIFT + order); + unsigned int bits = size >> PAGE_SHIFT; + unsigned int bitmap_size = BITS_TO_LONGS(bits) * sizeof(long); struct dma_iommu_mapping *mapping; - int extensions = 0; + int extensions = 1; int err = -ENOMEM; - if (!count) + if (!bitmap_size) return ERR_PTR(-EINVAL); + if (bitmap_size > PAGE_SIZE) { + extensions = bitmap_size / PAGE_SIZE; + bitmap_size = PAGE_SIZE; + } + mapping = kzalloc(sizeof(struct dma_iommu_mapping), GFP_KERNEL); if (!mapping) goto err; - mapping->bitmap_size = BITS_TO_LONGS(count) * sizeof(long); - mapping->bitmaps = kzalloc((extensions + 1) * sizeof(unsigned long *), + mapping->bitmap_size = bitmap_size; + mapping->bitmaps = kzalloc(extensions * sizeof(unsigned long *), GFP_KERNEL); if (!mapping->bitmaps) goto err2; - mapping->bitmaps[0] = kzalloc(mapping->bitmap_size, GFP_KERNEL); + mapping->bitmaps[0] = kzalloc(bitmap_size, GFP_KERNEL); if (!mapping->bitmaps[0]) goto err3; mapping->nr_bitmaps = 1; mapping->extensions = extensions; mapping->base = base; - mapping->size = size; - mapping->order = order; - mapping->bits = BITS_PER_BYTE * mapping->bitmap_size; + mapping->size = bitmap_size << PAGE_SHIFT; + mapping->bits = BITS_PER_BYTE * bitmap_size; spin_lock_init(&mapping->lock); diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.h b/drivers/gpu/drm/exynos/exynos_drm_drv.h index 0eaf5a2..a8f9dba 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.h +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h @@ -237,7 +237,6 @@ struct drm_exynos_file_private { * otherwise default one. * @da_space_size: size of device address space. * if 0 then default value is used for it. - * @da_space_order: order to device address space. */ struct exynos_drm_private { struct drm_fb_helper *fb_helper; @@ -255,7 +254,6 @@ struct exynos_drm_private { unsigned long da_start; unsigned long da_space_size; - unsigned long da_space_order; }; /* diff --git a/drivers/gpu/drm/exynos/exynos_drm_iommu.c b/drivers/gpu/drm/exynos/exynos_drm_iommu.c index fb8db03..b32b291 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_iommu.c +++ b/drivers/gpu/drm/exynos/exynos_drm_iommu.c @@ -36,12 +36,10 @@ int drm_create_iommu_mapping(struct drm_device *drm_dev) priv->da_start = EXYNOS_DEV_ADDR_START; if (!priv->da_space_size) priv->da_space_size = EXYNOS_DEV_ADDR_SIZE; - if (!priv->da_space_order) - priv->da_space_order = EXYNOS_DEV_ADDR_ORDER; mapping = arm_iommu_create_mapping(&platform_bus_type, priv->da_start, - priv->da_space_size, - priv->da_space_order); + priv->da_space_size); + if (IS_ERR(mapping)) return PTR_ERR(mapping); diff --git a/drivers/gpu/drm/exynos/exynos_drm_iommu.h b/drivers/gpu/drm/exynos/exynos_drm_iommu.h index 598e60f..72376d4 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_iommu.h +++ b/drivers/gpu/drm/exynos/exynos_drm_iommu.h @@ -14,7 +14,6 @@ #define EXYNOS_DEV_ADDR_START 0x20000000 #define EXYNOS_DEV_ADDR_SIZE 0x40000000 -#define EXYNOS_DEV_ADDR_ORDER 0x0 #ifdef CONFIG_DRM_EXYNOS_IOMMU diff --git a/drivers/iommu/shmobile-iommu.c b/drivers/iommu/shmobile-iommu.c index 7a3b928..464acda 100644 --- a/drivers/iommu/shmobile-iommu.c +++ b/drivers/iommu/shmobile-iommu.c @@ -343,7 +343,7 @@ static int shmobile_iommu_add_device(struct device *dev) mapping = archdata->iommu_mapping; if (!mapping) { mapping = arm_iommu_create_mapping(&platform_bus_type, 0, - L1_LEN << 20, 0); + L1_LEN << 20); if (IS_ERR(mapping)) return PTR_ERR(mapping); archdata->iommu_mapping = mapping;