Skip to contentSkip to conversation

Platform: goldfish: goldfish_pipe.c: Add DMA support using managed version

PATCH Superseded Shraddha Barke 2 participants 2 messages Jan 22, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Platform: goldfish: goldfish_pipe.c: Add DMA support using managed version

Function setup_access_params_addr is called only from probe function, hence managed version dmam_alloc_coherent is used.

setup_access_params_addr has 2 goals-

-Initialize the access_params field so that it can be used to send and read commands from the device in access_with_param
-Get a bus address for the allocated memory to transfer to the device.

Replace the combination of devm_kzalloc and _pa() with dmam_alloc_coherent. Coherent mapping guarantees that the device and CPU are in sync.

---
 drivers/platform/goldfish/goldfish_pipe.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/platform/goldfish/goldfish_pipe.c +11 -8
index e7a29e2..fb982ac 100644
@@ -57,6 +57,7 @@
 #include <linux/slab.h>
 #include <linux/io.h>
 #include <linux/goldfish.h>
+#include <linux/dma-mapping.h>
 
 /*
  * IMPORTANT: The following constants must match the ones used and defined
@@ -217,17 +218,19 @@ static int valid_batchbuffer_addr(struct goldfish_pipe_dev *dev,
 static int setup_access_params_addr(struct platform_device *pdev,
 					struct goldfish_pipe_dev *dev)
 {
-	u64 paddr;
+	dma_addr_t dma_handle;
 	struct access_params *aps;
 
-	aps = devm_kzalloc(&pdev->dev, sizeof(struct access_params), GFP_KERNEL);
-	if (!aps)
-		return -1;
+	aps = dmam_alloc_coherent(&pdev->dev, sizeof(struct access_params),
+				  &dma_handle, GFP_KERNEL);
+	if (!aps) {
+		dev_err(&pdev->dev, "allocate buffer failed\n");
+		return -ENOMEM;
+	}
 
-	/* FIXME */
-	paddr = __pa(aps);
-	writel((u32)(paddr >> 32), dev->base + PIPE_REG_PARAMS_ADDR_HIGH);
-	writel((u32)paddr, dev->base + PIPE_REG_PARAMS_ADDR_LOW);
+	writel((u32)((u64)dma_handle >> 32), dev->base +
+		PIPE_REG_PARAMS_ADDR_HIGH);
+	writel((u32)dma_handle, dev->base + PIPE_REG_PARAMS_ADDR_LOW);
 
 	if (valid_batchbuffer_addr(dev, aps)) {
 		dev->aps = aps;
Signature · 1 line
2.1.4
#1 lore raw
Quoted 2 lines · Shraddha Barke

Function setup_access_params_addr is called only from probe function, hence managed version dmam_alloc_coherent is used.

trivia:

drivers/platform/goldfish/goldfish_pipe.c

Quoted 1 line
drivers/platform/goldfish/goldfish_pipe.c +0 -0

[]

Quoted 8 lines
drivers/platform/goldfish/goldfish_pipe.c +1 -1
@@ -217,17 +218,19 @@ static int valid_batchbuffer_addr(struct goldfish_pipe_dev *dev,
  static int setup_access_params_addr(struct platform_device *pdev,
  					struct goldfish_pipe_dev *dev)
  {
-	u64 paddr;
+	dma_addr_t dma_handle;
  	struct access_params *aps;

drivers/platform/goldfish/goldfish_pipe.c static int valid_batchbuffer_addr(struct goldfish_pipe_dev *dev, · line 227

Quoted 7 lines
drivers/platform/goldfish/goldfish_pipe.c +4 -3
-	aps = devm_kzalloc(&pdev->dev, sizeof(struct access_params), GFP_KERNEL);
-	if (!aps)
-		return -1;
+	aps = dmam_alloc_coherent(&pdev->dev, sizeof(struct access_params),
+				  &dma_handle, GFP_KERNEL);
+	if (!aps) {
+		dev_err(&pdev->dev, "allocate buffer failed\n");

Unnecessary error message

drivers/platform/goldfish/goldfish_pipe.c static int valid_batchbuffer_addr(struct goldfish_pipe_dev *dev, · line 233

Quoted 10 lines
drivers/platform/goldfish/goldfish_pipe.c +2 -0
+		return -ENOMEM;
+	}

drivers/platform/goldfish/goldfish_pipe.c +3 -4
-	/* FIXME */
-	paddr = __pa(aps);
-	writel((u32)(paddr >> 32), dev->base + PIPE_REG_PARAMS_ADDR_HIGH);
-	writel((u32)paddr, dev->base + PIPE_REG_PARAMS_ADDR_LOW);
+	writel((u32)((u64)dma_handle >> 32), dev->base +
+		PIPE_REG_PARAMS_ADDR_HIGH);
+	writel((u32)dma_handle, dev->base + PIPE_REG_PARAMS_ADDR_LOW);

Probably better to use upper_32_bits and lower_32_bits