From patchwork Mon Sep 15 13:41:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 4905441 Return-Path: X-Original-To: patchwork-linux-sh@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 77959BEEA5 for ; Mon, 15 Sep 2014 13:39:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1E0C6201DE for ; Mon, 15 Sep 2014 13:39:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A8B75201C0 for ; Mon, 15 Sep 2014 13:39:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751847AbaIONjV (ORCPT ); Mon, 15 Sep 2014 09:39:21 -0400 Received: from mail-pd0-f178.google.com ([209.85.192.178]:57185 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751561AbaIONjU (ORCPT ); Mon, 15 Sep 2014 09:39:20 -0400 Received: by mail-pd0-f178.google.com with SMTP id p10so6265946pdj.37 for ; Mon, 15 Sep 2014 06:39:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:date:message-id:subject; bh=UVSiO8vn742/fwMKRmAIv50JuCcrWpjoh6UNk7i50tQ=; b=FRt5e7R22jbBBSsj8sWr/8Vfxd0xWqOKdKu2XkewnR/hbOUHkNBUV/ONiT+TsGHrrx 5fzrdsXoi3vF82iAHxIlww1brFrnmoJQuzh28N4rEb6+AOva+J/QOMmInyFRKmgq1dTf pcVCIWKkbCkCPc4oi+z/aOccw5iARBgI2mSA3CCv4NRO1ilCCFHx4ODAz6q348JgrD4Y OJrtRlPwoLo5ttR/qVUDAou8uYJmIBAIRY/jLauugT+ZYJRM7hvq66FM0t5Ip21j+fUb rE95UZQza5l4cIuBfDmJWsaNw5OXqaaCdsNazHEKka41zSmUSFWoTcQUXAAj5yzMJ+RE frUQ== X-Received: by 10.66.90.162 with SMTP id bx2mr38504350pab.39.1410788360115; Mon, 15 Sep 2014 06:39:20 -0700 (PDT) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by mx.google.com with ESMTPSA id cu3sm11495555pbb.48.2014.09.15.06.39.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Sep 2014 06:39:18 -0700 (PDT) From: Magnus Damm To: linux-sh@vger.kernel.org Cc: Magnus Damm Date: Mon, 15 Sep 2014 22:41:41 +0900 Message-Id: <20140915134141.21545.86917.sendpatchset@w520> Subject: [PATCH] ARM: shmobile: CMA prototype test code Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 From: Magnus Damm This is some basic prototype code that uses CMA to reserve a 256 MiB physically contiguous memory window at 0x7000000. It may be used on r8a7790 Lager, r8a7791 Koelsch or r8a7794 Alt. Through some hackish test code it then allocates several 16MiB chunks with 16MiB alignment from the CMA window. The following kernel configuration parameters are required: CONFIG_CMA=y CONFIG_DMA_CMA=y A couple of notes about known short comings: - The default CMA area is overriden - a new CMA area should be added instead - NULL is passed as struct device * - the driver model should be used - The test is allocating 15 times to keep some space in the default CMA area For information about the DMA API and the DMA attributes, please see: Documentation/DMA-API-HOWTO.txt Documentation/DMA-API.txt Documentation/DMA-attributes.txt Not for upstream merge. Written to show how CMA can be used to reserve and allocate memory. Not-Yet-Signed-off-by: Magnus Damm --- Based on "[PATCH] ARM: shmobile: CMA prototype test code for Koelsch" Written on top of renesas-devel-20140911-v3.17-rc4, tested on Lager. arch/arm/mach-shmobile/Makefile | 2 - arch/arm/mach-shmobile/cma-test.c | 58 ++++++++++++++++++++++++++++++ arch/arm/mach-shmobile/setup-rcar-gen2.c | 3 + 3 files changed, 62 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0001/arch/arm/mach-shmobile/Makefile +++ work/arch/arm/mach-shmobile/Makefile 2014-09-15 18:37:32.000000000 +0900 @@ -3,7 +3,7 @@ # # Common objects -obj-y := timer.o console.o +obj-y := timer.o console.o cma-test.o # CPU objects obj-$(CONFIG_ARCH_SH7372) += setup-sh7372.o intc-sh7372.o pm-sh7372.o --- /dev/null +++ work/arch/arm/mach-shmobile/cma-test.c 2014-09-15 18:37:33.000000000 +0900 @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include + +static int do_alloc(struct device *dev, unsigned int size, unsigned int align, + phys_addr_t *paddr) +{ + /* use CMA directly if one of the following is true + * - explicit alignment is required + * - no IOMMU is available (dma-mapping.c for ARM ignores attrs) + */ + if (!iommu_present(&platform_bus_type) || (align != size)) { + struct page *p; + + p = dma_alloc_from_contiguous(dev, size, align); + if (!p) + return -ENOMEM; + + *paddr = page_to_phys(p); + } else { + DEFINE_DMA_ATTRS(attrs); + void *p; + + /* a few lines derived from drivers/gpu/drm/msm/msm_drv.c */ + dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs); + dma_set_attr(DMA_ATTR_FORCE_CONTIGUOUS, &attrs); + + /* note that for no-kernel-mapping, the vaddr returned + * is bogus, but non-null if allocation succeeded: + */ + p = dma_alloc_attrs(dev, size, paddr, 0, &attrs); + if (!p) + return -ENOMEM; + } + + return 0; +} + +static int __init test_cma(void) +{ + unsigned int align_order = SZ_16M >> PAGE_SHIFT; + unsigned int size_pages = SZ_16M >> PAGE_SHIFT; + unsigned int k; + unsigned int success = 0; + phys_addr_t p; + + for (k = 0; k < ((256 / 16) - 1); k++) + if (do_alloc(NULL, size_pages, align_order, &p) == 0) + success++; + + pr_info("CMA test succeeded %d times\n", success); + + return 0; +} + +late_initcall(test_cma) --- 0001/arch/arm/mach-shmobile/setup-rcar-gen2.c +++ work/arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-09-15 18:48:15.000000000 +0900 @@ -177,6 +177,9 @@ void __init rcar_gen2_reserve(void) of_scan_flat_dt(rcar_gen2_scan_mem, &mrc); #ifdef CONFIG_DMA_CMA + /* override default CMA area */ + dma_contiguous_reserve_area(0x10000000, 0x70000000, 0xffffffff, + &dma_contiguous_default_area, true); if (mrc.size) dma_contiguous_reserve_area(mrc.size, mrc.base, 0, &rcar_gen2_dma_contiguous, true);