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: 25292 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C054320543 for ; Tue, 25 Feb 2014 12:43:45 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id w8sf712294qac.0 for ; Tue, 25 Feb 2014 04:43:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=wzZJVRGvw9GeKGZNVriRnR9iaIbzRl/KnkcR7aVRRP8=; b=RLt3U8QjbhWF/dKAvcAboI+0GccZgO8v7I1rGsgTzcpNzUZfqi6ANVVovCH5E0VEV4 6FHpiLzgWXMgLAnMHsDeheimpB+GmhUAyG8rqNS/mDpKN8RkxI1d0UADohn6g2LZkh31 3cHB0PzvEloYOZ2zzlgVnV+GDhxKdq81dKoviYnRHUT8QE6IqBDEL3YGma6lmx34NV/c B0oaNmYkc8IzZbf4vsOEO/zwMh8UBI9pIeUeYScj3wh2Fb+brZc3h8fRegJfnDUVIiie X0tWinZDPf8y/qFjV3R3mfHBV1iprZTg0BwtL0E+p5Rh7O9LBU0NQXDbtBZ/CCOUneMF 4chQ== X-Gm-Message-State: ALoCoQn6LsJEuHmXKP03jsabe7sGRwb2PRLXQAdPPsPmeWt+6mWCo5WG3Klar0K1be9BL7ZOmmRm X-Received: by 10.236.85.100 with SMTP id t64mr1680536yhe.29.1393332225564; Tue, 25 Feb 2014 04:43:45 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.117 with SMTP id z108ls486594qge.51.gmail; Tue, 25 Feb 2014 04:43:45 -0800 (PST) X-Received: by 10.52.104.68 with SMTP id gc4mr862765vdb.2.1393332225339; Tue, 25 Feb 2014 04:43:45 -0800 (PST) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id ru2si6759379vcb.104.2014.02.25.04.43.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 04:43:45 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id jw12so338184veb.26 for ; Tue, 25 Feb 2014 04:43:45 -0800 (PST) X-Received: by 10.52.171.39 with SMTP id ar7mr770480vdc.5.1393332225249; Tue, 25 Feb 2014 04:43:45 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp136113vcz; Tue, 25 Feb 2014 04:43:37 -0800 (PST) X-Received: by 10.180.100.72 with SMTP id ew8mr19656974wib.16.1393332182771; Tue, 25 Feb 2014 04:43:02 -0800 (PST) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id fw15si403637wic.33.2014.02.25.04.43.02 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 25 Feb 2014 04:43:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WIHKL-000147-3o; Tue, 25 Feb 2014 12:41:37 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WIHK9-000136-NI for linaro-mm-sig@lists.linaro.org; Tue, 25 Feb 2014 12:41:26 +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 linaro-mm-sig@lists.linaro.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 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 Cc: Russell King , Andreas Herrmann , Joerg Roedel , Will Deacon Subject: [Linaro-mm-sig] [PATCH 2/2] arm: dma-mapping: remove order parameter from arm_iommu_create_mapping() X-BeenThere: linaro-mm-sig@lists.linaro.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 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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;