Skip to contentSkip to conversation

dma_declare_coherent_memory on main memory

DISCUSSION Christoph Hellwig 3 participants 4 messages Dec 7, 2018 – Dec 10, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi all,

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.

#1 lore raw
Quoted 9 lines · Christoph Hellwig

Hi all,

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.

Not that I know of?

Rob

maintainer
#2 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

Hi all,

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.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#3 lore raw
Quoted 10 lines · Sascha Hauer
Quoted 7 lines

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.

arch/arm/configs/imx_v4_v5_defconfig +2 -0
index 8661dd9b064a..88852e7e5e7e 100644
@@ -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
arch/arm/configs/imx_v6_v7_defconfig +2 -0
index 1ad5736c8fa6..16c8d717316c 100644
@@ -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
arch/arm/mach-imx/mach-imx27_visstrim_m10.c +27 -19

100 lines not on this page · raw message

arch/arm/mach-imx/mach-mx31moboard.c +11 -8
index 643a3d749703..1c0705ec0ccd 100644
@@ -13,6 +13,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/cma.h>
 #include <linux/dma-mapping.h>
 #include <linux/gfp.h>
 #include <linux/gpio.h>
@@ -37,6 +38,7 @@
 #include <linux/usb/otg.h>
 #include <linux/usb/ulpi.h>
 
+#include <asm/dma-contiguous.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/time.h>
@@ -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;
 
 }