Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4108890imu; Mon, 10 Dec 2018 13:17:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/WJ3VSlQqxRpbtM+Yb5/s6rWEYsBXsQdpSmss8Q2/NEE3SqJE9fQS/yMDTekbXBZbYUAyHn X-Received: by 2002:a17:902:2c83:: with SMTP id n3mr13678111plb.104.1544476655461; Mon, 10 Dec 2018 13:17:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544476655; cv=none; d=google.com; s=arc-20160816; b=PCJwRRVr3LvevX7STWHEa9dGECLGhYojSL56DRQuZgCsqZAQW6lzIHA5jR34mMu1It 2+iGUlTMo7FNIFvoNHY/rIFCncdwKiTZQzkENPBLk2j8ryW0vOGrNXa1jeHSDuZq0S1a hiYFWAXD1/beJLCjNpBZxcOgd8MoHZPA4yBaUQ4p3y5t9dyh9bFxBFh85lIzmh2yeqYM 7OXfLRLAkgux21sUlF+a+mzAowqSVZS3U3Sl4yPQ0BQtYHxXACBqKDmIEWeuLOPOVI6C 6QDGDI6u1hulzoLK0/14I6ofh+urvRMBFiEQ02XULxXJ888ATvHqrxZlswoKTlHC8C6Q lsZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=6sexJ3sUxeyVZHeIHX2RL75Abr7umz+aeVLBVk1hrSo=; b=QVV+ng6O0vwRyvjkX3V8My/yjmf4BfN8zbykq3kdtA/QiOLroxsFHq4amRaUHJE1rI JQ7LrZrNjy5P93JNnAvR5MHBX5rK9OSkkxKtvUddUs6DSx22ExslOpaW59g81s/VpSim Hl8dZ2n9KF3KaSKzL8+lMRDGQCVfkxwxqpy8IMVNlO0gUgoqo064iO6yfhHUOe3dD8EQ KtND7fanOc7LSYOdIoObgAUxc+fdgTPgTg0E0+ygrui7O57I5g/eov99nyWSWFWKzHDM BIlWOZxyfuwrmXPiPeClFOCdSrJzJH4fgKBBzEqsoT19POsm0Wbv+mrFtP5ew+FXZ1yl f1dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r18si10728307pgb.491.2018.12.10.13.17.20; Mon, 10 Dec 2018 13:17:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbeLJTCC (ORCPT + 99 others); Mon, 10 Dec 2018 14:02:02 -0500 Received: from verein.lst.de ([213.95.11.211]:50554 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726024AbeLJTCB (ORCPT ); Mon, 10 Dec 2018 14:02:01 -0500 Received: by newverein.lst.de (Postfix, from userid 2407) id 2896B6732D; Mon, 10 Dec 2018 20:02:00 +0100 (CET) Date: Mon, 10 Dec 2018 20:02:00 +0100 From: Christoph Hellwig To: Sascha Hauer Cc: Christoph Hellwig , Shawn Guo , Fabio Estevam , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org Subject: Re: dma_declare_coherent_memory on main memory Message-ID: <20181210190159.GA30648@lst.de> References: <20181207153432.GA24917@lst.de> <20181210072648.ore6xttedsgpndi4@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181210072648.ore6xttedsgpndi4@pengutronix.de> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 10, 2018 at 08:26:48AM +0100, Sascha Hauer wrote: > > the ARM imx27/31 ports and various sh boards use > > dma_declare_coherent_memory on main memory taken from the memblock > > allocator. > > > > Is there any good reason these couldn't be switched to CMA areas? > > Getting rid of these magic dma_declare_coherent_memory area would > > help making the dma allocator a lot simpler. > > At least for i.MX27/31 I'd say this predates CMA support, so historical > reasons. Ok. Do you still have test hardware for i.MX? If so I'd love to see if the patch below works. Note that this is the brute force approach, just having a global CMA pool might be a little more elegant. diff --git a/arch/arm/configs/imx_v4_v5_defconfig b/arch/arm/configs/imx_v4_v5_defconfig index 8661dd9b064a..88852e7e5e7e 100644 --- a/arch/arm/configs/imx_v4_v5_defconfig +++ b/arch/arm/configs/imx_v4_v5_defconfig @@ -185,3 +185,5 @@ CONFIG_NLS_ISO8859_1=y CONFIG_NLS_ISO8859_15=m CONFIG_FONTS=y CONFIG_FONT_8x8=y +CONFIG_CMA=y +CONFIG_DMA_CMA=y diff --git a/arch/arm/configs/imx_v6_v7_defconfig b/arch/arm/configs/imx_v6_v7_defconfig index 1ad5736c8fa6..16c8d717316c 100644 --- a/arch/arm/configs/imx_v6_v7_defconfig +++ b/arch/arm/configs/imx_v6_v7_defconfig @@ -444,3 +444,5 @@ CONFIG_PROVE_LOCKING=y # CONFIG_DEBUG_BUGVERBOSE is not set # CONFIG_FTRACE is not set # CONFIG_ARM_UNWIND is not set +CONFIG_CMA=y +CONFIG_DMA_CMA=y diff --git a/arch/arm/mach-imx/mach-imx27_visstrim_m10.c b/arch/arm/mach-imx/mach-imx27_visstrim_m10.c index 5169dfba9718..2339a50d5459 100644 --- a/arch/arm/mach-imx/mach-imx27_visstrim_m10.c +++ b/arch/arm/mach-imx/mach-imx27_visstrim_m10.c @@ -23,6 +23,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -245,6 +247,7 @@ static phys_addr_t mx2_camera_base __initdata; static void __init visstrim_analog_camera_init(void) { struct platform_device *pdev; + struct cma *cma; gpio_set_value(TVP5150_PWDN, 1); ndelay(1); @@ -257,9 +260,10 @@ static void __init visstrim_analog_camera_init(void) if (IS_ERR(pdev)) return; - dma_declare_coherent_memory(&pdev->dev, mx2_camera_base, - mx2_camera_base, MX2_CAMERA_BUF_SIZE, - DMA_MEMORY_EXCLUSIVE); + if (cma_init_reserved_mem(mx2_camera_base, MX2_CAMERA_BUF_SIZE, 0, + "visstrim-cam", &cma)) + return; + dma_contiguous_early_fixup(mx2_camera_base, MX2_CAMERA_BUF_SIZE); } static void __init visstrim_reserve(void) @@ -440,13 +444,16 @@ static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = { static void __init visstrim_coda_init(void) { struct platform_device *pdev; + struct cma *cma; pdev = imx27_add_coda(); - dma_declare_coherent_memory(&pdev->dev, - mx2_camera_base + MX2_CAMERA_BUF_SIZE, - mx2_camera_base + MX2_CAMERA_BUF_SIZE, - MX2_CAMERA_BUF_SIZE, - DMA_MEMORY_EXCLUSIVE); + if (IS_ERR(pdev)) + return; + if (cma_init_reserved_mem(mx2_camera_base + MX2_CAMERA_BUF_SIZE, + MX2_CAMERA_BUF_SIZE, 0, "visstrim-coda", &cma)) + return; + dma_contiguous_early_fixup(mx2_camera_base + MX2_CAMERA_BUF_SIZE, + MX2_CAMERA_BUF_SIZE); } /* DMA deinterlace */ @@ -459,21 +466,22 @@ static void __init visstrim_deinterlace_init(void) { int ret = -ENOMEM; struct platform_device *pdev = &visstrim_deinterlace; + struct cma *cma; ret = platform_device_register(pdev); - dma_declare_coherent_memory(&pdev->dev, - mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE, - mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE, - MX2_CAMERA_BUF_SIZE, - DMA_MEMORY_EXCLUSIVE); + if (cma_init_reserved_mem(mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE, + MX2_CAMERA_BUF_SIZE, 0, "visstrim-deinterlace", &cma)) + return; + dma_contiguous_early_fixup(mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE, + MX2_CAMERA_BUF_SIZE); } /* Emma-PrP for format conversion */ static void __init visstrim_emmaprp_init(void) { struct platform_device *pdev; - int ret; + struct cma *cma; pdev = imx27_add_mx2_emmaprp(); if (IS_ERR(pdev)) @@ -483,12 +491,12 @@ static void __init visstrim_emmaprp_init(void) * Use the same memory area as the analog camera since both * devices are, by nature, exclusive. */ - ret = dma_declare_coherent_memory(&pdev->dev, - mx2_camera_base, mx2_camera_base, - MX2_CAMERA_BUF_SIZE, - DMA_MEMORY_EXCLUSIVE); - if (ret) + if (cma_init_reserved_mem(mx2_camera_base, MX2_CAMERA_BUF_SIZE, 0, + "visstrim-emmaprp", &cma)) { pr_err("Failed to declare memory for emmaprp\n"); + return; + } + dma_contiguous_early_fixup(mx2_camera_base, MX2_CAMERA_BUF_SIZE); } /* Audio */ diff --git a/arch/arm/mach-imx/mach-mx31moboard.c b/arch/arm/mach-imx/mach-mx31moboard.c index 643a3d749703..1c0705ec0ccd 100644 --- a/arch/arm/mach-imx/mach-mx31moboard.c +++ b/arch/arm/mach-imx/mach-mx31moboard.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -37,6 +38,7 @@ #include #include +#include #include #include #include @@ -466,6 +468,7 @@ static int __init mx31moboard_init_cam(void) { int ret; struct platform_device *pdev; + struct cma *cma; imx31_add_ipu_core(); @@ -473,18 +476,18 @@ static int __init mx31moboard_init_cam(void) if (IS_ERR(pdev)) return PTR_ERR(pdev); - ret = dma_declare_coherent_memory(&pdev->dev, - mx3_camera_base, mx3_camera_base, - MX3_CAMERA_BUF_SIZE, - DMA_MEMORY_EXCLUSIVE); + ret = cma_init_reserved_mem(mx3_camera_base, MX3_CAMERA_BUF_SIZE, 0, + "mx31cam", &cma); if (ret) - goto err; + goto out_device_put; + dma_contiguous_early_fixup(mx3_camera_base, MX3_CAMERA_BUF_SIZE); ret = platform_device_add(pdev); if (ret) -err: - platform_device_put(pdev); - + goto out_device_put; + return 0; +out_device_put: + platform_device_put(pdev); return ret; }