From patchwork Fri Jul 13 18:01:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 1196541 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 B6254DFFFD for ; Fri, 13 Jul 2012 18:06: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 1SpkDA-0000g6-1V; Fri, 13 Jul 2012 18:03:28 +0000 Received: from wolverine01.qualcomm.com ([199.106.114.254]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SpkCW-0000eW-OS for linux-arm-kernel@lists.infradead.org; Fri, 13 Jul 2012 18:02:49 +0000 X-IronPort-AV: E=McAfee;i="5400,1158,6771"; a="210398073" Received: from pdmz-ns-mip.qualcomm.com (HELO mostmsg01.qualcomm.com) ([199.106.114.10]) by wolverine01.qualcomm.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 13 Jul 2012 11:02:07 -0700 Received: from lauraa-linux.qualcomm.com (pdmz-ns-snip_218_1.qualcomm.com [192.168.218.1]) by mostmsg01.qualcomm.com (Postfix) with ESMTPA id 3599210004B1; Fri, 13 Jul 2012 11:02:06 -0700 (PDT) From: Laura Abbott To: linaro-mm-sig@lists.linaro.org, Marek Szyprowski , Russell King Subject: [PATCH][RFC] arm: dma-mapping: Add support for allocating/mapping cached buffers Date: Fri, 13 Jul 2012 11:01:46 -0700 Message-Id: <1342202506-12449-2-git-send-email-lauraa@codeaurora.org> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1342202506-12449-1-git-send-email-lauraa@codeaurora.org> References: <1342202506-12449-1-git-send-email-lauraa@codeaurora.org> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [199.106.114.254 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-arm-msm@vger.kernel.org, Laura Abbott , linux-arm-kernel@lists.infradead.org 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 There are currently no dma allocation APIs that support cached buffers. For some use cases, caching provides a signficiant performance boost that beats write-combining regions. Add apis to allocate and map a cached DMA region. Signed-off-by: Laura Abbott --- arch/arm/include/asm/dma-mapping.h | 21 +++++++++++++++++++++ arch/arm/mm/dma-mapping.c | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index dc988ff..1565403 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -239,12 +239,33 @@ int dma_mmap_coherent(struct device *, struct vm_area_struct *, extern void *dma_alloc_writecombine(struct device *, size_t, dma_addr_t *, gfp_t); +/** + * dma_alloc_cached - allocate cached memory for DMA + * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices + * @size: required memory size + * @handle: bus-specific DMA address + * + * Allocate some cached memory for a device for + * performing DMA. This function allocates pages, and will + * return the CPU-viewed address, and sets @handle to be the + * device-viewed address. + */ +extern void *dma_alloc_cached(struct device *, size_t, dma_addr_t *, + gfp_t); + #define dma_free_writecombine(dev,size,cpu_addr,handle) \ dma_free_coherent(dev,size,cpu_addr,handle) +#define dma_free_cached(dev,size,cpu_addr,handle) \ + dma_free_coherent(dev,size,cpu_addr,handle) + int dma_mmap_writecombine(struct device *, struct vm_area_struct *, void *, dma_addr_t, size_t); + +int dma_mmap_cached(struct device *, struct vm_area_struct *, + void *, dma_addr_t, size_t); + /* * This can be called during boot to increase the size of the consistent * DMA region above it's default value of 2MB. It must be called before the diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index b1911c4..f396ddc 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -633,6 +633,20 @@ dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *handle, gfp_ } EXPORT_SYMBOL(dma_alloc_writecombine); +/* + * Allocate a cached DMA region + */ +void * +dma_alloc_cached(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp) +{ + return __dma_alloc(dev, size, handle, gfp, + pgprot_kernel, + __builtin_return_address(0)); +} +EXPORT_SYMBOL(dma_alloc_cached); + + + static int dma_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size) { @@ -664,6 +678,13 @@ int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma, } EXPORT_SYMBOL(dma_mmap_writecombine); +int dma_mmap_cached(struct device *dev, struct vm_area_struct *vma, + void *cpu_addr, dma_addr_t dma_addr, size_t size) +{ + return dma_mmap(dev, vma, cpu_addr, dma_addr, size); +} +EXPORT_SYMBOL(dma_mmap_cached); + /* * Free a buffer as defined by the above mapping.