From patchwork Thu May 17 16:53:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 8769 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D7E0923F04 for ; Thu, 17 May 2012 16:53:39 +0000 (UTC) Received: from mail-qa0-f53.google.com (mail-qa0-f53.google.com [209.85.216.53]) by fiordland.canonical.com (Postfix) with ESMTP id AA3D8A18B7E for ; Thu, 17 May 2012 16:53:39 +0000 (UTC) Received: by mail-qa0-f53.google.com with SMTP id z32so2209443qad.19 for ; Thu, 17 May 2012 09:53:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :mime-version:date:from:in-reply-to:to:message-id:x-mailer :references:cc:subject:x-beenthere:x-mailman-version:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:content-type:content-transfer-encoding:sender :errors-to:x-gm-message-state; bh=gr9K1PDIqNjS17YIhl6tvHsJqZ/sZHxG9z5pHF1jP38=; b=X0XxJ3y6KoHMSh7rOBHFtc95mGGu+gvW39YOCuktrXxqVhTQBPRv78RIsh/7LDAP5h LeBz2I3Qk0lMNRFEsyfhpSPVgYiV/RCuyG1iiomgGW/Jkb5lgiy7MBoyXUlFn/1YDHif 4yz0VHZrSSfwBJNETwP9y/JoH8HruITUeGC9aixLyJg5olPpExiZMUAD8AfTZAR/qpFW cqGxGSCwpuufEIcoKouQJEReF6l10uLcvfKMbvXkPewxuSuLvKGwxVQtpJdGsGrOS9JR Grd763McG4/x9XknQTo9rjZU/4WI92PbMhIzYMGr6KlbEby/1DLYmlpOY0JgYP0zwbfj MISg== Received: by 10.50.154.169 with SMTP id vp9mr14127178igb.53.1337273619203; Thu, 17 May 2012 09:53:39 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp41938ibd; Thu, 17 May 2012 09:53:35 -0700 (PDT) Received: by 10.180.84.4 with SMTP id u4mr20112696wiy.2.1337273615385; Thu, 17 May 2012 09:53:35 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id d24si8101748wed.139.2012.05.17.09.53.33; Thu, 17 May 2012 09:53:35 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SV3xC-00006A-2m; Thu, 17 May 2012 16:53:30 +0000 Received: from mailout3.w1.samsung.com ([210.118.77.13]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SV3xA-00004t-Gt for linaro-mm-sig@lists.linaro.org; Thu, 17 May 2012 16:53:28 +0000 MIME-version: 1.0 Received: from euspt1 ([210.118.77.13]) by mailout3.w1.samsung.com (Sun Java(tm) System Messaging Server 6.3-8.04 (built Jul 29 2009; 32bit)) with ESMTP id <0M46006J3EVT6K70@mailout3.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 17 May 2012 17:52:41 +0100 (BST) Received: from ubuntu.arm.acom ([106.210.236.191]) by spt1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0M46008IQEWVMY@spt1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 17 May 2012 17:53:27 +0100 (BST) Date: Thu, 17 May 2012 18:53:05 +0200 From: Marek Szyprowski In-reply-to: <1337273586-11089-1-git-send-email-m.szyprowski@samsung.com> To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Message-id: <1337273586-11089-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.10.1 References: <1337273586-11089-1-git-send-email-m.szyprowski@samsung.com> Cc: Abhinav Kochhar , Russell King - ARM Linux , Arnd Bergmann , Konrad Rzeszutek Wilk , Benjamin Herrenschmidt , Kyungmin Park , Subash Patel Subject: [Linaro-mm-sig] [PATCH 2/3] ARM: dma-mapping: add support for DMA_ATTR_NO_KERNEL_MAPPING attribute X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQkVDuQd5QuxTBxqC84cfQyuYRsMwBqJPy61ImAWiET0dAekELFIkwqUwaK1TR/KoQFrjBAc This patch adds support for DMA_ATTR_NO_KERNEL_MAPPING attribute for IOMMU allocations, what let drivers to save precious kernel virtual address space for large buffers that are intended to be accessed only from userspace. This patch is heavily based on initial work kindly provided by Abhinav Kochhar . Signed-off-by: Marek Szyprowski --- arch/arm/mm/dma-mapping.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 2e98403..23d0ace 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -940,9 +940,13 @@ static int __iommu_remove_mapping(struct device *dev, dma_addr_t iova, size_t si return 0; } -static struct page **__iommu_get_pages(void *cpu_addr) +static struct page **__iommu_get_pages(void *cpu_addr, struct dma_attrs *attrs) { struct vm_struct *area; + + if (dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs)) + return cpu_addr; + read_lock(&vmlist_lock); area = find_vm_area(cpu_addr); read_unlock(&vmlist_lock); @@ -969,6 +973,9 @@ static void *arm_iommu_alloc_attrs(struct device *dev, size_t size, if (*handle == DMA_ERROR_CODE) goto err_buffer; + if (dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs)) + return pages; + addr = __iommu_alloc_remap(pages, size, gfp, prot, __builtin_return_address(0)); if (!addr) @@ -989,7 +996,7 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, { unsigned long uaddr = vma->vm_start; unsigned long usize = vma->vm_end - vma->vm_start; - struct page **pages = __iommu_get_pages(cpu_addr); + struct page **pages = __iommu_get_pages(cpu_addr, attrs); vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot); @@ -1016,7 +1023,7 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle, struct dma_attrs *attrs) { - struct page **pages = __iommu_get_pages(cpu_addr); + struct page **pages = __iommu_get_pages(cpu_addr, attrs); size = PAGE_ALIGN(size); if (!pages) { @@ -1026,8 +1033,11 @@ void arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr, return; } - unmap_kernel_range((unsigned long)cpu_addr, size); - vunmap(cpu_addr); + if (!dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs)) { + unmap_kernel_range((unsigned long)cpu_addr, size); + vunmap(cpu_addr); + } + __iommu_remove_mapping(dev, handle, size); __iommu_free_buffer(dev, pages, size); }