Skip to contentSkip to conversation

Support for QCOM BAM DMA command descriptor

PATCH Applied Abhishek Sahu 2 participants 5 messages Aug 1, 2017 – Aug 28, 2017

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

v3 cover Support for QCOM BAM DMA command descriptor

v3:

1. Added Documentation for new flag
2. Changed the flag description

v2:

1. Added DMA_PREP_CMD flag and used the same for BAM DMA command descriptor
2. Removed custom mapping API patches

v1:

https://www.spinics.net/lists/dmaengine/msg12009.html

These patches mainly add the support for QCOM BAM command descriptor implementing BAM DMA support for some QCOM peripherals like QPIC NAND/LCD.

Currently there is no flag in DMA API which tells the DMA controller that the passed data is in command descriptor format so added the flag in DMA API for this.

Abhishek Sahu (3):
dmaengine: add DMA_PREP_CMD for non-Data descriptors.
dmaengine: qcom: bam_dma: wrapper functions for command descriptor
dmaengine: qcom: bam_dma: add command descriptor flag

 Documentation/dmaengine/provider.txt |  7 ++++
 drivers/dma/qcom/bam_dma.c           |  6 ++-
 include/linux/dma/qcom_bam_dma.h     | 79 ++++++++++++++++++++++++++++++++++++
 include/linux/dmaengine.h            |  4 ++
 4 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 include/linux/dma/qcom_bam_dma.h
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

PATCH v3 1/3 dmaengine: add DMA_PREP_CMD for non-Data descriptors.

Some of the DMA controllers are capable of issuing the commands to peripheral by the DMA. These commands can be list of register reads/writes and its different from normal data reads/writes. This patch adds new flag DMA_PREP_CMD in DMA API which tells the driver that the data passed to DMA API is command data and DMA controller driver will form descriptor in the required format.

This flag can be used by any DMA controller driver which requires the descriptor in different format for non-Data descriptors.

---
 Documentation/dmaengine/provider.txt | 7 +++++++
 include/linux/dmaengine.h            | 4 ++++
 2 files changed, 11 insertions(+)
Documentation/dmaengine/provider.txt +7 -0
index e33bc1c..bfadbfd 100644
@@ -395,6 +395,13 @@ where to put them)
 	  when DMA_CTRL_REUSE is already set
 	- Terminating the channel
 
+  * DMA_PREP_CMD
+    - If set, the client driver tells DMA controller that passed data in DMA
+      API is command data.
+    - Interpretation of command data is DMA controller specific. It can be
+      used for issuing commands to other peripherals/register reads/register
+      writes for which the descriptor should be in different format from
+      normal data descriptors.
 
 General Design Notes
 --------------------
include/linux/dmaengine.h +4 -0
index 5336808..45fc833 100644
@@ -186,6 +186,9 @@ struct dma_interleaved_template {
  *  on the result of this operation
  * @DMA_CTRL_REUSE: client can reuse the descriptor and submit again till
  *  cleared or freed
+ * @DMA_PREP_CMD: tell the driver that the data passed to DMA API is command
+ *  data and the descriptor should be in different format from normal
+ *  data descriptors.
  */
 enum dma_ctrl_flags {
 	DMA_PREP_INTERRUPT = (1 << 0),
@@ -195,6 +198,7 @@ enum dma_ctrl_flags {
 	DMA_PREP_CONTINUE = (1 << 4),
 	DMA_PREP_FENCE = (1 << 5),
 	DMA_CTRL_REUSE = (1 << 6),
+	DMA_PREP_CMD = (1 << 7),
 };
 
 /**
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#2 lore raw

PATCH v3 2/3 dmaengine: qcom: bam_dma: wrapper functions for command descriptor

In reply to Abhishek Sahu

QCOM BAM also supports command descriptor which allows the SW to create descriptors of type command which does not generate any data transmissions but configures registers in the peripheral. In command descriptor the 32bit address point to the start of the command block which holds the command elements and the 16bit size define the size of the command block.

Each Command Element is structured by 4 words:
Write command: address + cmd
register data
register mask
reserved

Read command: address + cmd
read data result address,
reserved
reserved

This patch creates a new header file for BAM driver which contains the structures and wrapper functions for command descriptor. This file will be used by different QCOM peripheral drivers for forming the command descriptor

---
 include/linux/dma/qcom_bam_dma.h | 79 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 include/linux/dma/qcom_bam_dma.h
include/linux/dma/qcom_bam_dma.h new file +79 -0
new file mode 100644
index 0000000..077d43a
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _QCOM_BAM_DMA_H
+#define _QCOM_BAM_DMA_H
+
+#include <asm/byteorder.h>
+
+/*
+ * This data type corresponds to the native Command Element
+ * supported by BAM DMA Engine.
+ *
+ * @cmd_and_addr - upper 8 bits command and lower 24 bits register address.
+ * @data - for write command: content to be written into peripheral register.
+ *	   for read command: dest addr to write peripheral register value.
+ * @mask - register mask.
+ * @reserved - for future usage.
+ *
+ */
+struct bam_cmd_element {
+	__le32 cmd_and_addr;
+	__le32 data;
+	__le32 mask;
+	__le32 reserved;
+};
+
+/*
+ * This enum indicates the command type in a command element
+ */
+enum bam_command_type {
+	BAM_WRITE_COMMAND = 0,
+	BAM_READ_COMMAND,
+};
+
+/*
+ * prep_bam_ce_le32 - Wrapper function to prepare a single BAM command
+ * element with the data already in le32 format.
+ *
+ * @bam_ce: bam command element
+ * @addr: target address
+ * @cmd: BAM command
+ * @data: actual data for write and dest addr for read in le32
+ */
+static inline void
+bam_prep_ce_le32(struct bam_cmd_element *bam_ce, u32 addr,
+		 enum bam_command_type cmd, __le32 data)
+{
+	bam_ce->cmd_and_addr =
+		cpu_to_le32((addr & 0xffffff) | ((cmd & 0xff) << 24));
+	bam_ce->data = data;
+	bam_ce->mask = cpu_to_le32(0xffffffff);
+}
+
+/*
+ * bam_prep_ce - Wrapper function to prepare a single BAM command element
+ * with the data.
+ *
+ * @bam_ce: BAM command element
+ * @addr: target address
+ * @cmd: BAM command
+ * @data: actual data for write and dest addr for read
+ */
+static inline void
+bam_prep_ce(struct bam_cmd_element *bam_ce, u32 addr,
+	    enum bam_command_type cmd, u32 data)
+{
+	bam_prep_ce_le32(bam_ce, addr, cmd, cpu_to_le32(data));
+}
+#endif
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#3 lore raw

PATCH v3 3/3 dmaengine: qcom: bam_dma: add command descriptor flag

In reply to Abhishek Sahu

If DMA_PREP_CMD flag is passed in prep_slave_sg then peripheral driver has passed the data is in BAM command descriptor format and BAM driver should set CMD bit for each of the HW descriptors.

---
 drivers/dma/qcom/bam_dma.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/dma/qcom/bam_dma.c +5 -1
index 03c4eb3..6d89fb6 100644
@@ -65,6 +65,7 @@ struct bam_desc_hw {
 #define DESC_FLAG_EOT BIT(14)
 #define DESC_FLAG_EOB BIT(13)
 #define DESC_FLAG_NWD BIT(12)
+#define DESC_FLAG_CMD BIT(11)
 
 struct bam_async_desc {
 	struct virt_dma_desc vd;
@@ -645,6 +646,9 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,
 		unsigned int curr_offset = 0;
 
 		do {
+			if (flags & DMA_PREP_CMD)
+				desc->flags |= cpu_to_le16(DESC_FLAG_CMD);
+
 			desc->addr = cpu_to_le32(sg_dma_address(sg) +
 						 curr_offset);
 
@@ -960,7 +964,7 @@ static void bam_start_dma(struct bam_chan *bchan)
 
 	/* set any special flags on the last descriptor */
 	if (async_desc->num_desc == async_desc->xfer_len)
-		desc[async_desc->xfer_len - 1].flags =
+		desc[async_desc->xfer_len - 1].flags |=
 					cpu_to_le16(async_desc->flags);
 	else
 		desc[async_desc->xfer_len - 1].flags |=
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Applied
#4 lore raw
In reply to Abhishek Sahu
Quoted 15 lines · Abhishek Sahu

v3:

1. Added Documentation for new flag
2. Changed the flag description

v2:

1. Added DMA_PREP_CMD flag and used the same for BAM DMA command descriptor
2. Removed custom mapping API patches

v1:

https://www.spinics.net/lists/dmaengine/msg12009.html

Quoted 7 lines

These patches mainly add the support for QCOM BAM command descriptor implementing BAM DMA support for some QCOM peripherals like QPIC NAND/LCD.

Currently there is no flag in DMA API which tells the DMA controller that the passed data is in command descriptor format so added the flag in DMA API for this.

Applied, thanks

Quoted 19 lines

Abhishek Sahu (3):
dmaengine: add DMA_PREP_CMD for non-Data descriptors.
dmaengine: qcom: bam_dma: wrapper functions for command descriptor
dmaengine: qcom: bam_dma: add command descriptor flag

 Documentation/dmaengine/provider.txt |  7 ++++
 drivers/dma/qcom/bam_dma.c           |  6 ++-
 include/linux/dma/qcom_bam_dma.h     | 79 ++++++++++++++++++++++++++++++++++++
 include/linux/dmaengine.h            |  4 ++
 4 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 include/linux/dma/qcom_bam_dma.h
Signature · 6 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
~Vinod