Skip to contentSkip to conversation

dma: add Qualcomm Technologies HIDMA management driver

PATCH Superseded Sinan Kaya 8 participants 51 messages Oct 30, 2015 – Nov 4, 2015

Subsystems (3)

v1 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

PATCH 1/2 dma: add Qualcomm Technologies HIDMA management driver

The Qualcomm Technologies HIDMA device has been designed to support virtualization technology. The driver has been divided into two to follow the hardware design. The management driver is executed in hypervisor context and is the main managment for all channels provided by the device. The channel driver is exected in the guest OS context.

---
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  42 +
 drivers/dma/Kconfig                                |  11 +
 drivers/dma/Makefile                               |   1 +
 drivers/dma/qcom_hidma_mgmt.c                      | 868 +++++++++++++++++++++
 4 files changed, 922 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt
 create mode 100644 drivers/dma/qcom_hidma_mgmt.c
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +42 -0
new file mode 100644
index 0000000..81674ab
@@ -0,0 +1,42 @@
+Qualcomm Technologies HIDMA Management interface
+
+Required properties:
+- compatible: must contain "qcom,hidma_mgmt"
+- reg: Address range for DMA device
+- interrupts: Should contain the one interrupt shared by all channels
+- nr-channels: Number of channels supported by this DMA controller.
+- max-write: Maximum write burst in bytes. A memcpy requested is
+  fragmented to multiples of this amount.
+- max-read: Maximum read burst in bytes. A memcpy request is
+  fragmented to multiples of this amount.
+- max-wxactions: Maximum write transactions to perform in a burst
+- max-rdactions: Maximum read transactions to perform in a burst
+- max-memset-limit: Maximum memset limit
+- ch-priority-#n: Priority of the channel
+- ch-weight-#n: Round robin weight of the channel
+Example:
+
+	hidma-mgmt@f9984000 = {
+		compatible = "qcom,hidma_mgmt";
+		reg = <0xf9984000 0x15000>;
+		interrupts = <0 94 0>;
+		nr-channels = 6;
+		max-write = 1024;
+		max-read = 1024;
+		max-wxactions = 31;
+		max-rdactions = 31;
+		max-memset-limit = 8;
+		ch-priority-0 = 0;
+		ch-priority-1 = 1;
+		ch-priority-2 = 1;
+		ch-priority-3 = 0;
+		ch-priority-4 = 0;
+		ch-priority-5 = 0;
+		ch-weight-0 = 1;
+		ch-weight-1 = 13;
+		ch-weight-2 = 10;
+		ch-weight-3 = 3;
+		ch-weight-4 = 4;
+		ch-weight-5 = 5;
+	};
+
drivers/dma/Kconfig +11 -0
index b458475..76a5a5e 100644
@@ -501,6 +501,17 @@ config XGENE_DMA
 	help
 	  Enable support for the APM X-Gene SoC DMA engine.
 
+config QCOM_HIDMA_MGMT
+	bool "Qualcomm Technologies HIDMA Managment support"
+	select DMA_ENGINE
+	help
+	  Enable support for the Qualcomm Technologies HIDMA Management.
+	  Each DMA device requires one management interface driver
+	  for basic initialization before QCOM_HIDMA driver can start
+	  managing the channels. In a virtualized environment, the guest
+	  OS would run QCOM_HIDMA driver and the hypervisor would run
+	  the QCOM_HIDMA_MGMT driver.
+
 config XILINX_VDMA
 	tristate "Xilinx AXI VDMA Engine"
 	depends on (ARCH_ZYNQ || MICROBLAZE)
drivers/dma/Makefile +1 -0
index 7711a71..3d25ffd 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_PL330_DMA) += pl330.o
 obj-$(CONFIG_PPC_BESTCOMM) += bestcomm/
 obj-$(CONFIG_PXA_DMA) += pxa_dma.o
 obj-$(CONFIG_QCOM_BAM_DMA) += qcom_bam_dma.o
+obj-$(CONFIG_QCOM_HIDMA_MGMT) += qcom_hidma_mgmt.o
 obj-$(CONFIG_RENESAS_DMA) += sh/
 obj-$(CONFIG_SIRF_DMA) += sirf-dma.o
 obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o
drivers/dma/qcom_hidma_mgmt.c new file +868 -0

868 lines not on this page · raw message

Signature · 7 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#1 lore raw

PATCH 2/2 dma: add Qualcomm Technologies HIDMA channel driver

This patch adds support for hidma engine. The driver consists of two logical blocks. The DMA engine interface and the low-level interface. This version of the driver does not support virtualization on this release and only memcpy interface support is included.

---
 .../devicetree/bindings/dma/qcom_hidma.txt         |   18 +
 drivers/dma/Kconfig                                |   11 +
 drivers/dma/Makefile                               |    4 +
 drivers/dma/qcom_hidma.c                           | 1717 ++++++++++++++++++++
 drivers/dma/qcom_hidma.h                           |   44 +
 drivers/dma/qcom_hidma_ll.c                        | 1132 +++++++++++++
 6 files changed, 2926 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma.txt
 create mode 100644 drivers/dma/qcom_hidma.c
 create mode 100644 drivers/dma/qcom_hidma.h
 create mode 100644 drivers/dma/qcom_hidma_ll.c
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +18 -0
new file mode 100644
index 0000000..9a01635
@@ -0,0 +1,18 @@
+Qualcomm Technologies HIDMA Channel driver
+
+Required properties:
+- compatible: must contain "qcom,hidma"
+- reg: Addresses for the transfer and event channel
+- interrupts: Should contain the event interrupt
+- desc-count: Number of asynchronous requests this channel can handle
+- event-channel: The HW event channel completions will be delivered.
+Example:
+
+	hidma_24: hidma@0x5c050000 {
+		compatible = "qcom,hidma";
+		reg = <0 0x5c050000 0x0 0x1000>,
+		      <0 0x5c0b0000 0x0 0x1000>;
+		interrupts = <0 389 0>;
+		desc-count = <10>;
+		event-channel = /bits/ 8 <4>;
+	};
drivers/dma/Kconfig +11 -0
index 76a5a5e..2645185 100644
@@ -512,6 +512,17 @@ config QCOM_HIDMA_MGMT
 	  OS would run QCOM_HIDMA driver and the hypervisor would run
 	  the QCOM_HIDMA_MGMT driver.
 
+config QCOM_HIDMA
+	tristate "Qualcomm Technologies HIDMA support"
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Enable support for the Qualcomm Technologies HIDMA controller.
+	  The HIDMA controller supports optimized buffer copies
+	  (user to kernel, kernel to kernel, etc.).  It only supports
+	  memcpy/memset interfaces. The core is not intended for general
+	  purpose slave DMA.
+
 config XILINX_VDMA
 	tristate "Xilinx AXI VDMA Engine"
 	depends on (ARCH_ZYNQ || MICROBLAZE)
drivers/dma/Makefile +4 -0
index 3d25ffd..5665df2 100644
@@ -53,6 +53,10 @@ obj-$(CONFIG_PL330_DMA) += pl330.o
 obj-$(CONFIG_PPC_BESTCOMM) += bestcomm/
 obj-$(CONFIG_PXA_DMA) += pxa_dma.o
 obj-$(CONFIG_QCOM_BAM_DMA) += qcom_bam_dma.o
+obj-$(CONFIG_QCOM_HIDMA) +=  qcom_hdma.o
+qcom_hdma-objs        := qcom_hidma_ll.o qcom_hidma.o
+
+
 obj-$(CONFIG_QCOM_HIDMA_MGMT) += qcom_hidma_mgmt.o
 obj-$(CONFIG_RENESAS_DMA) += sh/
 obj-$(CONFIG_SIRF_DMA) += sirf-dma.o
drivers/dma/qcom_hidma.c new file +1717 -0

1,717 lines not on this page · raw message

drivers/dma/qcom_hidma.h new file +44 -0

44 lines not on this page · raw message

drivers/dma/qcom_hidma_ll.c new file +1132 -0

1,132 lines not on this page · raw message

Signature · 2 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#24 lore raw

[PATCH] dma: fix platform_no_drv_owner.cocci warnings

In reply to Sinan Kaya
drivers/dma/qcom_hidma_mgmt.c:852:3-8: No need to set .owner here. The core will do it.

drivers/dma/qcom_hidma_mgmt.c:852:3-8: No need to set .owner here. The core will do it.

Remove .owner field if calls are used which set it automatically

Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci

---

 qcom_hidma_mgmt.c |    1 -
 1 file changed, 1 deletion(-)
drivers/dma/qcom_hidma_mgmt.c +0 -1
@@ -849,7 +849,6 @@ static struct platform_driver qcom_hidma
 	.remove = qcom_hidma_mgmt_remove,
 	.driver = {
 		.name = MODULE_NAME,
-		.owner = THIS_MODULE,
 		.of_match_table = of_match_ptr(qcom_hidma_mgmt_match),
 		.acpi_match_table = ACPI_PTR(qcom_hidma_mgmt_acpi_ids),
 	},

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

#25 lore raw
In reply to Sinan Kaya
url: https://github.com/0day-ci/linux/commits/Sinan-Kaya/dma-add-Qualcomm-Technologies-HIDMA-management-driver/20151030-111408

Hi Sinan,

[auto build test WARNING on lwn/docs-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url: https://github.com/0day-ci/linux/commits/Sinan-Kaya/dma-add-Qualcomm-Technologies-HIDMA-management-driver/20151030-111408

coccinelle warnings: (new ones prefixed by >>)

>> drivers/dma/qcom_hidma_mgmt.c:852:3-8: No need to set .owner here. The core will do it.

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Sinan Kaya
reproduce:

Hi Sinan,

[auto build test ERROR on lwn/docs-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/Sinan-Kaya/dma-add-Qualcomm-Technologies-HIDMA-management-driver/20151030-111408
config: i386-allmodconfig (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

ERROR: "__udivdi3" undefined!

>> ERROR: "dma_to_phys" undefined!

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Sinan Kaya
reproduce:

Hi Sinan,

[auto build test ERROR on lwn/docs-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/Sinan-Kaya/dma-add-Qualcomm-Technologies-HIDMA-management-driver/20151030-111408
config: i386-allyesconfig (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

drivers/built-in.o: In function `hidma_selftest_sg.constprop.7':

>> qcom_hidma.c:(.text+0x175be6): undefined reference to `__udivdi3'

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#26 lore raw
In reply to Sinan Kaya

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 4

Quoted 10 lines · On Thursday 29 October 2015 23:08:12 Sinan Kaya wrote:
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
new file mode 100644
index 0000000..81674ab
@@ -0,0 +1,42 @@
+Qualcomm Technologies HIDMA Management interface
+
+Required properties:
+- compatible: must contain "qcom,hidma_mgmt"

No underscores in the name please. Also try to be more specific, in case this device shows up in more than one SoC and they end up not being 100% compatible we want to be able to tell them apart.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 16

Quoted 12 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +12 -0
+- reg: Address range for DMA device
+- interrupts: Should contain the one interrupt shared by all channels
+- nr-channels: Number of channels supported by this DMA controller.
+- max-write: Maximum write burst in bytes. A memcpy requested is
+  fragmented to multiples of this amount.
+- max-read: Maximum read burst in bytes. A memcpy request is
+  fragmented to multiples of this amount.
+- max-wxactions: Maximum write transactions to perform in a burst
+- max-rdactions: Maximum read transactions to perform in a burst
+- max-memset-limit: Maximum memset limit
+- ch-priority-#n: Priority of the channel
+- ch-weight-#n: Round robin weight of the channel

For the last two, you can just use a multi-cell property, using one cell per channel.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 19

Quoted 3 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +3 -0
+
+#define MODULE_NAME			"hidma-mgmt"
+#define PREFIX				MODULE_NAME ": "

These can be removed, just use dev_info() etc for messages, to include a unique identifier.

Quoted 11 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +11 -0
+#define AUTOSUSPEND_TIMEOUT		2000
+
+#define HIDMA_RUNTIME_GET(dmadev)				\
+do {								\
+	atomic_inc(&(dmadev)->pm_counter);			\
+	TRC_PM(&(dmadev)->pdev->dev,				\
+		"%s:%d pm_runtime_get %d\n", __func__, __LINE__,\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_get_sync(&(dmadev)->pdev->dev);		\
+} while (0)
+

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 40

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+#define HIDMA_RUNTIME_SET(dmadev)				\
+do {								\
+	atomic_dec(&(dmadev)->pm_counter);			\
+	TRC_PM(&(dmadev)->pdev->dev,				\
+		"%s:%d pm_runtime_put_autosuspend:%d\n",	\
+		__func__, __LINE__,				\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_mark_last_busy(&(dmadev)->pdev->dev);	\
+	pm_runtime_put_autosuspend(&(dmadev)->pdev->dev);	\
+} while (0)

Better use inline functions.

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +5 -0
+struct qcom_hidma_mgmt_dev {
+	u8 max_wr_xactions;
+	u8 max_rd_xactions;
+	u8 max_memset_limit;
+	u16 max_write_request;

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+	u16 max_read_request;
+	u16 nr_channels;
+	u32 chreset_timeout;
+	u32 sw_version;
+	u8 *priority;
+	u8 *weight;
+
+	atomic_t	pm_counter;
+	/* Hardware device constants */
+	dma_addr_t dev_physaddr;

No need to store the physaddr, it's write-only here.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 11 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +11 -0
+
+static unsigned int debug_pm;
+module_param(debug_pm, uint, 0644);
+MODULE_PARM_DESC(debug_pm,
+		 "debug runtime power management transitions (default: 0)");
+
+#define TRC_PM(...) do {			\
+		if (debug_pm)			\
+			dev_info(__VA_ARGS__);	\
+	} while (0)
+

Once you are done debugging the driver and have a final version, please remove these.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+
+#define HIDMA_SHOW(dma, name) \
+		seq_printf(s, #name "=0x%x\n", dma->name)

Only used once, just remove.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+#define HIDMA_READ_SHOW(dma, name, offset) \
+	do { \
+		u32 val; \
+		val = readl(dma->dev_virtaddr + offset); \
+		seq_printf(s, name "=0x%x\n", val); \
+	} while (0)

Inline function.

Quoted 18 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +18 -0
+/**
+ * qcom_hidma_mgmt_info: display HIDMA device info
+ *
+ * Display the info for the current HIDMA device.
+ */
+static int qcom_hidma_mgmt_info(struct seq_file *s, void *unused)
+{
+	struct qcom_hidma_mgmt_dev *mgmtdev = s->private;
+	u32 val;
+	int i;
+
+	HIDMA_RUNTIME_GET(mgmtdev);
+	HIDMA_SHOW(mgmtdev, sw_version);
+
+	val = readl(mgmtdev->dev_virtaddr + CFG_OFFSET);
+	seq_printf(s, "ENABLE=%d\n", val & 0x1);
+
+	val = readl(mgmtdev->dev_virtaddr + CHRESET_TIMEOUUT_OFFSET);

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+	seq_printf(s, "reset_timeout=%d\n", val & CHRESET_TIMEOUUT_MASK);
+
+	val = readl(mgmtdev->dev_virtaddr + MHICFG_OFFSET);
+	seq_printf(s, "nr_event_channel=%d\n",
+		(val >> NR_EV_CHANNEL_BIT_POS) & NR_CHANNEL_MASK);
+	seq_printf(s, "nr_tr_channel=%d\n", (val & NR_CHANNEL_MASK));
+	seq_printf(s, "nr_virt_tr_channel=%d\n", mgmtdev->nr_channels);
+	seq_printf(s, "dev_virtaddr=%p\n", &mgmtdev->dev_virtaddr);
+	seq_printf(s, "dev_physaddr=%pap\n", &mgmtdev->dev_physaddr);
+	seq_printf(s, "dev_addrsize=%pap\n", &mgmtdev->dev_addrsize);

printing pointers is a security risk, just remove them if they are not essential here.

Quoted 17 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +17 -0
+
+static int qcom_hidma_mgmt_err_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, qcom_hidma_mgmt_err, inode->i_private);
+}
+
+static const struct file_operations qcom_hidma_mgmt_err_fops = {
+	.open = qcom_hidma_mgmt_err_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
+static ssize_t qcom_hidma_mgmt_mhiderr_clr(struct file *file,
+	const char __user *user_buf, size_t count, loff_t *ppos)
+{
+	struct qcom_hidma_mgmt_dev *mgmtdev = file->f_inode->i_private;

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+
+	HIDMA_RUNTIME_GET(mgmtdev);
+	writel(1, mgmtdev->dev_virtaddr + MHID_BUS_ERR_CLR_OFFSET);
+	HIDMA_RUNTIME_SET(mgmtdev);
+	return count;
+}
+
+static const struct file_operations qcom_hidma_mgmt_mhiderr_clrfops = {
+	.write = qcom_hidma_mgmt_mhiderr_clr,
+};

Is this really just a debugging interface? If anyone would do this for normal operation, it needs to be a proper API.

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
+
+static void qcom_hidma_mgmt_debug_uninit(struct qcom_hidma_mgmt_dev *mgmtdev)
+{
+	debugfs_remove(mgmtdev->evt_ena);

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+	debugfs_remove(mgmtdev->tre_errclr);
+	debugfs_remove(mgmtdev->msi_errclr);
+	debugfs_remove(mgmtdev->ode_errclr);
+	debugfs_remove(mgmtdev->ide_errclr);
+	debugfs_remove(mgmtdev->evt_errclr);
+	debugfs_remove(mgmtdev->mhid_errclr);
+	debugfs_remove(mgmtdev->err);
+	debugfs_remove(mgmtdev->info);
+	debugfs_remove(mgmtdev->debugfs);
+}

I guess debugfs_remove_recursive() would do the job as well.

Quoted 23 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +23 -0
+static int qcom_hidma_mgmt_debug_init(struct qcom_hidma_mgmt_dev *mgmtdev)
+{
+	int rc = 0;
+
+	mgmtdev->debugfs = debugfs_create_dir(dev_name(&mgmtdev->pdev->dev),
+						NULL);
+	if (!mgmtdev->debugfs) {
+		rc = -ENODEV;
+		return rc;
+	}
+
+	mgmtdev->info = debugfs_create_file("info", S_IRUGO,
+			mgmtdev->debugfs, mgmtdev, &qcom_hidma_mgmt_fops);
+	if (!mgmtdev->info) {
+		rc = -ENOMEM;
+		goto cleanup;
+	}
+
+	mgmtdev->err = debugfs_create_file("err", S_IRUGO,
+			mgmtdev->debugfs, mgmtdev,
+			&qcom_hidma_mgmt_err_fops);
+	if (!mgmtdev->err) {
+		rc = -ENOMEM;

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+		goto cleanup;
+	}
+
+	mgmtdev->mhid_errclr = debugfs_create_file("mhiderrclr", S_IWUSR,
+			mgmtdev->debugfs, mgmtdev,
+			&qcom_hidma_mgmt_mhiderr_clrfops);
+	if (!mgmtdev->mhid_errclr) {
+		rc = -ENOMEM;
+		goto cleanup;
+	}

Maybe use a loop around an array here to avoid writing the same thing 10 times?

Also, you could move the debugging code into a separate file and have a separate Kconfig symbol so users can disable this if they do not debug your driver but still want to use debugfs for other things.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 13 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +11 -0
+static irqreturn_t qcom_hidma_mgmt_irq_handler(int irq, void *arg)
+{
+	/* TODO: handle irq here */
+	return IRQ_HANDLED;
+}
 
 
+	rc = devm_request_irq(&pdev->dev, irq, qcom_hidma_mgmt_irq_handler,
+		IRQF_SHARED, "qcom-hidmamgmt", mgmtdev);
+	if (rc) {
+		dev_err(&pdev->dev, "irq registration failed: %d\n", irq);
+		goto out;
+	}

If you create a shared handler, you must check whether there was an interrupt pending, otherwise you will lose interrupts for all other devices that share the same IRQ.

Better remove the handler completely here so you don't need to check it.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +7 -0
+
+	if (device_property_read_u16(&pdev->dev, "nr-channels",
+		&mgmtdev->nr_channels)) {
+		dev_err(&pdev->dev, "number of channels missing\n");
+		rc = -EINVAL;
+		goto out;
+	}

This should be a u32 name 'dma-channels' for consistency with the generic DMA binding.

Also, try to avoid using u8 and u16 properties everywhere and just us u32 for consistency.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 11 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +11 -0
+
+	for (i = 0; i < mgmtdev->nr_channels; i++) {
+		char name[30];
+
+		sprintf(name, "ch-priority-%d", i);
+		device_property_read_u8(&pdev->dev, name,
+			&mgmtdev->priority[i]);
+
+		sprintf(name, "ch-weight-%d", i);
+		device_property_read_u8(&pdev->dev, name,
+			&mgmtdev->weight[i]);

Per comment above, just read this as an array.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+	dev_info(&pdev->dev,
+		"HI-DMA engine management driver registration complete\n");
+	platform_set_drvdata(pdev, mgmtdev);
+	HIDMA_RUNTIME_SET(mgmtdev);
+	return 0;
+out:
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_sync_suspend(&pdev->dev);
+	return rc;
+}

The rest of the probe function does not register any user interface aside from the debugging stuff. Can you explain in the changelog how you expect the driver to be used in a real system? Is there another driver coming?

Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
+
+static const struct of_device_id qcom_hidma_mgmt_match[] = {
+	{ .compatible = "qcom,hidma_mgmt", },
+	{},

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+};
+MODULE_DEVICE_TABLE(of, qcom_hidma_mgmt_match);
+
+static struct platform_driver qcom_hidma_mgmt_driver = {
+	.probe = qcom_hidma_mgmt_probe,
+	.remove = qcom_hidma_mgmt_remove,
+	.driver = {
+		.name = MODULE_NAME,
+		.owner = THIS_MODULE,
+		.of_match_table = of_match_ptr(qcom_hidma_mgmt_match),

drop the .owner field and the of_match_ptr() macro to avoid warnings here.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 11 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +11 -0
+static int __init qcom_hidma_mgmt_init(void)
+{
+	return platform_driver_register(&qcom_hidma_mgmt_driver);
+}
+device_initcall(qcom_hidma_mgmt_init);
+
+static void __exit qcom_hidma_mgmt_exit(void)
+{
+	platform_driver_unregister(&qcom_hidma_mgmt_driver);
+}
+module_exit(qcom_hidma_mgmt_exit);

module_platform_driver()

Arnd

#4 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Sinan Kaya
Quoted 5 lines · On Thursday 29 October 2015 23:08:13 Sinan Kaya wrote:

This patch adds support for hidma engine. The driver consists of two logical blocks. The DMA engine interface and the low-level interface. This version of the driver does not support virtualization on this release and only memcpy interface support is included.

Does that mean you can have slave device support eventually?

If so, please put that into the binding document already.

Quoted 20 lines
---
 .../devicetree/bindings/dma/qcom_hidma.txt         |   18 +
 drivers/dma/Kconfig                                |   11 +
 drivers/dma/Makefile                               |    4 +
 drivers/dma/qcom_hidma.c                           | 1717 ++++++++++++++++++++
 drivers/dma/qcom_hidma.h                           |   44 +
 drivers/dma/qcom_hidma_ll.c                        | 1132 +++++++++++++
 6 files changed, 2926 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma.txt
 create mode 100644 drivers/dma/qcom_hidma.c
 create mode 100644 drivers/dma/qcom_hidma.h
 create mode 100644 drivers/dma/qcom_hidma_ll.c
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +0 -0
new file mode 100644
index 0000000..9a01635

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +4 -0
@@ -0,0 +1,18 @@
+Qualcomm Technologies HIDMA Channel driver
+
+Required properties:
+- compatible: must contain "qcom,hidma"

Be more specific here. Also, should this be 'hisilicon,hidma-1.0' rather than 'qcom'? I'm guessing from the name that this is a device you licensed from them.

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 11

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +7 -0
+- reg: Addresses for the transfer and event channel
+- interrupts: Should contain the event interrupt
+- desc-count: Number of asynchronous requests this channel can handle
+- event-channel: The HW event channel completions will be delivered.
+Example:
+
+	hidma_24: hidma@0x5c050000 {

Name should be 'dma-controller' in DT, not 'hidma'.

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 18

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +7 -0
+		compatible = "qcom,hidma";
+		reg = <0 0x5c050000 0x0 0x1000>,
+		      <0 0x5c0b0000 0x0 0x1000>;
+		interrupts = <0 389 0>;
+		desc-count = <10>;
+		event-channel = /bits/ 8 <4>;
+	};

Remove the /bits/.

Quoted 27 lines
drivers/dma/Kconfig +11 -0
index 76a5a5e..2645185 100644
@@ -512,6 +512,17 @@ config QCOM_HIDMA_MGMT
 	  OS would run QCOM_HIDMA driver and the hypervisor would run
 	  the QCOM_HIDMA_MGMT driver.
 
+config QCOM_HIDMA
+	tristate "Qualcomm Technologies HIDMA support"
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Enable support for the Qualcomm Technologies HIDMA controller.
+	  The HIDMA controller supports optimized buffer copies
+	  (user to kernel, kernel to kernel, etc.).  It only supports
+	  memcpy/memset interfaces. The core is not intended for general
+	  purpose slave DMA.
+
 config XILINX_VDMA
 	tristate "Xilinx AXI VDMA Engine"
 	depends on (ARCH_ZYNQ || MICROBLAZE)
drivers/dma/Makefile +0 -0
index 3d25ffd..5665df2 100644

drivers/dma/Makefile obj-$(CONFIG_PL330_DMA) += pl330.o · line 58

Quoted 6 lines
drivers/dma/Makefile +3 -0
@@ -53,6 +53,10 @@ obj-$(CONFIG_PL330_DMA) += pl330.o
 obj-$(CONFIG_PPC_BESTCOMM) += bestcomm/
 obj-$(CONFIG_PXA_DMA) += pxa_dma.o
 obj-$(CONFIG_QCOM_BAM_DMA) += qcom_bam_dma.o
+obj-$(CONFIG_QCOM_HIDMA) +=  qcom_hdma.o
+qcom_hdma-objs        := qcom_hidma_ll.o qcom_hidma.o
+

The driver is linked into a single module, so all the EXPORT_SYMBOL statements can be dropped.

drivers/dma/Makefile obj-$(CONFIG_PL330_DMA) += pl330.o

Quoted 8 lines
drivers/dma/Makefile +8 -0
+/* Default idle time is 2 seconds. This parameter can
+ * be overridden by changing the following
+ * /sys/bus/platform/devices/QCOM8061:<xy>/power/autosuspend_delay_ms
+ * during kernel boot.
+ */
+#define AUTOSUSPEND_TIMEOUT		2000
+#define HIDMA_DEFAULT_DESCRIPTOR_COUNT	16
+#define MODULE_NAME			"hidma"

MODULE_NAME and HIDMA_DEFAULT_DESCRIPTOR_COUNT can be dropped

Quoted 9 lines
drivers/dma/Makefile +9 -0
+#define HIDMA_RUNTIME_GET(dmadev)				\
+do {								\
+	atomic_inc(&(dmadev)->pm_counter);			\
+	TRC_PM((dmadev)->ddev.dev,				\
+		"%s:%d pm_runtime_get %d\n", __func__, __LINE__,\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_get_sync((dmadev)->ddev.dev);		\
+} while (0)
+

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+#define HIDMA_RUNTIME_SET(dmadev)				\
+do {								\
+	atomic_dec(&(dmadev)->pm_counter);			\
+	TRC_PM((dmadev)->ddev.dev,				\
+		"%s:%d pm_runtime_put_autosuspend:%d\n",	\
+		__func__, __LINE__,				\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_mark_last_busy((dmadev)->ddev.dev);		\
+	pm_runtime_put_autosuspend((dmadev)->ddev.dev);		\
+} while (0)

Inline functions.

drivers/dma/Makefile

Quoted 4 lines
drivers/dma/Makefile +4 -0
+struct hidma_test_sync {
+	atomic_t			counter;
+	wait_queue_head_t		wq;
+};

Let me guess, you converted this from a semaphore? ;-)

Just put the two members into the containing structure and relete it here.

Quoted 6 lines
drivers/dma/Makefile +6 -0
+struct hidma_dev {
+	u8				evridx;
+	u32				nr_descriptors;
+
+	void				*lldev;
+	void				__iomem *dev_trca;

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+	void				__iomem *dev_evca;
+	int (*self_test)(struct hidma_dev *device);
+	struct dentry			*debugfs;
+	struct dentry			*stats;
+
+	/* used to protect the pending channel list*/
+	spinlock_t			lock;
+	dma_addr_t			dev_trca_phys;
+	struct dma_device		ddev;
+	struct tasklet_struct		tasklet;

workqueue maybe?

drivers/dma/Makefile

Quoted 3 lines
drivers/dma/Makefile +3 -0
+	resource_size_t			dev_trca_size;
+	dma_addr_t			dev_evca_phys;
+	resource_size_t			dev_evca_size;

All three look unused and can be removed.

drivers/dma/Makefile

Quoted 9 lines
drivers/dma/Makefile +9 -0
+static unsigned int debug_pm;
+module_param(debug_pm, uint, 0644);
+MODULE_PARM_DESC(debug_pm,
+		 "debug runtime power management transitions (default: 0)");
+
+#define TRC_PM(...) do {			\
+		if (debug_pm)			\
+			dev_info(__VA_ARGS__);	\
+	} while (0)

Again, remove these after you are done debugging the problem at hand, we don't need to clutter up the upstream version.

Quoted 4 lines
drivers/dma/Makefile +4 -0
+	/*
+	 * It is assumed that the hardware can move the data within 1s
+	 * and signal the OS of the completion
+	 */

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+	ret = wait_event_interruptible_timeout(dmadev->test_result.wq,
+		atomic_read(&dmadev->test_result.counter) == (map_count),
+				msecs_to_jiffies(10000));
+
+	if (ret <= 0) {
+		dev_err(dmadev->ddev.dev,
+			"Self-test sg copy timed out, disabling\n");
+		err = -ENODEV;
+		goto tx_status;
+	}

Why ENODEV? Could you make this handle restarted system calls?

drivers/dma/Makefile

Quoted 8 lines
drivers/dma/Makefile +8 -0
+
+/*
+ * Perform a streaming transaction to verify the HW works.
+ */
+static int hidma_selftest_streaming(struct hidma_dev *dmadev,
+			struct dma_chan *dma_chanptr, u64 size,
+			unsigned long flags)
+{

You have a lot of selftest code here. Can you try to move that into a file that works for all DMA engines? It feels like this should not be part of a driver.

drivers/dma/Makefile

Quoted 5 lines
drivers/dma/Makefile +5 -0
+
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+
+#define SIER_CHAN_SHOW(chan, name) \
+		seq_printf(s, #name "=%u\n", chan->name)

can be open-coded for clarity.

Quoted 6 lines
drivers/dma/Makefile +6 -0
+       ret = dma_mapping_error(dev, dma_src);
+       if (ret) {
+               dev_err(dev, "dma_mapping_error with ret:%d\n", ret);
+               ret = -ENOMEM;
+       } else {
+               phys_addr_t phys;

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+
+               phys = dma_to_phys(dev, dma_src);
+               if (strcmp(__va(phys), "hello world") != 0) {
+                       dev_err(dev, "memory content mismatch\n");
+                       ret = -EINVAL;
+               } else {
+                       dev_dbg(dev, "mapsingle:dma_map_single works\n");
+               }
+               dma_unmap_single(dev, dma_src, buf_size, DMA_TO_DEVICE);
+       }

dma_to_phys() is architecture specific and does not work if you have an IOMMU. Just use the virtual address you passed into dma_map_*.

Quoted 7 lines
drivers/dma/Makefile +7 -0
+/**
+ * hidma_dma_info: display HIDMA device info
+ *
+ * Display the info for the current HIDMA device.
+ */
+static int hidma_dma_info(struct seq_file *s, void *unused)
+{

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+	struct hidma_dev *dmadev = s->private;
+	struct dma_device *dma = &dmadev->ddev;
+
+	seq_printf(s, "nr_descriptors=%d\n", dmadev->nr_descriptors);
+	seq_printf(s, "dev_trca=%p\n", &dmadev->dev_trca);
+	seq_printf(s, "dev_trca_phys=%pa\n", &dmadev->dev_trca_phys);
+	seq_printf(s, "dev_trca_size=%pa\n", &dmadev->dev_trca_size);
+	seq_printf(s, "dev_evca=%p\n", &dmadev->dev_evca);
+	seq_printf(s, "dev_evca_phys=%pa\n", &dmadev->dev_evca_phys);
+	seq_printf(s, "dev_evca_size=%pa\n", &dmadev->dev_evca_size);

Don't print pointers here.

Quoted 8 lines
drivers/dma/Makefile +8 -0
+	seq_printf(s, "self_test=%u\n",
+		atomic_read(&dmadev->test_result.counter));
+
+	seq_printf(s, "copy%s%s%s%s%s%s%s%s%s%s%s\n",
+		dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
+		dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
+		dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
+		dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+		dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "",
+		dma_has_cap(DMA_SG, dma->cap_mask) ? " sg" : "",
+		dma_has_cap(DMA_ASYNC_TX, dma->cap_mask) ? " async" : "",
+		dma_has_cap(DMA_SLAVE, dma->cap_mask) ? " slave" : "",
+		dma_has_cap(DMA_CYCLIC, dma->cap_mask) ? " cyclic" : "",
+		dma_has_cap(DMA_INTERLEAVE, dma->cap_mask) ? " intl" : "",
+		dma_has_cap(DMA_MEMCPY, dma->cap_mask) ? " memcpy" : "");
+
+	return 0;
+}

The selftest part and the features could just be separate files in the core dmaengine code, it doesn't really belong here.

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+}
+#else
+static void hidma_debug_uninit(struct hidma_dev *dmadev)
+{
+}
+static int hidma_debug_init(struct hidma_dev *dmadev)
+{
+	return 0;
+}
+#endif

You can remove the #ifdef here. The debugfs code already stubs out all debugfs_create_*() and turns it all into nops when it is disabled.

drivers/dma/Makefile

Quoted 7 lines
drivers/dma/Makefile +7 -0
+	dma_cap_set(DMA_MEMCPY, dmadev->ddev.cap_mask);
+	/* Apply default dma_mask if needed */
+	if (!pdev->dev.dma_mask) {
+		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
+		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
+	}
+

remove the check, or use

	if (WARN_ON(!pdev->dev.dma_mask))
		return -ENXIO;

The dma mask has to always be set by the platform code before probe() is called. If it is not set, you are not allowed to perform DMA.

Quoted 7 lines
drivers/dma/Makefile +6 -0
+	dmadev->dev_evca_phys = evca_resource->start;
+	dmadev->dev_evca_size = resource_size(evca_resource);
+
+	dev_dbg(&pdev->dev, "dev_evca_phys:%pa\n", &dmadev->dev_evca_phys);
+	dev_dbg(&pdev->dev, "dev_evca_size:%pa\n", &dmadev->dev_evca_size);
+
 

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +7 -0
+	dev_dbg(&pdev->dev, "qcom_hidma: mapped EVCA %pa to %p\n",
+		&dmadev->dev_evca_phys, dmadev->dev_evca);
 
 
 
+	dmadev->dev_trca_phys = trca_resource->start;
+	dmadev->dev_trca_size = resource_size(trca_resource);
+
+	dev_dbg(&pdev->dev, "dev_trca_phys:%pa\n", &dmadev->dev_trca_phys);
+	dev_dbg(&pdev->dev, "dev_trca_size:%pa\n", &dmadev->dev_trca_size);

Don't print pointers.

Quoted 32 lines
drivers/dma/Makefile +32 -0
+	rc = devm_request_irq(&pdev->dev, chirq, hidma_chirq_handler, 0,
+			      "qcom-hidma", &dmadev->lldev);
+	if (rc) {
+		dev_err(&pdev->dev, "chirq registration failed: %d\n", chirq);
+		goto chirq_request_failed;
+	}
+
+	dev_dbg(&pdev->dev, "initializing DMA channels\n");
+	INIT_LIST_HEAD(&dmadev->ddev.channels);
+	rc = hidma_chan_init(dmadev, 0);
+	if (rc) {
+		dev_err(&pdev->dev, "probe:channel init failed\n");
+		goto channel_init_failed;
+	}
+	dev_dbg(&pdev->dev, "HI-DMA engine driver starting self test\n");
+	rc = dmadev->self_test(dmadev);
+	if (rc) {
+		dev_err(&pdev->dev, "probe: self test failed: %d\n", rc);
+		goto self_test_failed;
+	}
+	dev_info(&pdev->dev, "probe: self test succeeded.\n");
+
+	dev_dbg(&pdev->dev, "calling dma_async_device_register\n");
+	rc = dma_async_device_register(&dmadev->ddev);
+	if (rc) {
+		dev_err(&pdev->dev,
+			"probe: failed to register slave DMA: %d\n", rc);
+		goto device_register_failed;
+	}
+	dev_dbg(&pdev->dev, "probe: dma_async_device_register done\n");
+
+	rc = hidma_debug_init(dmadev);

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+	if (rc) {
+		dev_err(&pdev->dev,
+			"probe: failed to init debugfs: %d\n", rc);
+		goto debug_init_failed;
+	}
+
+	dev_info(&pdev->dev, "HI-DMA engine driver registration complete\n");
+	platform_set_drvdata(pdev, dmadev);
+	HIDMA_RUNTIME_SET(dmadev);
+	return 0;

Remove the debug prints when you are done debugging.

drivers/dma/Makefile

Quoted 12 lines
drivers/dma/Makefile +12 -0
+debug_init_failed:
+device_register_failed:
+self_test_failed:
+channel_init_failed:
+chirq_request_failed:
+	hidma_ll_uninit(dmadev->lldev);
+ll_init_failed:
+evridx_failed:
+remap_trca_failed:
+remap_evca_failed:
+	if (dmadev)
+		hidma_free(dmadev);

Rename the labels according to what you do at in the failure case and remove most of them. This is 'goto', not 'comefrom' ;-)

drivers/dma/Makefile

Quoted 8 lines
drivers/dma/Makefile +8 -0
+static struct platform_driver hidma_driver = {
+	.probe = hidma_probe,
+	.remove = hidma_remove,
+	.driver = {
+		.name = MODULE_NAME,
+		.owner = THIS_MODULE,
+		.of_match_table = of_match_ptr(hidma_match),
+		.acpi_match_table = ACPI_PTR(hidma_acpi_ids),

Remove .owner and of_match_ptr().

Quoted 4 lines
drivers/dma/Makefile +4 -0
+	},
+};
+
+static int __init hidma_init(void)

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+{
+	return platform_driver_register(&hidma_driver);
+}
+late_initcall(hidma_init);
+
+static void __exit hidma_exit(void)
+{
+	platform_driver_unregister(&hidma_driver);
+}
+module_exit(hidma_exit);

module_platform_driver()

drivers/dma/Makefile

Quoted 12 lines
drivers/dma/Makefile +12 -0
+
+	if (unlikely(tre_ch >= lldev->nr_tres)) {
+		dev_err(lldev->dev, "invalid TRE number in free:%d", tre_ch);
+		return;
+	}
+
+	tre = &lldev->trepool[tre_ch];
+	if (unlikely(atomic_read(&tre->allocated) != true)) {
+		dev_err(lldev->dev, "trying to free an unused TRE:%d",
+			tre_ch);
+		return;
+	}

Remove the 'unlikely' and the redundant '!= true'.

Only use 'likely' or 'unlikely' if you can measure a difference.

Quoted 37 lines
drivers/dma/Makefile +37 -0
+static int hidma_ll_reset(struct hidma_lldev *lldev)
+{
+	u32 val;
+	int count;
+
+	val = readl_relaxed(lldev->trca + TRCA_CTRLSTS_OFFSET);
+	val = val & ~(CH_CONTROL_MASK << 16);
+	val = val | (CH_RESET << 16);
+	writel_relaxed(val, lldev->trca + TRCA_CTRLSTS_OFFSET);
+
+	/* wait until the reset is performed */
+	wmb();
+
+	/* Delay 10ms after reset to allow DMA logic to quiesce.*/
+	for (count = 0; count < 10; count++) {
+		val = readl_relaxed(lldev->trca + TRCA_CTRLSTS_OFFSET);
+		lldev->trch_state = (val >> CH_STATE_BIT_POS)
+					& CH_STATE_MASK;
+		if (lldev->trch_state == CH_DISABLED)
+			break;
+		mdelay(1);
+	}
+	val = readl_relaxed(lldev->trca + TRCA_CTRLSTS_OFFSET);
+	lldev->trch_state = (val >> CH_STATE_BIT_POS) & CH_STATE_MASK;
+	if (lldev->trch_state != CH_DISABLED) {
+		dev_err(lldev->dev,
+			"transfer channel did not reset\n");
+		return -ENODEV;
+	}
+
+	val = readl_relaxed(lldev->evca + EVCA_CTRLSTS_OFFSET);
+	val = val & ~(CH_CONTROL_MASK << 16);
+	val = val | (CH_RESET << 16);
+	writel_relaxed(val, lldev->evca + EVCA_CTRLSTS_OFFSET);
+
+	/* wait until the reset is performed */
+	wmb();

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+
+	/* Delay 10ms after reset to allow DMA logic to quiesce.*/
+	for (count = 0; count < 10; count++) {
+		val = readl_relaxed(lldev->evca + EVCA_CTRLSTS_OFFSET);
+		lldev->evch_state = (val >> CH_STATE_BIT_POS)
+					& CH_STATE_MASK;
+		if (lldev->evch_state == CH_DISABLED)
+			break;
+		mdelay(1);
+	}

Try using a workqueue to get into a state where you can call msleep() instead of mdelay().

Also, if you waste CPU cycles for hundreds of milliseconds, it's unlikely that the function is so performance critical that it requires writel_relaxed().

Just use writel() here.

Quoted 16 lines
drivers/dma/Makefile +16 -0
+/*
+ * The interrupt handler for HIDMA will try to consume as many pending
+ * EVRE from the event queue as possible. Each EVRE has an associated
+ * TRE that holds the user interface parameters. EVRE reports the
+ * result of the transaction. Hardware guarantees ordering between EVREs
+ * and TREs. We use last processed offset to figure out which TRE is
+ * associated with which EVRE. If two TREs are consumed by HW, the EVREs
+ * are in order in the event ring.
+ * This handler will do a one pass for consuming EVREs. Other EVREs may
+ * be delivered while we are working. It will try to consume incoming
+ * EVREs one more time and return.
+ * For unprocessed EVREs, hardware will trigger another interrupt until
+ * all the interrupt bits are cleared.
+ */
+static void hidma_ll_int_handler_internal(struct hidma_lldev *lldev)
+{

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+	u32 status;
+	u32 enable;
+	u32 cause;
+	int repeat = 2;
+	unsigned long timeout;
+
+	status = readl_relaxed(lldev->evca + EVCA_IRQ_STAT_OFFSET);
+	enable = readl_relaxed(lldev->evca + EVCA_IRQ_EN_OFFSET);
+	cause = status & enable;
+

Reading the status probably requires a readl() rather than readl_relaxed() to guarantee that the DMA data has arrived in memory by the time that the register data is seen by the CPU. If using readl_relaxed() here is a valid and required optimization, please add a comment to explain why it works and how much you gain.

drivers/dma/Makefile

Quoted 9 lines
drivers/dma/Makefile +9 -0
+		/* Another interrupt might have arrived while we are
+		 * processing this one. Read the new cause.
+		 */
+		status = readl_relaxed(lldev->evca + EVCA_IRQ_STAT_OFFSET);
+		enable = readl_relaxed(lldev->evca + EVCA_IRQ_EN_OFFSET);
+		cause = status & enable;
+
+		repeat--;
+	}

Same here.

Quoted 26 lines
drivers/dma/Makefile +26 -0
+}
+
+
+static int hidma_ll_enable(struct hidma_lldev *lldev)
+{
+	u32 val;
+
+	val = readl_relaxed(lldev->evca + EVCA_CTRLSTS_OFFSET);
+	val &= ~(CH_CONTROL_MASK << 16);
+	val |= (CH_ENABLE << 16);
+
+	writel_relaxed(val, lldev->evca + EVCA_CTRLSTS_OFFSET);
+
+	/* wait until channel is enabled */
+	wmb();
+
+	mdelay(1);
+
+	val = readl_relaxed(lldev->evca + EVCA_CTRLSTS_OFFSET);
+	lldev->evch_state = (val >> CH_STATE_BIT_POS) & CH_STATE_MASK;
+	if ((lldev->evch_state != CH_ENABLED) &&
+		(lldev->evch_state != CH_RUNNING)) {
+		dev_err(lldev->dev,
+			"event channel did not get enabled\n");
+		return -ENODEV;
+	}

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+
+	val = readl_relaxed(lldev->trca + TRCA_CTRLSTS_OFFSET);
+	val = val & ~(CH_CONTROL_MASK << 16);
+	val = val | (CH_ENABLE << 16);
+	writel_relaxed(val, lldev->trca + TRCA_CTRLSTS_OFFSET);
+
+	/* wait until channel is enabled */
+	wmb();
+
+	mdelay(1);

Another workqueue? You should basically never call mdelay().

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+static int hidma_ll_hw_start(void *llhndl)
+{
+	int rc = 0;
+	struct hidma_lldev *lldev = llhndl;
+	unsigned long irqflags;
+
+	spin_lock_irqsave(&lldev->lock, irqflags);
+	writel_relaxed(lldev->tre_write_offset,
+			lldev->trca + TRCA_DOORBELL_OFFSET);
+	spin_unlock_irqrestore(&lldev->lock, irqflags);

How does this work? The writel_relaxed() won't synchronize with either the DMA data or the spinlock.

drivers/dma/Makefile

Quoted 3 lines
drivers/dma/Makefile +3 -0
+int hidma_ll_init(void **lldevp, struct device *dev, u32 nr_tres,
+			void __iomem *trca, void __iomem *evca,
+			u8 evridx)

How about returning the pointer rather than passing in an indirect pointer?

Also, your abstraction seem to go a little too far if the upper driver doesn't know what the lower driver calls its main device structure.

Or you can go further and just embed the struct hidma_lldev within the struct hidma_dev to save one?

Quoted 32 lines
drivers/dma/Makefile +32 -0
+void hidma_ll_chstats(struct seq_file *s, void *llhndl, u32 tre_ch)
+{
+	struct hidma_lldev *lldev = llhndl;
+	struct hidma_tre *tre;
+	u32 length;
+	dma_addr_t src_start;
+	dma_addr_t dest_start;
+	u32 *tre_local;
+
+	if (unlikely(tre_ch >= lldev->nr_tres)) {
+		dev_err(lldev->dev, "invalid TRE number in chstats:%d",
+			tre_ch);
+		return;
+	}
+	tre = &lldev->trepool[tre_ch];
+	seq_printf(s, "------Channel %d -----\n", tre_ch);
+	seq_printf(s, "allocated=%d\n", atomic_read(&tre->allocated));
+	HIDMA_CHAN_SHOW(tre, queued);
+	seq_printf(s, "err_info=0x%x\n",
+		   lldev->tx_status_list[tre->chidx].err_info);
+	seq_printf(s, "err_code=0x%x\n",
+		   lldev->tx_status_list[tre->chidx].err_code);
+	HIDMA_CHAN_SHOW(tre, status);
+	HIDMA_CHAN_SHOW(tre, chidx);
+	HIDMA_CHAN_SHOW(tre, dma_sig);
+	seq_printf(s, "dev_name=%s\n", tre->dev_name);
+	seq_printf(s, "callback=%p\n", tre->callback);
+	seq_printf(s, "data=%p\n", tre->data);
+	HIDMA_CHAN_SHOW(tre, tre_index);
+
+	tre_local = &tre->tre_local[0];
+	src_start = tre_local[TRE_SRC_LOW_IDX];

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+	src_start = ((u64)(tre_local[TRE_SRC_HI_IDX]) << 32) + src_start;
+	dest_start = tre_local[TRE_DEST_LOW_IDX];
+	dest_start += ((u64)(tre_local[TRE_DEST_HI_IDX]) << 32);
+	length = tre_local[TRE_LEN_IDX];
+
+	seq_printf(s, "src=%pap\n", &src_start);
+	seq_printf(s, "dest=%pap\n", &dest_start);
+	seq_printf(s, "length=0x%x\n", length);
+}
+EXPORT_SYMBOL_GPL(hidma_ll_chstats);

Remove all the pointers here. I guess you can remove the entire debugfs file really ;-)

This looks like it is better done using ftrace for the low-level internals of the driver.

Arnd

#22 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Sinan Kaya
Quoted 33 lines · Sinan Kaya

This patch adds support for hidma engine. The driver consists of two logical blocks. The DMA engine interface and the low-level interface. This version of the driver does not support virtualization on this release and only memcpy interface support is included.

---
 .../devicetree/bindings/dma/qcom_hidma.txt         |   18 +
 drivers/dma/Kconfig                                |   11 +
 drivers/dma/Makefile                               |    4 +
 drivers/dma/qcom_hidma.c                           | 1717 ++++++++++++++++++++
 drivers/dma/qcom_hidma.h                           |   44 +
 drivers/dma/qcom_hidma_ll.c                        | 1132 +++++++++++++
 6 files changed, 2926 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma.txt
 create mode 100644 drivers/dma/qcom_hidma.c
 create mode 100644 drivers/dma/qcom_hidma.h
 create mode 100644 drivers/dma/qcom_hidma_ll.c
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +7 -0
new file mode 100644
index 0000000..9a01635
@@ -0,0 +1,18 @@
+Qualcomm Technologies HIDMA Channel driver
+
+Required properties:
+- compatible: must contain "qcom,hidma"
+- reg: Addresses for the transfer and event channel
+- interrupts: Should contain the event interrupt
+- desc-count: Number of asynchronous requests this channel can handle

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +10 -0
+- event-channel: The HW event channel completions will be delivered.
+Example:
+
+	hidma_24: hidma@0x5c050000 {
+		compatible = "qcom,hidma";
+		reg = <0 0x5c050000 0x0 0x1000>,
+		      <0 0x5c0b0000 0x0 0x1000>;
+		interrupts = <0 389 0>;
+		desc-count = <10>;
+		event-channel = /bits/ 8 <4>;

The documentation above didn't state this was an 8-bit quantity, and you save nothing by doing this (all values in the binary format are padded to 4-byte alignment).

Have this as a cell, and use of_property_read_u32. That means you may need a temporary u32, but it's far less surprising and makes things far easier for dts authors to get right.

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#35 lore raw
In reply to Sinan Kaya
Quoted 23 lines · Sinan Kaya

The Qualcomm Technologies HIDMA device has been designed to support virtualization technology. The driver has been divided into two to follow the hardware design. The management driver is executed in hypervisor context and is the main managment for all channels provided by the device. The channel driver is exected in the guest OS context.

---
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  42 +
 drivers/dma/Kconfig                                |  11 +
 drivers/dma/Makefile                               |   1 +
 drivers/dma/qcom_hidma_mgmt.c                      | 868 +++++++++++++++++++++
 4 files changed, 922 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt
 create mode 100644 drivers/dma/qcom_hidma_mgmt.c
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +0 -0
new file mode 100644
index 0000000..81674ab

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
@@ -0,0 +1,42 @@
+Qualcomm Technologies HIDMA Management interface
+
+Required properties:
+- compatible: must contain "qcom,hidma_mgmt"

s/_/-/ in property names and compatible strings.

Per your rationale for splitting the device nodes, surely the relationship between the two needs to be described?

The GIC has a similar split, yet we use a single node, with the hypervisor portions being optional.

What if there were multiple instances?

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 11

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +7 -0
+- reg: Address range for DMA device
+- interrupts: Should contain the one interrupt shared by all channels
+- nr-channels: Number of channels supported by this DMA controller.
+- max-write: Maximum write burst in bytes. A memcpy requested is
+  fragmented to multiples of this amount.
+- max-read: Maximum read burst in bytes. A memcpy request is
+  fragmented to multiples of this amount.

Thse would be better named as max-read-burst-bytes and min-read-burst-bytes.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 13

Quoted 2 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +2 -0
+- max-wxactions: Maximum write transactions to perform in a burst
+- max-rdactions: Maximum read transactions to perform in a burst

max-{write,read}-transactions

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 14

Quoted 1 line
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +1 -0
+- max-memset-limit: Maximum memset limit

I have no idea what this is meant to mean.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 16

Quoted 2 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +2 -0
+- ch-priority-#n: Priority of the channel
+- ch-weight-#n: Round robin weight of the channel

These need better descriptions. They sound like configuration options.

[...]

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 22

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_hidma_mgmt_acpi_ids[] = {
+	{"QCOM8060"},
+	{},
+};
+#endif

How do DMA engines work with ACPI?

How are client relationships defined?

THanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#36 lore raw
Quoted 18 lines · Mark Rutland
Quoted 8 lines · Sinan Kaya

The Qualcomm Technologies HIDMA device has been designed to support virtualization technology. The driver has been divided into two to follow the hardware design. The management driver is executed in hypervisor context and is the main managment for all channels provided by the device. The channel driver is exected in the guest OS context.

drivers/dma/qcom_hidma_mgmt.c line 839

Quoted 6 lines
drivers/dma/qcom_hidma_mgmt.c new file +6 -0
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_hidma_mgmt_acpi_ids[] = {
+     {"QCOM8060"},
+     {},
+};
+#endif

How do DMA engines work with ACPI?

Quoted 1 line

How are client relationships defined?

The ACPI tables DSDT and CSRT (more info here:
http://www.acpi.info/links.htm) defines properties.

DSDT:
per DMAC: the resources
per client: FixedDMA descriptor that contains channel / request line pair.

CSRT:
necessary table to map which DMAC provides which request line, thus
request line numbering are global on platform.

When DMAC driver is probed in the running system it should call as well registration function from acpi-dma.c.

All clients when use new DMA slave API gets channel automatically based on their FixedDMA property.

So, above is how it should be done. Didn't actually checked what this driver does.

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#37 lore raw
Quoted 32 lines · Andy Shevchenko
Quoted 18 lines · Mark Rutland
Quoted 8 lines · Sinan Kaya

The Qualcomm Technologies HIDMA device has been designed to support virtualization technology. The driver has been divided into two to follow the hardware design. The management driver is executed in hypervisor context and is the main managment for all channels provided by the device. The channel driver is exected in the guest OS context.

drivers/dma/qcom_hidma_mgmt.c line 839

Quoted 6 lines
drivers/dma/qcom_hidma_mgmt.c new file +6 -0
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_hidma_mgmt_acpi_ids[] = {
+     {"QCOM8060"},
+     {},
+};
+#endif

How do DMA engines work with ACPI?

Quoted 1 line

How are client relationships defined?

The ACPI tables DSDT and CSRT (more info here:
http://www.acpi.info/links.htm) defines properties.

DSDT:
per DMAC: the resources
per client: FixedDMA descriptor that contains channel / request line pair.

CSRT:
necessary table to map which DMAC provides which request line, thus
request line numbering are global on platform.

Quoted 9 lines

When DMAC driver is probed in the running system it should call as well registration function from acpi-dma.c.

All clients when use new DMA slave API gets channel automatically based on their FixedDMA property.

So, above is how it should be done. Didn't actually checked what this driver does.

I was going to reply to all the questions in one pass but let me handle piece by piece.

Here are some facts.
- This hardware supports memcpy and memset only.
- Memset feature was removed from the kernel sometime around 3.14. So no memset support in this driver either.
- The hardware does not support DMA slave support
- The goal is to provide an interface to DMA engine framework for memcpy optimization so that the rest of the kernel drivers and applications make use of the hardware.

CSRT is an Intel specific ACPI table for slave devices. It was decided by Linaro that CSRT will not be supported for ARM64.

There were some discussions in ACPI forums to define a similar table for ARM64 but we are not there today and this hardware does not support slave interface.

ACPI enumeration is just like any other platform device. The driver gets looked up by a QCOM specific HID and the driver gets probed with the rest of the arguments in DSM object similar to device-tree attributes. The code uses device functions so the driver is not aware of where the parameters are coming from.

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#38 lore raw
Quoted 44 lines · Sinan Kaya
Quoted 32 lines · Andy Shevchenko
Quoted 18 lines · Mark Rutland
Quoted 8 lines · Sinan Kaya

The Qualcomm Technologies HIDMA device has been designed to support virtualization technology. The driver has been divided into two to follow the hardware design. The management driver is executed in hypervisor context and is the main managment for all channels provided by the device. The channel driver is exected in the guest OS context.

drivers/dma/qcom_hidma_mgmt.c line 839

Quoted 6 lines
drivers/dma/qcom_hidma_mgmt.c new file +6 -0
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_hidma_mgmt_acpi_ids[] = {
+     {"QCOM8060"},
+     {},
+};
+#endif

How do DMA engines work with ACPI?

Quoted 1 line

How are client relationships defined?

The ACPI tables DSDT and CSRT (more info here:
http://www.acpi.info/links.htm) defines properties.

DSDT:
per DMAC: the resources
per client: FixedDMA descriptor that contains channel / request line pair.

CSRT:
necessary table to map which DMAC provides which request line, thus
request line numbering are global on platform.

Quoted 9 lines

When DMAC driver is probed in the running system it should call as well registration function from acpi-dma.c.

All clients when use new DMA slave API gets channel automatically based on their FixedDMA property.

So, above is how it should be done. Didn't actually checked what this driver does.

Quoted 8 lines

I was going to reply to all the questions in one pass but let me handle piece by piece.

Here are some facts.
- This hardware supports memcpy and memset only.
- Memset feature was removed from the kernel sometime around 3.14. So no memset support in this driver either.
- The hardware does not support DMA slave support

This point is what I'd missed when reviewing. Apologies for that.

Quoted 10 lines

- The goal is to provide an interface to DMA engine framework for memcpy optimization so that the rest of the kernel drivers and applications make use of the hardware.

CSRT is an Intel specific ACPI table for slave devices. It was decided by Linaro that CSRT will not be supported for ARM64.

There were some discussions in ACPI forums to define a similar table for ARM64 but we are not there today and this hardware does not support slave interface.

Ok. Thanks for the info!

Quoted 5 lines

ACPI enumeration is just like any other platform device. The driver gets looked up by a QCOM specific HID and the driver gets probed with the rest of the arguments in DSM object similar to device-tree attributes. The code uses device functions so the driver is not aware of where the parameters are coming from.

Ok.

So far the properties look device-internal, so I'm ok with thoses properties being uniform and parsed in the manner that they are, though I'm worried about the way the device description is split over two nodes.

Thanks,
Mark.

#39 lore raw
In reply to Sinan Kaya
Quoted 34 lines · Sinan Kaya
Quoted 12 lines

The ACPI tables DSDT and CSRT (more info here:
http://www.acpi.info/links.htm) defines properties.

DSDT:
per DMAC: the resources
per client: FixedDMA descriptor that contains channel / request line
pair.

CSRT:
necessary table to map which DMAC provides which request line, thus
request line numbering are global on platform.

Quoted 9 lines

When DMAC driver is probed in the running system it should call as well registration function from acpi-dma.c.

All clients when use new DMA slave API gets channel automatically based on their FixedDMA property.

So, above is how it should be done. Didn't actually checked what this driver does.

I was going to reply to all the questions in one pass but let me handle piece by piece.

Here are some facts.
- This hardware supports memcpy and memset only.
- Memset feature was removed from the kernel sometime around 3.14. So no memset support in this driver either.
- The hardware does not support DMA slave support
- The goal is to provide an interface to DMA engine framework for memcpy optimization so that the rest of the kernel drivers and applications make use of the hardware.

Quoted 1 line

CSRT is an Intel specific ACPI table for slave devices.

Wrong.
It was designed by Microsoft to support multiple controllers, in particular DMACs.
Have you read that document I posted link to?

Quoted 2 lines

It was decided by
Linaro that CSRT will not be supported for ARM64.

Interesting, ARM64 platforms are not going to have more than one DMAC per system?

Quoted 9 lines

There were some discussions in ACPI forums to define a similar table for ARM64 but we are not there today and this hardware does not support slave interface.

ACPI enumeration is just like any other platform device. The driver gets looked up by a QCOM specific HID and the driver gets probed with the rest of the arguments in DSM object similar to device-tree attributes. The code uses device functions so the driver is not aware of where the parameters are coming from.

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#40 lore raw
Quoted 43 lines · Andy Shevchenko
Quoted 34 lines · Sinan Kaya
Quoted 12 lines

The ACPI tables DSDT and CSRT (more info here:
http://www.acpi.info/links.htm) defines properties.

DSDT:
per DMAC: the resources
per client: FixedDMA descriptor that contains channel / request line
pair.

CSRT:
necessary table to map which DMAC provides which request line, thus
request line numbering are global on platform.

Quoted 9 lines

When DMAC driver is probed in the running system it should call as well registration function from acpi-dma.c.

All clients when use new DMA slave API gets channel automatically based on their FixedDMA property.

So, above is how it should be done. Didn't actually checked what this driver does.

I was going to reply to all the questions in one pass but let me handle piece by piece.

Here are some facts.
- This hardware supports memcpy and memset only.
- Memset feature was removed from the kernel sometime around 3.14. So no memset support in this driver either.
- The hardware does not support DMA slave support
- The goal is to provide an interface to DMA engine framework for memcpy optimization so that the rest of the kernel drivers and applications make use of the hardware.

Quoted 1 line

CSRT is an Intel specific ACPI table for slave devices.

Wrong.
It was designed by Microsoft to support multiple controllers, in particular DMACs.
Have you read that document I posted link to?

Quoted 5 lines
Quoted 2 lines

It was decided by
Linaro that CSRT will not be supported for ARM64.

Interesting, ARM64 platforms are not going to have more than one DMAC per system?

I cannot imagine that being true, and I don't see why Linaro would decide such a thing.

It does appear that it's not relevant to this device and driver, given the lack of clients, unless I've misunderstood?

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#41 lore raw
Quoted 10 lines · Mark Rutland
Quoted 10 lines
Quoted 1 line

CSRT is an Intel specific ACPI table for slave devices.

Wrong.
It was designed by Microsoft to support multiple controllers, in particular DMACs.
Have you read that document I posted link to?

Quoted 2 lines

It was decided by
Linaro that CSRT will not be supported for ARM64.

Quoted 8 lines
Quoted 2 lines

Interesting, ARM64 platforms are not going to have more than one DMAC per system?

I cannot imagine that being true, and I don't see why Linaro would decide such a thing.

It does appear that it's not relevant to this device and driver, given the lack of clients, unless I've misunderstood?

Yeah, just a side note.

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#42 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Mark Rutland
Quoted 7 lines
Quoted 1 line

CSRT is an Intel specific ACPI table for slave devices.

Wrong.
It was designed by Microsoft to support multiple controllers, in particular DMACs.
Have you read that document I posted link to?

Nope.

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

It was decided by
Linaro that CSRT will not be supported for ARM64.

Interesting, ARM64 platforms are not going to have more than one DMAC per system?

I cannot imagine that being true, and I don't see why Linaro would decide such a thing.

See this.

https://wiki.linaro.org/LEG/Engineering/Kernel/ACPI/TablePriorities

Quoted 6 lines
Quoted 3 lines

It does appear that it's not relevant to this device and driver, given the lack of clients, unless I've misunderstood?

Yeah, just a side note.

OK.

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#43 lore raw
Quoted 6 lines · Sinan Kaya
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It was decided by
Linaro that CSRT will not be supported for ARM64.

See this.

https://wiki.linaro.org/LEG/Engineering/Kernel/ACPI/TablePriorities

The CSRT is listed under "Want", not "Never" or "Don't Care", so Linaro have certainly not said that CSRT will not be supported. If anything, they have stated that the table should be supported.

I suspect that the rationale for it not being "Critical" or "Must" is that it's possible to use contemporary systems without DMA engines, but we will need support at some point in future.

I also note that there are Linaro patches adding supoprt for DBG2 [1] , which is listed as "Never". So the page may be out of date...

Leif, Al?

[1] https://lkml.org/lkml/2015/9/8/287

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#49 lore raw
In reply to Mark Rutland
Quoted 2 lines · Mark Rutland

It does appear that it's not relevant to this device and driver, given the lack of clients, unless I've misunderstood?

You are right. Kernel and guest machine kernel are the only user of this DMA device.

No other HW devices.

Signature · 3 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#44 lore raw
In reply to Mark Rutland
Quoted 3 lines · Mark Rutland
Quoted 2 lines · Sinan Kaya
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It was decided by
Linaro that CSRT will not be supported for ARM64.

Hrm. I personally decided we didn't have to worry about using the CSRT (specifically, let's wait until someone has a need for it), but I know of no decision to *not* support it. Please cite a source for that claim.

Quoted 7 lines
Quoted 3 lines

See this.

https://wiki.linaro.org/LEG/Engineering/Kernel/ACPI/TablePriorities

The CSRT is listed under "Want", not "Never" or "Don't Care", so Linaro have certainly not said that CSRT will not be supported. If anything, they have stated that the table should be supported.

"Want" means interesting, and probably useful, but no clear indication that anyone actually needs it. At one point, we thought we might use the CSRT for describing DMA, but it turns out we have not needed to.

However, let's make sure we're saying the same thing: the CSRT table is properly defined in the kernel include/acpi/actbl2.h file so one can read such a table and use it if they so choose. Nothing that we have done at Linaro in the arm64 part of the kernel relies on any of the content from the CSRT, nor does it preclude someone relying on that content. So, the CSRT is defined, and is usable, but is just not being used -- by Linaro -- at present.

If that needs to change, let me know; no one has asked us to use the CSRT for a DMA engine, and we have not been provided any hardware that requires it.

Quoted 3 lines

I suspect that the rationale for it not being "Critical" or "Must" is that it's possible to use contemporary systems without DMA engines, but we will need support at some point in future.

Essentially correct. We (Linaro ACPI team) would be glad to work on it, if needed. We just need to know that someone wants it, and we need to have some way to test it (i.e., aka "hardware").

Quoted 2 lines

I also note that there are Linaro patches adding supoprt for DBG2 [1] , which is listed as "Never". So the page may be out of date...

Sadly, it is indeed out of date, but it is on my TODO list. The DBG2 table was originally listed as "Never" only because of the licensing; this has since changed and is now usable for consoles, so it got worked on and implemented.

Quoted 7 lines

Leif, Al?

[1] https://lkml.org/lkml/2015/9/8/287

Thanks,
Mark.

Signature · 8 lines
ciao,
al
-----------------------------------
Al Stone
Software Engineer
Linaro Enterprise Group
[email protected]
-----------------------------------
#45 lore raw
Quoted 10 lines · Al Stone
Quoted 5 lines · Mark Rutland

On Fri, Oct 30, 2015 at 02:48:06PM -0400, Sinan Kaya wrote:

The CSRT is listed under "Want", not "Never" or "Don't Care", so Linaro have certainly not said that CSRT will not be supported. If anything, they have stated that the table should be supported.

"Want" means interesting, and probably useful, but no clear indication that anyone actually needs it. At one point, we thought we might use the CSRT for describing DMA, but it turns out we have not needed to.

Then you are going to have either 1 or 0 DMAC for slave devices, right?

The CSRT, unfortunately, the only way how to enumerate DMAC to be used by slave devices.
You may look into drivers/dma/acpi-dma.c for usage in Linux.

Yes, I know about _DSD, but I don't think it will provide soon any other official mechanisms to what we have now. Better to ask Rafael and Mika.

Quoted 7 lines

However, let's make sure we're saying the same thing: the CSRT table is properly defined in the kernel include/acpi/actbl2.h file so one can read such a table and use it if they so choose. Nothing that we have done at Linaro in the arm64 part of the kernel relies on any of the content from the CSRT, nor does it preclude someone relying on that content. So, the CSRT is defined, and is usable, but is just not being used -- by Linaro -- at present.

This sounds clear.

Quoted 3 lines

If that needs to change, let me know; no one has asked us to use the CSRT for a DMA engine, and we have not been provided any hardware that requires it.

See above.

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#46 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Al Stone
Quoted 5 lines · Mark Rutland

On Fri, Oct 30, 2015 at 02:48:06PM -0400, Sinan Kaya wrote:

The CSRT is listed under "Want", not "Never" or "Don't Care", so Linaro have certainly not said that CSRT will not be supported. If anything, they have stated that the table should be supported.

Quoted 5 lines
Quoted 3 lines

"Want" means interesting, and probably useful, but no clear indication that anyone actually needs it. At one point, we thought we might use the CSRT for describing DMA, but it turns out we have not needed to.

Then you are going to have either 1 or 0 DMAC for slave devices, right?

I suspect that the currently supported platforms have 0. If not, we have problems.

Quoted 7 lines

The CSRT, unfortunately, the only way how to enumerate DMAC to be used by slave devices.
You may look into drivers/dma/acpi-dma.c for usage in Linux.

Yes, I know about _DSD, but I don't think it will provide soon any other official mechanisms to what we have now. Better to ask Rafael and Mika.

_DSD is insufficient here, given that there is no prescribed way to use it to describe DMA. Anything for that would have to go through ASWG before we could use it.

Thanks,
Mark.

author
#5 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Arnd Bergmann

thanks for the review. I'll work on these.

Quoted 10 lines · Arnd Bergmann
Quoted 5 lines · On Thursday 29 October 2015 23:08:13 Sinan Kaya wrote:

This patch adds support for hidma engine. The driver consists of two logical blocks. The DMA engine interface and the low-level interface. This version of the driver does not support virtualization on this release and only memcpy interface support is included.

Does that mean you can have slave device support eventually?

If so, please put that into the binding document already.

will do.

Quoted 15 lines
Quoted 15 lines
---
  .../devicetree/bindings/dma/qcom_hidma.txt         |   18 +
  drivers/dma/Kconfig                                |   11 +
  drivers/dma/Makefile                               |    4 +
  drivers/dma/qcom_hidma.c                           | 1717 ++++++++++++++++++++
  drivers/dma/qcom_hidma.h                           |   44 +
  drivers/dma/qcom_hidma_ll.c                        | 1132 +++++++++++++
  6 files changed, 2926 insertions(+)

create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma.txt create mode 100644 drivers/dma/qcom_hidma.c
create mode 100644 drivers/dma/qcom_hidma.h
create mode 100644 drivers/dma/qcom_hidma_ll.c

Quoted 15 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 4

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +4 -0
new file mode 100644
index 0000000..9a01635
@@ -0,0 +1,18 @@
+Qualcomm Technologies HIDMA Channel driver
+
+Required properties:
+- compatible: must contain "qcom,hidma"

Be more specific here. Also, should this be 'hisilicon,hidma-1.0' rather than 'qcom'? I'm guessing from the name that this is a device you licensed from them.

No, this is a QCOM part. I used the driver from hisilicon as a starting point instead of starting from scratch. That's why, I kept the original copy rights.

Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 11

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +7 -0
+- reg: Addresses for the transfer and event channel
+- interrupts: Should contain the event interrupt
+- desc-count: Number of asynchronous requests this channel can handle
+- event-channel: The HW event channel completions will be delivered.
+Example:
+
+	hidma_24: hidma@0x5c050000 {

Name should be 'dma-controller' in DT, not 'hidma'.

will test and change.

Quoted 10 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 18

Quoted 8 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +7 -0
+		compatible = "qcom,hidma";
+		reg = <0 0x5c050000 0x0 0x1000>,
+		      <0 0x5c0b0000 0x0 0x1000>;
+		interrupts = <0 389 0>;
+		desc-count = <10>;
+		event-channel = /bits/ 8 <4>;
+	};

Remove the /bits/.

ok

Quoted 29 lines
Quoted 29 lines
drivers/dma/Kconfig +11 -0
index 76a5a5e..2645185 100644
@@ -512,6 +512,17 @@ config QCOM_HIDMA_MGMT
  	  OS would run QCOM_HIDMA driver and the hypervisor would run
  	  the QCOM_HIDMA_MGMT driver.
 
+config QCOM_HIDMA
+	tristate "Qualcomm Technologies HIDMA support"
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Enable support for the Qualcomm Technologies HIDMA controller.
+	  The HIDMA controller supports optimized buffer copies
+	  (user to kernel, kernel to kernel, etc.).  It only supports
+	  memcpy/memset interfaces. The core is not intended for general
+	  purpose slave DMA.
+
  config XILINX_VDMA
  	tristate "Xilinx AXI VDMA Engine"
  	depends on (ARCH_ZYNQ || MICROBLAZE)
drivers/dma/Makefile +0 -0
index 3d25ffd..5665df2 100644
@@ -53,6 +53,10 @@ obj-$(CONFIG_PL330_DMA) += pl330.o
  obj-$(CONFIG_PPC_BESTCOMM) += bestcomm/
Quoted 8 lines

drivers/dma/Makefile obj-$(CONFIG_PL330_DMA) += pl330.o · line 58

Quoted 5 lines
drivers/dma/Makefile +3 -0
  obj-$(CONFIG_PXA_DMA) += pxa_dma.o
  obj-$(CONFIG_QCOM_BAM_DMA) += qcom_bam_dma.o
+obj-$(CONFIG_QCOM_HIDMA) +=  qcom_hdma.o
+qcom_hdma-objs        := qcom_hidma_ll.o qcom_hidma.o
+

The driver is linked into a single module, so all the EXPORT_SYMBOL statements can be dropped.

will test and change.

Quoted 11 lines

drivers/dma/Makefile obj-$(CONFIG_PL330_DMA) += pl330.o

Quoted 9 lines
drivers/dma/Makefile +8 -0
+/* Default idle time is 2 seconds. This parameter can
+ * be overridden by changing the following
+ * /sys/bus/platform/devices/QCOM8061:<xy>/power/autosuspend_delay_ms
+ * during kernel boot.
+ */
+#define AUTOSUSPEND_TIMEOUT		2000
+#define HIDMA_DEFAULT_DESCRIPTOR_COUNT	16
+#define MODULE_NAME			"hidma"

MODULE_NAME and HIDMA_DEFAULT_DESCRIPTOR_COUNT can be dropped

I'll remove the module_name. The default descriptor is used if device-tree or acpi table does not have the descriptor count.

Quoted 15 lines
Quoted 15 lines
drivers/dma/Makefile +13 -0
+#define HIDMA_RUNTIME_GET(dmadev)				\
+do {								\
+	atomic_inc(&(dmadev)->pm_counter);			\
+	TRC_PM((dmadev)->ddev.dev,				\
+		"%s:%d pm_runtime_get %d\n", __func__, __LINE__,\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_get_sync((dmadev)->ddev.dev);		\
+} while (0)
+
+#define HIDMA_RUNTIME_SET(dmadev)				\
+do {								\
+	atomic_dec(&(dmadev)->pm_counter);			\
+	TRC_PM((dmadev)->ddev.dev,				\
Quoted 8 lines

drivers/dma/Makefile

Quoted 6 lines
drivers/dma/Makefile +6 -0
+		"%s:%d pm_runtime_put_autosuspend:%d\n",	\
+		__func__, __LINE__,				\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_mark_last_busy((dmadev)->ddev.dev);		\
+	pm_runtime_put_autosuspend((dmadev)->ddev.dev);		\
+} while (0)

Inline functions.

ok, I was hoping to keep the file and line numbers as the PM stuff gets called from multiple locations. should I call the inline functions with __func__ and __LINE__ from another macro like

#define HIDMA_RUNTIME_GET(dmadev)
	func(dmadev, __func__, __LINE__)

etc.

Quoted 9 lines

drivers/dma/Makefile

Quoted 5 lines
drivers/dma/Makefile +4 -0
+struct hidma_test_sync {
+	atomic_t			counter;
+	wait_queue_head_t		wq;
+};

Let me guess, you converted this from a semaphore? ;-)

Just put the two members into the containing structure and relete it here.

Probably some other code that I don't remember. will do.

Quoted 11 lines
Quoted 11 lines
drivers/dma/Makefile +10 -0
+struct hidma_dev {
+	u8				evridx;
+	u32				nr_descriptors;
+
+	void				*lldev;
+	void				__iomem *dev_trca;
+	void				__iomem *dev_evca;
+	int (*self_test)(struct hidma_dev *device);
+	struct dentry			*debugfs;
+	struct dentry			*stats;
Quoted 8 lines

drivers/dma/Makefile

Quoted 6 lines
drivers/dma/Makefile +6 -0
+
+	/* used to protect the pending channel list*/
+	spinlock_t			lock;
+	dma_addr_t			dev_trca_phys;
+	struct dma_device		ddev;
+	struct tasklet_struct		tasklet;

workqueue maybe?

is there an advantage of workqueue over tasklet? I'm open to suggestions.

Quoted 6 lines

drivers/dma/Makefile

Quoted 4 lines
drivers/dma/Makefile +3 -0
+	resource_size_t			dev_trca_size;
+	dma_addr_t			dev_evca_phys;
+	resource_size_t			dev_evca_size;

All three look unused and can be removed.

ok.

Quoted 13 lines

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +9 -0
+static unsigned int debug_pm;
+module_param(debug_pm, uint, 0644);
+MODULE_PARM_DESC(debug_pm,
+		 "debug runtime power management transitions (default: 0)");
+
+#define TRC_PM(...) do {			\
+		if (debug_pm)			\
+			dev_info(__VA_ARGS__);	\
+	} while (0)

Again, remove these after you are done debugging the problem at hand, we don't need to clutter up the upstream version.

ok, I'll take them out if that's the norm. I was hoping to keep them in case something shows up.

Quoted 17 lines
Quoted 5 lines
drivers/dma/Makefile +4 -0
+	/*
+	 * It is assumed that the hardware can move the data within 1s
+	 * and signal the OS of the completion
+	 */

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+	ret = wait_event_interruptible_timeout(dmadev->test_result.wq,
+		atomic_read(&dmadev->test_result.counter) == (map_count),
+				msecs_to_jiffies(10000));
+
+	if (ret <= 0) {
+		dev_err(dmadev->ddev.dev,
+			"Self-test sg copy timed out, disabling\n");
+		err = -ENODEV;
+		goto tx_status;
+	}

Why ENODEV? Could you make this handle restarted system calls?

This is the self test code. It gets called from probe. If there is a problem with the device or system configuration, I don't want to enable this device. I can certainly return a different error code though. What's a good code?

Quoted 13 lines

drivers/dma/Makefile

Quoted 9 lines
drivers/dma/Makefile +8 -0
+
+/*
+ * Perform a streaming transaction to verify the HW works.
+ */
+static int hidma_selftest_streaming(struct hidma_dev *dmadev,
+			struct dma_chan *dma_chanptr, u64 size,
+			unsigned long flags)
+{

You have a lot of selftest code here. Can you try to move that into a file that works for all DMA engines? It feels like this should not be part of a driver.

Will try.

Quoted 9 lines

drivers/dma/Makefile

Quoted 6 lines
drivers/dma/Makefile +5 -0
+
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+
+#define SIER_CHAN_SHOW(chan, name) \
+		seq_printf(s, #name "=%u\n", chan->name)

can be open-coded for clarity.

I think I copied this from another driver. Would you rather see seq_printf in the code than a macro.

Sorry, I didn't get what you mean by "open-coded".

Quoted 17 lines
Quoted 6 lines
drivers/dma/Makefile +6 -0
+       ret = dma_mapping_error(dev, dma_src);
+       if (ret) {
+               dev_err(dev, "dma_mapping_error with ret:%d\n", ret);
+               ret = -ENOMEM;
+       } else {
+               phys_addr_t phys;

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +10 -0
+
+               phys = dma_to_phys(dev, dma_src);
+               if (strcmp(__va(phys), "hello world") != 0) {
+                       dev_err(dev, "memory content mismatch\n");
+                       ret = -EINVAL;
+               } else {
+                       dev_dbg(dev, "mapsingle:dma_map_single works\n");
+               }
+               dma_unmap_single(dev, dma_src, buf_size, DMA_TO_DEVICE);
+       }
Quoted 2 lines

dma_to_phys() is architecture specific and does not work if you have an IOMMU. Just use the virtual address you passed into dma_map_*.

Should we fix the real problem?

I patched dma_to_phys to call IOMMU driver for translation when IOMMU is present. I was planning to upstream that patch when Robin Murphy's changes make upstream.

The assumption of phys==dma address doesn't look scalable to me. I was checking the DMA subsystem for correctness with this test. If use dma_src, it is going to be a 1==1 test.

Quoted 12 lines
Quoted 12 lines
drivers/dma/Makefile +11 -0
+/**
+ * hidma_dma_info: display HIDMA device info
+ *
+ * Display the info for the current HIDMA device.
+ */
+static int hidma_dma_info(struct seq_file *s, void *unused)
+{
+	struct hidma_dev *dmadev = s->private;
+	struct dma_device *dma = &dmadev->ddev;
+
+	seq_printf(s, "nr_descriptors=%d\n", dmadev->nr_descriptors);
Quoted 8 lines

drivers/dma/Makefile

Quoted 6 lines
drivers/dma/Makefile +6 -0
+	seq_printf(s, "dev_trca=%p\n", &dmadev->dev_trca);
+	seq_printf(s, "dev_trca_phys=%pa\n", &dmadev->dev_trca_phys);
+	seq_printf(s, "dev_trca_size=%pa\n", &dmadev->dev_trca_size);
+	seq_printf(s, "dev_evca=%p\n", &dmadev->dev_evca);
+	seq_printf(s, "dev_evca_phys=%pa\n", &dmadev->dev_evca_phys);
+	seq_printf(s, "dev_evca_size=%pa\n", &dmadev->dev_evca_size);

Don't print pointers here.

ok

Quoted 14 lines
Quoted 14 lines
drivers/dma/Makefile +13 -0
+	seq_printf(s, "self_test=%u\n",
+		atomic_read(&dmadev->test_result.counter));
+
+	seq_printf(s, "copy%s%s%s%s%s%s%s%s%s%s%s\n",
+		dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
+		dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
+		dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
+		dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",
+		dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "",
+		dma_has_cap(DMA_SG, dma->cap_mask) ? " sg" : "",
+		dma_has_cap(DMA_ASYNC_TX, dma->cap_mask) ? " async" : "",
+		dma_has_cap(DMA_SLAVE, dma->cap_mask) ? " slave" : "",
+		dma_has_cap(DMA_CYCLIC, dma->cap_mask) ? " cyclic" : "",
Quoted 9 lines

drivers/dma/Makefile

Quoted 5 lines
drivers/dma/Makefile +5 -0
+		dma_has_cap(DMA_INTERLEAVE, dma->cap_mask) ? " intl" : "",
+		dma_has_cap(DMA_MEMCPY, dma->cap_mask) ? " memcpy" : "");
+
+	return 0;
+}

The selftest part and the features could just be separate files in the core dmaengine code, it doesn't really belong here.

I'll take a look. It could take a couple of iterations to get this right but I could certainly move my testing to another file for sharing.

Quoted 5 lines
Quoted 5 lines
drivers/dma/Makefile +5 -0
+}
+#else
+static void hidma_debug_uninit(struct hidma_dev *dmadev)
+{
+}
Quoted 8 lines

drivers/dma/Makefile

Quoted 5 lines
drivers/dma/Makefile +5 -0
+static int hidma_debug_init(struct hidma_dev *dmadev)
+{
+	return 0;
+}
+#endif

You can remove the #ifdef here. The debugfs code already stubs out all debugfs_create_*() and turns it all into nops when it is disabled.

ok, I think I got compilation errors with the data structures but I'll take a look.

Quoted 10 lines

drivers/dma/Makefile

Quoted 8 lines
drivers/dma/Makefile +7 -0
+	dma_cap_set(DMA_MEMCPY, dmadev->ddev.cap_mask);
+	/* Apply default dma_mask if needed */
+	if (!pdev->dev.dma_mask) {
+		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
+		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
+	}
+

remove the check, or use

I got caught on this problem before. Let me go back and revisit. It took my entire day to figure out that dma_mask pointer was not set.

Quoted 6 lines
	if (WARN_ON(!pdev->dev.dma_mask))
		return -ENXIO;

The dma mask has to always be set by the platform code before probe() is called. If it is not set, you are not allowed to perform DMA.

I tested this on an ACPI platform BTW when I was working on the initial implementation.

Quoted 13 lines
Quoted 10 lines
drivers/dma/Makefile +8 -0
+	dmadev->dev_evca_phys = evca_resource->start;
+	dmadev->dev_evca_size = resource_size(evca_resource);
+
+	dev_dbg(&pdev->dev, "dev_evca_phys:%pa\n", &dmadev->dev_evca_phys);
+	dev_dbg(&pdev->dev, "dev_evca_size:%pa\n", &dmadev->dev_evca_size);
+
 
+	dev_dbg(&pdev->dev, "qcom_hidma: mapped EVCA %pa to %p\n",
+		&dmadev->dev_evca_phys, dmadev->dev_evca);
Quoted 7 lines

drivers/dma/Makefile

Quoted 5 lines
drivers/dma/Makefile +5 -0
+	dmadev->dev_trca_phys = trca_resource->start;
+	dmadev->dev_trca_size = resource_size(trca_resource);
+
+	dev_dbg(&pdev->dev, "dev_trca_phys:%pa\n", &dmadev->dev_trca_phys);
+	dev_dbg(&pdev->dev, "dev_trca_size:%pa\n", &dmadev->dev_trca_size);

Don't print pointers.

OK

Quoted 37 lines
Quoted 37 lines
drivers/dma/Makefile +36 -0
+	rc = devm_request_irq(&pdev->dev, chirq, hidma_chirq_handler, 0,
+			      "qcom-hidma", &dmadev->lldev);
+	if (rc) {
+		dev_err(&pdev->dev, "chirq registration failed: %d\n", chirq);
+		goto chirq_request_failed;
+	}
+
+	dev_dbg(&pdev->dev, "initializing DMA channels\n");
+	INIT_LIST_HEAD(&dmadev->ddev.channels);
+	rc = hidma_chan_init(dmadev, 0);
+	if (rc) {
+		dev_err(&pdev->dev, "probe:channel init failed\n");
+		goto channel_init_failed;
+	}
+	dev_dbg(&pdev->dev, "HI-DMA engine driver starting self test\n");
+	rc = dmadev->self_test(dmadev);
+	if (rc) {
+		dev_err(&pdev->dev, "probe: self test failed: %d\n", rc);
+		goto self_test_failed;
+	}
+	dev_info(&pdev->dev, "probe: self test succeeded.\n");
+
+	dev_dbg(&pdev->dev, "calling dma_async_device_register\n");
+	rc = dma_async_device_register(&dmadev->ddev);
+	if (rc) {
+		dev_err(&pdev->dev,
+			"probe: failed to register slave DMA: %d\n", rc);
+		goto device_register_failed;
+	}
+	dev_dbg(&pdev->dev, "probe: dma_async_device_register done\n");
+
+	rc = hidma_debug_init(dmadev);
+	if (rc) {
+		dev_err(&pdev->dev,
+			"probe: failed to init debugfs: %d\n", rc);
+		goto debug_init_failed;
Quoted 8 lines

drivers/dma/Makefile

Quoted 6 lines
drivers/dma/Makefile +6 -0
+	}
+
+	dev_info(&pdev->dev, "HI-DMA engine driver registration complete\n");
+	platform_set_drvdata(pdev, dmadev);
+	HIDMA_RUNTIME_SET(dmadev);
+	return 0;

Remove the debug prints when you are done debugging.

errors or the dev_infos?

Quoted 16 lines

drivers/dma/Makefile

Quoted 13 lines
drivers/dma/Makefile +12 -0
+debug_init_failed:
+device_register_failed:
+self_test_failed:
+channel_init_failed:
+chirq_request_failed:
+	hidma_ll_uninit(dmadev->lldev);
+ll_init_failed:
+evridx_failed:
+remap_trca_failed:
+remap_evca_failed:
+	if (dmadev)
+		hidma_free(dmadev);

Rename the labels according to what you do at in the failure case and remove most of them. This is 'goto', not 'comefrom' ;-)

ok, We had different opinions how gotos should be written.

Quoted 13 lines

drivers/dma/Makefile

Quoted 9 lines
drivers/dma/Makefile +8 -0
+static struct platform_driver hidma_driver = {
+	.probe = hidma_probe,
+	.remove = hidma_remove,
+	.driver = {
+		.name = MODULE_NAME,
+		.owner = THIS_MODULE,
+		.of_match_table = of_match_ptr(hidma_match),
+		.acpi_match_table = ACPI_PTR(hidma_acpi_ids),

Remove .owner and of_match_ptr().

ok, will do.

Quoted 8 lines
Quoted 8 lines
drivers/dma/Makefile +8 -0
+	},
+};
+
+static int __init hidma_init(void)
+{
+	return platform_driver_register(&hidma_driver);
+}
+late_initcall(hidma_init);
Quoted 8 lines

drivers/dma/Makefile

Quoted 6 lines
drivers/dma/Makefile +6 -0
+
+static void __exit hidma_exit(void)
+{
+	platform_driver_unregister(&hidma_driver);
+}
+module_exit(hidma_exit);

module_platform_driver()

ok

Quoted 16 lines

drivers/dma/Makefile

Quoted 13 lines
drivers/dma/Makefile +12 -0
+
+	if (unlikely(tre_ch >= lldev->nr_tres)) {
+		dev_err(lldev->dev, "invalid TRE number in free:%d", tre_ch);
+		return;
+	}
+
+	tre = &lldev->trepool[tre_ch];
+	if (unlikely(atomic_read(&tre->allocated) != true)) {
+		dev_err(lldev->dev, "trying to free an unused TRE:%d",
+			tre_ch);
+		return;
+	}

Remove the 'unlikely' and the redundant '!= true'.

Quoted 1 line

Only use 'likely' or 'unlikely' if you can measure a difference.

ok

Quoted 43 lines
Quoted 43 lines
drivers/dma/Makefile +42 -0
+static int hidma_ll_reset(struct hidma_lldev *lldev)
+{
+	u32 val;
+	int count;
+
+	val = readl_relaxed(lldev->trca + TRCA_CTRLSTS_OFFSET);
+	val = val & ~(CH_CONTROL_MASK << 16);
+	val = val | (CH_RESET << 16);
+	writel_relaxed(val, lldev->trca + TRCA_CTRLSTS_OFFSET);
+
+	/* wait until the reset is performed */
+	wmb();
+
+	/* Delay 10ms after reset to allow DMA logic to quiesce.*/
+	for (count = 0; count < 10; count++) {
+		val = readl_relaxed(lldev->trca + TRCA_CTRLSTS_OFFSET);
+		lldev->trch_state = (val >> CH_STATE_BIT_POS)
+					& CH_STATE_MASK;
+		if (lldev->trch_state == CH_DISABLED)
+			break;
+		mdelay(1);
+	}
+	val = readl_relaxed(lldev->trca + TRCA_CTRLSTS_OFFSET);
+	lldev->trch_state = (val >> CH_STATE_BIT_POS) & CH_STATE_MASK;
+	if (lldev->trch_state != CH_DISABLED) {
+		dev_err(lldev->dev,
+			"transfer channel did not reset\n");
+		return -ENODEV;
+	}
+
+	val = readl_relaxed(lldev->evca + EVCA_CTRLSTS_OFFSET);
+	val = val & ~(CH_CONTROL_MASK << 16);
+	val = val | (CH_RESET << 16);
+	writel_relaxed(val, lldev->evca + EVCA_CTRLSTS_OFFSET);
+
+	/* wait until the reset is performed */
+	wmb();
+
+	/* Delay 10ms after reset to allow DMA logic to quiesce.*/
+	for (count = 0; count < 10; count++) {
+		val = readl_relaxed(lldev->evca + EVCA_CTRLSTS_OFFSET);
+		lldev->evch_state = (val >> CH_STATE_BIT_POS)
Quoted 9 lines

drivers/dma/Makefile

Quoted 5 lines
drivers/dma/Makefile +5 -0
+					& CH_STATE_MASK;
+		if (lldev->evch_state == CH_DISABLED)
+			break;
+		mdelay(1);
+	}

Try using a workqueue to get into a state where you can call msleep() instead of mdelay().

will try

Quoted 4 lines

Also, if you waste CPU cycles for hundreds of milliseconds, it's unlikely that the function is so performance critical that it requires writel_relaxed().

Just use writel() here.

The issue is not writel_relaxed vs. writel. After I issue reset, I need wait for some time to confirm reset was done. I can use readl_polling instead of mdelay if we don't like mdelay.

Quoted 24 lines
Quoted 24 lines
drivers/dma/Makefile +24 -0
+/*
+ * The interrupt handler for HIDMA will try to consume as many pending
+ * EVRE from the event queue as possible. Each EVRE has an associated
+ * TRE that holds the user interface parameters. EVRE reports the
+ * result of the transaction. Hardware guarantees ordering between EVREs
+ * and TREs. We use last processed offset to figure out which TRE is
+ * associated with which EVRE. If two TREs are consumed by HW, the EVREs
+ * are in order in the event ring.
+ * This handler will do a one pass for consuming EVREs. Other EVREs may
+ * be delivered while we are working. It will try to consume incoming
+ * EVREs one more time and return.
+ * For unprocessed EVREs, hardware will trigger another interrupt until
+ * all the interrupt bits are cleared.
+ */
+static void hidma_ll_int_handler_internal(struct hidma_lldev *lldev)
+{
+	u32 status;
+	u32 enable;
+	u32 cause;
+	int repeat = 2;
+	unsigned long timeout;
+
+	status = readl_relaxed(lldev->evca + EVCA_IRQ_STAT_OFFSET);
+	enable = readl_relaxed(lldev->evca + EVCA_IRQ_EN_OFFSET);
Quoted 8 lines

drivers/dma/Makefile

Quoted 2 lines
drivers/dma/Makefile +2 -0
+	cause = status & enable;
+

Reading the status probably requires a readl() rather than readl_relaxed() to guarantee that the DMA data has arrived in memory by the time that the register data is seen by the CPU. If using readl_relaxed() here is a valid and required optimization, please add a comment to explain why it works and how much you gain.

I will add some description. This is a high speed peripheral. I don't like spreading barriers as candies inside the readl and writel unless I have to.

According to the barriers video, I watched on youtube this should be the rule for ordering.

"if you do two relaxed reads and check the results of the returned variables, ARM architecture guarantees that these two relaxed variables will get observed during the check."

this is called implied ordering or something of that sort.

Quoted 13 lines

drivers/dma/Makefile

Quoted 10 lines
drivers/dma/Makefile +9 -0
+		/* Another interrupt might have arrived while we are
+		 * processing this one. Read the new cause.
+		 */
+		status = readl_relaxed(lldev->evca + EVCA_IRQ_STAT_OFFSET);
+		enable = readl_relaxed(lldev->evca + EVCA_IRQ_EN_OFFSET);
+		cause = status & enable;
+
+		repeat--;
+	}

Same here.

comment above.

Quoted 31 lines
Quoted 31 lines
drivers/dma/Makefile +30 -0
+}
+
+
+static int hidma_ll_enable(struct hidma_lldev *lldev)
+{
+	u32 val;
+
+	val = readl_relaxed(lldev->evca + EVCA_CTRLSTS_OFFSET);
+	val &= ~(CH_CONTROL_MASK << 16);
+	val |= (CH_ENABLE << 16);
+
+	writel_relaxed(val, lldev->evca + EVCA_CTRLSTS_OFFSET);
+
+	/* wait until channel is enabled */
+	wmb();
+
+	mdelay(1);
+
+	val = readl_relaxed(lldev->evca + EVCA_CTRLSTS_OFFSET);
+	lldev->evch_state = (val >> CH_STATE_BIT_POS) & CH_STATE_MASK;
+	if ((lldev->evch_state != CH_ENABLED) &&
+		(lldev->evch_state != CH_RUNNING)) {
+		dev_err(lldev->dev,
+			"event channel did not get enabled\n");
+		return -ENODEV;
+	}
+
+	val = readl_relaxed(lldev->trca + TRCA_CTRLSTS_OFFSET);
+	val = val & ~(CH_CONTROL_MASK << 16);
+	val = val | (CH_ENABLE << 16);
Quoted 8 lines

drivers/dma/Makefile

Quoted 6 lines
drivers/dma/Makefile +6 -0
+	writel_relaxed(val, lldev->trca + TRCA_CTRLSTS_OFFSET);
+
+	/* wait until channel is enabled */
+	wmb();
+
+	mdelay(1);

Another workqueue? You should basically never call mdelay().

I'll use polled read instead.

Quoted 14 lines

drivers/dma/Makefile

Quoted 11 lines
drivers/dma/Makefile +10 -0
+static int hidma_ll_hw_start(void *llhndl)
+{
+	int rc = 0;
+	struct hidma_lldev *lldev = llhndl;
+	unsigned long irqflags;
+
+	spin_lock_irqsave(&lldev->lock, irqflags);
+	writel_relaxed(lldev->tre_write_offset,
+			lldev->trca + TRCA_DOORBELL_OFFSET);
+	spin_unlock_irqrestore(&lldev->lock, irqflags);

How does this work? The writel_relaxed() won't synchronize with either the DMA data or the spinlock.

mutex and spinlocks have barriers inside. See the youtube video.

https://www.youtube.com/watch?v=6ORn6_35kKo

Quoted 6 lines

drivers/dma/Makefile

Quoted 4 lines
drivers/dma/Makefile +3 -0
+int hidma_ll_init(void **lldevp, struct device *dev, u32 nr_tres,
+			void __iomem *trca, void __iomem *evca,
+			u8 evridx)

How about returning the pointer rather than passing in an indirect pointer?

ok

Quoted 6 lines

Also, your abstraction seem to go a little too far if the upper driver doesn't know what the lower driver calls its main device structure.

Or you can go further and just embed the struct hidma_lldev within the struct hidma_dev to save one?

That's how it was before. It got too complex and variables/spinlocks got intermixed. I borrowed the upper layer and it worked as it is. I rather keep all hardware stuff in another file and do not mix and match for safety.

Quoted 38 lines
Quoted 38 lines
drivers/dma/Makefile +37 -0
+void hidma_ll_chstats(struct seq_file *s, void *llhndl, u32 tre_ch)
+{
+	struct hidma_lldev *lldev = llhndl;
+	struct hidma_tre *tre;
+	u32 length;
+	dma_addr_t src_start;
+	dma_addr_t dest_start;
+	u32 *tre_local;
+
+	if (unlikely(tre_ch >= lldev->nr_tres)) {
+		dev_err(lldev->dev, "invalid TRE number in chstats:%d",
+			tre_ch);
+		return;
+	}
+	tre = &lldev->trepool[tre_ch];
+	seq_printf(s, "------Channel %d -----\n", tre_ch);
+	seq_printf(s, "allocated=%d\n", atomic_read(&tre->allocated));
+	HIDMA_CHAN_SHOW(tre, queued);
+	seq_printf(s, "err_info=0x%x\n",
+		   lldev->tx_status_list[tre->chidx].err_info);
+	seq_printf(s, "err_code=0x%x\n",
+		   lldev->tx_status_list[tre->chidx].err_code);
+	HIDMA_CHAN_SHOW(tre, status);
+	HIDMA_CHAN_SHOW(tre, chidx);
+	HIDMA_CHAN_SHOW(tre, dma_sig);
+	seq_printf(s, "dev_name=%s\n", tre->dev_name);
+	seq_printf(s, "callback=%p\n", tre->callback);
+	seq_printf(s, "data=%p\n", tre->data);
+	HIDMA_CHAN_SHOW(tre, tre_index);
+
+	tre_local = &tre->tre_local[0];
+	src_start = tre_local[TRE_SRC_LOW_IDX];
+	src_start = ((u64)(tre_local[TRE_SRC_HI_IDX]) << 32) + src_start;
+	dest_start = tre_local[TRE_DEST_LOW_IDX];
+	dest_start += ((u64)(tre_local[TRE_DEST_HI_IDX]) << 32);
+	length = tre_local[TRE_LEN_IDX];
+
Quoted 8 lines

drivers/dma/Makefile

Quoted 5 lines
drivers/dma/Makefile +5 -0
+	seq_printf(s, "src=%pap\n", &src_start);
+	seq_printf(s, "dest=%pap\n", &dest_start);
+	seq_printf(s, "length=0x%x\n", length);
+}
+EXPORT_SYMBOL_GPL(hidma_ll_chstats);

Remove all the pointers here. I guess you can remove the entire debugfs file really ;-)

ok, I need some facility to print out stuff when problems happened. Would you rather use sysfs?

Quoted 3 lines

This looks like it is better done using ftrace for the low-level internals of the driver.

I'll look at ftrace.

Quoted 3 lines

Arnd

thanks for the review again.

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 9 lines · Sinan Kaya
Quoted 6 lines
    if (WARN_ON(!pdev->dev.dma_mask))
        return -ENXIO;

The dma mask has to always be set by the platform code before probe() is called. If it is not set, you are not allowed to perform DMA.

I tested this on an ACPI platform BTW when I was working on the initial implementation.

PowerPC sets the mask to 32 bits by default:

http://lxr.free-electrons.com/ident?i=arch_setup_pdev_archdata

Should we do something similar in ARM64? Today, we have to manually set the DMA mask in all drivers.

Signature · 7 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Sinan Kaya
Quoted 31 lines · On Friday 30 October 2015 17:42:26 Sinan Kaya wrote:
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · On Thursday 29 October 2015 23:08:13 Sinan Kaya wrote:
---
  .../devicetree/bindings/dma/qcom_hidma.txt         |   18 +
  drivers/dma/Kconfig                                |   11 +
  drivers/dma/Makefile                               |    4 +
  drivers/dma/qcom_hidma.c                           | 1717 ++++++++++++++++++++
  drivers/dma/qcom_hidma.h                           |   44 +
  drivers/dma/qcom_hidma_ll.c                        | 1132 +++++++++++++
  6 files changed, 2926 insertions(+)

create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma.txt create mode 100644 drivers/dma/qcom_hidma.c
create mode 100644 drivers/dma/qcom_hidma.h
create mode 100644 drivers/dma/qcom_hidma_ll.c

Quoted 15 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 4

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +4 -0
new file mode 100644
index 0000000..9a01635
@@ -0,0 +1,18 @@
+Qualcomm Technologies HIDMA Channel driver
+
+Required properties:
+- compatible: must contain "qcom,hidma"

Be more specific here. Also, should this be 'hisilicon,hidma-1.0' rather than 'qcom'? I'm guessing from the name that this is a device you licensed from them.

Quoted 3 lines

No, this is a QCOM part. I used the driver from hisilicon as a starting point instead of starting from scratch. That's why, I kept the original copy rights.

I meant the 'hidma' name. ;-)

Quoted 10 lines
Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt line 11

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +7 -0
+- reg: Addresses for the transfer and event channel
+- interrupts: Should contain the event interrupt
+- desc-count: Number of asynchronous requests this channel can handle
+- event-channel: The HW event channel completions will be delivered.
+Example:
+
+	hidma_24: hidma@0x5c050000 {

Name should be 'dma-controller' in DT, not 'hidma'.

will test and change.

no need to test, Linux ignores the node name.

Quoted 5 lines
Quoted 2 lines

MODULE_NAME and HIDMA_DEFAULT_DESCRIPTOR_COUNT can be dropped

I'll remove the module_name. The default descriptor is used if device-tree or acpi table does not have the descriptor count.

I missed that part. If the descriptor count is a hardware feature, just make that property mandatory. OTOH, if this is an optimization setting, better drop that property entirely.

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +13 -0
+#define HIDMA_RUNTIME_GET(dmadev)				\
+do {								\
+	atomic_inc(&(dmadev)->pm_counter);			\
+	TRC_PM((dmadev)->ddev.dev,				\
+		"%s:%d pm_runtime_get %d\n", __func__, __LINE__,\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_get_sync((dmadev)->ddev.dev);		\
+} while (0)
+
+#define HIDMA_RUNTIME_SET(dmadev)				\
+do {								\
+	atomic_dec(&(dmadev)->pm_counter);			\
+	TRC_PM((dmadev)->ddev.dev,				\
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +6 -0
+		"%s:%d pm_runtime_put_autosuspend:%d\n",	\
+		__func__, __LINE__,				\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_mark_last_busy((dmadev)->ddev.dev);		\
+	pm_runtime_put_autosuspend((dmadev)->ddev.dev);		\
+} while (0)

Inline functions.

Quoted 8 lines

ok, I was hoping to keep the file and line numbers as the PM stuff gets called from multiple locations. should I call the inline functions with __func__ and __LINE__ from another macro like

#define HIDMA_RUNTIME_GET(dmadev)
	func(dmadev, __func__, __LINE__)

etc.

I would just drop the debugging macros entirely here.

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +10 -0
+struct hidma_dev {
+	u8				evridx;
+	u32				nr_descriptors;
+
+	void				*lldev;
+	void				__iomem *dev_trca;
+	void				__iomem *dev_evca;
+	int (*self_test)(struct hidma_dev *device);
+	struct dentry			*debugfs;
+	struct dentry			*stats;
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +6 -0
+
+	/* used to protect the pending channel list*/
+	spinlock_t			lock;
+	dma_addr_t			dev_trca_phys;
+	struct dma_device		ddev;
+	struct tasklet_struct		tasklet;

workqueue maybe?

Quoted 1 line

is there an advantage of workqueue over tasklet? I'm open to suggestions.

tasklets are not normally used in new code. They are only marginally faster than workqueues, but are executed in atomic context and cannot call sleeping functions.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +4 -0
+static unsigned int debug_pm;
+module_param(debug_pm, uint, 0644);
+MODULE_PARM_DESC(debug_pm,
+		 "debug runtime power management transitions (default: 0)");
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +5 -0
+
+#define TRC_PM(...) do {			\
+		if (debug_pm)			\
+			dev_info(__VA_ARGS__);	\
+	} while (0)

Again, remove these after you are done debugging the problem at hand, we don't need to clutter up the upstream version.

Quoted 2 lines

ok, I'll take them out if that's the norm. I was hoping to keep them in case something shows up.

In my experience, the bugs you have now are different from the bugs that other people find next, and debugging macros like this end up not helping then.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +8 -0
+	/*
+	 * It is assumed that the hardware can move the data within 1s
+	 * and signal the OS of the completion
+	 */
+	ret = wait_event_interruptible_timeout(dmadev->test_result.wq,
+		atomic_read(&dmadev->test_result.counter) == (map_count),
+				msecs_to_jiffies(10000));
+
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +6 -0
+	if (ret <= 0) {
+		dev_err(dmadev->ddev.dev,
+			"Self-test sg copy timed out, disabling\n");
+		err = -ENODEV;
+		goto tx_status;
+	}

Why ENODEV? Could you make this handle restarted system calls?

Quoted 4 lines

This is the self test code. It gets called from probe. If there is a problem with the device or system configuration, I don't want to enable this device. I can certainly return a different error code though. What's a good code?

I see. probe() is not restartable, so it cannot be -ERESTARTSYS.

Maybe better use wait_event_timeout and not handle the signals then. It will eventually time out if something goes wrong.

Quoted 9 lines
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +5 -0
+
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+
+#define SIER_CHAN_SHOW(chan, name) \
+		seq_printf(s, #name "=%u\n", chan->name)

can be open-coded for clarity.

Quoted 4 lines

I think I copied this from another driver. Would you rather see seq_printf in the code than a macro.

Sorry, I didn't get what you mean by "open-coded".

Yes, that is what I meant. Keep the code but don't put it into an inline function or macro.

Quoted 22 lines
Quoted 17 lines
Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +6 -0
+       ret = dma_mapping_error(dev, dma_src);
+       if (ret) {
+               dev_err(dev, "dma_mapping_error with ret:%d\n", ret);
+               ret = -ENOMEM;
+       } else {
+               phys_addr_t phys;

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +10 -0
+
+               phys = dma_to_phys(dev, dma_src);
+               if (strcmp(__va(phys), "hello world") != 0) {
+                       dev_err(dev, "memory content mismatch\n");
+                       ret = -EINVAL;
+               } else {
+                       dev_dbg(dev, "mapsingle:dma_map_single works\n");
+               }
+               dma_unmap_single(dev, dma_src, buf_size, DMA_TO_DEVICE);
+       }
Quoted 2 lines

dma_to_phys() is architecture specific and does not work if you have an IOMMU. Just use the virtual address you passed into dma_map_*.

Should we fix the real problem?

Quoted 7 lines

I patched dma_to_phys to call IOMMU driver for translation when IOMMU is present. I was planning to upstream that patch when Robin Murphy's changes make upstream.

The assumption of phys==dma address doesn't look scalable to me. I was checking the DMA subsystem for correctness with this test. If use dma_src, it is going to be a 1==1 test.

dma_to_phys is the internal helper that is used by the iommu implementation, drivers should never call it, and I don't see why you would do that.

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +13 -0
+	seq_printf(s, "self_test=%u\n",
+		atomic_read(&dmadev->test_result.counter));
+
+	seq_printf(s, "copy%s%s%s%s%s%s%s%s%s%s%s\n",
+		dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
+		dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
+		dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
+		dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",
+		dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "",
+		dma_has_cap(DMA_SG, dma->cap_mask) ? " sg" : "",
+		dma_has_cap(DMA_ASYNC_TX, dma->cap_mask) ? " async" : "",
+		dma_has_cap(DMA_SLAVE, dma->cap_mask) ? " slave" : "",
+		dma_has_cap(DMA_CYCLIC, dma->cap_mask) ? " cyclic" : "",
Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +5 -0
+		dma_has_cap(DMA_INTERLEAVE, dma->cap_mask) ? " intl" : "",
+		dma_has_cap(DMA_MEMCPY, dma->cap_mask) ? " memcpy" : "");
+
+	return 0;
+}

The selftest part and the features could just be separate files in the core dmaengine code, it doesn't really belong here.

Quoted 2 lines

I'll take a look. It could take a couple of iterations to get this right but I could certainly move my testing to another file for sharing.

I also missed the part about the selftest being called from probe rather than through debugfs.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +5 -0
+}
+#else
+static void hidma_debug_uninit(struct hidma_dev *dmadev)
+{
+}
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +5 -0
+static int hidma_debug_init(struct hidma_dev *dmadev)
+{
+	return 0;
+}
+#endif

You can remove the #ifdef here. The debugfs code already stubs out all debugfs_create_*() and turns it all into nops when it is disabled.

Quoted 2 lines

ok, I think I got compilation errors with the data structures but I'll take a look.

Ok. There may be cases where a structure definition is mistakenly placed in an #ifdef and should instead be taken out.

Quoted 14 lines
Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +7 -0
+	dma_cap_set(DMA_MEMCPY, dmadev->ddev.cap_mask);
+	/* Apply default dma_mask if needed */
+	if (!pdev->dev.dma_mask) {
+		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
+		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
+	}
+

remove the check, or use

I got caught on this problem before. Let me go back and revisit. It took my entire day to figure out that dma_mask pointer was not set.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
	if (WARN_ON(!pdev->dev.dma_mask))
		return -ENXIO;

The dma mask has to always be set by the platform code before probe() is called. If it is not set, you are not allowed to perform DMA.

I tested this on an ACPI platform BTW when I was working on the initial implementation.

I remember there was a bug in ACPI that it was not setting the dma mask pointer right. That should be fixed in newer kernels. If not, don't add another workaround for broken ACPI but instead fix the ACPI code.

Quoted 46 lines
Quoted 37 lines
Quoted 37 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +36 -0
+	rc = devm_request_irq(&pdev->dev, chirq, hidma_chirq_handler, 0,
+			      "qcom-hidma", &dmadev->lldev);
+	if (rc) {
+		dev_err(&pdev->dev, "chirq registration failed: %d\n", chirq);
+		goto chirq_request_failed;
+	}
+
+	dev_dbg(&pdev->dev, "initializing DMA channels\n");
+	INIT_LIST_HEAD(&dmadev->ddev.channels);
+	rc = hidma_chan_init(dmadev, 0);
+	if (rc) {
+		dev_err(&pdev->dev, "probe:channel init failed\n");
+		goto channel_init_failed;
+	}
+	dev_dbg(&pdev->dev, "HI-DMA engine driver starting self test\n");
+	rc = dmadev->self_test(dmadev);
+	if (rc) {
+		dev_err(&pdev->dev, "probe: self test failed: %d\n", rc);
+		goto self_test_failed;
+	}
+	dev_info(&pdev->dev, "probe: self test succeeded.\n");
+
+	dev_dbg(&pdev->dev, "calling dma_async_device_register\n");
+	rc = dma_async_device_register(&dmadev->ddev);
+	if (rc) {
+		dev_err(&pdev->dev,
+			"probe: failed to register slave DMA: %d\n", rc);
+		goto device_register_failed;
+	}
+	dev_dbg(&pdev->dev, "probe: dma_async_device_register done\n");
+
+	rc = hidma_debug_init(dmadev);
+	if (rc) {
+		dev_err(&pdev->dev,
+			"probe: failed to init debugfs: %d\n", rc);
+		goto debug_init_failed;
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +6 -0
+	}
+
+	dev_info(&pdev->dev, "HI-DMA engine driver registration complete\n");
+	platform_set_drvdata(pdev, dmadev);
+	HIDMA_RUNTIME_SET(dmadev);
+	return 0;

Remove the debug prints when you are done debugging.

Quoted 1 line

errors or the dev_infos?

I would remove both. Some might still be useful, but generally you only want to print messages when something happens that is not triggered by user action.

Quoted 9 lines
Quoted 5 lines

Also, if you waste CPU cycles for hundreds of milliseconds, it's unlikely that the function is so performance critical that it requires writel_relaxed().

Just use writel() here.

The issue is not writel_relaxed vs. writel. After I issue reset, I need wait for some time to confirm reset was done. I can use readl_polling instead of mdelay if we don't like mdelay.

I meant that both _relaxed() and mdelay() are probably wrong here.

readl_polling() would avoid the part with _relaxed(), but if that can still take more than a few microseconds, you should try to sleep inbetween rather than burn CPU cycles.

Quoted 37 lines
Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +24 -0
+/*
+ * The interrupt handler for HIDMA will try to consume as many pending
+ * EVRE from the event queue as possible. Each EVRE has an associated
+ * TRE that holds the user interface parameters. EVRE reports the
+ * result of the transaction. Hardware guarantees ordering between EVREs
+ * and TREs. We use last processed offset to figure out which TRE is
+ * associated with which EVRE. If two TREs are consumed by HW, the EVREs
+ * are in order in the event ring.
+ * This handler will do a one pass for consuming EVREs. Other EVREs may
+ * be delivered while we are working. It will try to consume incoming
+ * EVREs one more time and return.
+ * For unprocessed EVREs, hardware will trigger another interrupt until
+ * all the interrupt bits are cleared.
+ */
+static void hidma_ll_int_handler_internal(struct hidma_lldev *lldev)
+{
+	u32 status;
+	u32 enable;
+	u32 cause;
+	int repeat = 2;
+	unsigned long timeout;
+
+	status = readl_relaxed(lldev->evca + EVCA_IRQ_STAT_OFFSET);
+	enable = readl_relaxed(lldev->evca + EVCA_IRQ_EN_OFFSET);
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 2 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +2 -0
+	cause = status & enable;
+

Reading the status probably requires a readl() rather than readl_relaxed() to guarantee that the DMA data has arrived in memory by the time that the register data is seen by the CPU. If using readl_relaxed() here is a valid and required optimization, please add a comment to explain why it works and how much you gain.

I will add some description. This is a high speed peripheral. I don't like spreading barriers as candies inside the readl and writel unless I have to.

Quoted 8 lines

According to the barriers video, I watched on youtube this should be the rule for ordering.

"if you do two relaxed reads and check the results of the returned variables, ARM architecture guarantees that these two relaxed variables will get observed during the check."

this is called implied ordering or something of that sort.

My point was a bit different: while it is guaranteed that the result of the readl_relaxed() is observed in order, they do not guarantee that a DMA from device to memory that was started by the device before the readl_relaxed() has arrived in memory by the time that the readl_relaxed() result is visible to the CPU and it starts accessing the memory.

In other words, when the hardware sends you data followed by an interrupt to tell you the data is there, your interrupt handler can tell the driver that is waiting for this data that the DMA is complete while the data itself is still in flight, e.g. waiting for an IOMMU to fetch page table entries.

Quoted 7 lines
Quoted 5 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 3 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +3 -0
+	wmb();
+
+	mdelay(1);

Another workqueue? You should basically never call mdelay().

I'll use polled read instead.

Ok, but again make sure that you call msleep() or usleep_range() between the reads.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +5 -0
+static int hidma_ll_hw_start(void *llhndl)
+{
+	int rc = 0;
+	struct hidma_lldev *lldev = llhndl;
+	unsigned long irqflags;
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +5 -0
+
+	spin_lock_irqsave(&lldev->lock, irqflags);
+	writel_relaxed(lldev->tre_write_offset,
+			lldev->trca + TRCA_DOORBELL_OFFSET);
+	spin_unlock_irqrestore(&lldev->lock, irqflags);

How does this work? The writel_relaxed() won't synchronize with either the DMA data or the spinlock.

Quoted 3 lines

mutex and spinlocks have barriers inside. See the youtube video.

https://www.youtube.com/watch?v=6ORn6_35kKo

I'm pretty sure these barriers only make sense to the CPU, so the spinlock guarantees that the access to lldev->tre_write_offset is protected, but not the access to lldev->trca, because that write is posted on the bus and might not complete until after the unlock. There is no "dsb(st)" in here:

static inline void arch_spin_unlock(arch_spinlock_t *lock)

{
        unsigned long tmp;

        asm volatile(ARM64_LSE_ATOMIC_INSN(
        /* LL/SC */
        "       ldrh    %w1, %0\n"
        "       add     %w1, %w1, #1\n"
        "       stlrh   %w1, %0",
        /* LSE atomics */
        "       mov     %w1, #1\n"
        "       nop\n"
        "       staddlh %w1, %0")
        : "=Q" (lock->owner), "=&r" (tmp)
        :
        : "memory");
}
Quoted 10 lines
Quoted 6 lines

Also, your abstraction seem to go a little too far if the upper driver doesn't know what the lower driver calls its main device structure.

Or you can go further and just embed the struct hidma_lldev within the struct hidma_dev to save one?

That's how it was before. It got too complex and variables/spinlocks got intermixed. I borrowed the upper layer and it worked as it is. I rather keep all hardware stuff in another file and do not mix and match for safety.

Ok, then just use a forward declaration for the struct name so you can have a type-safe pointer but don't need to show the members.

Quoted 46 lines
Quoted 37 lines
Quoted 37 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +37 -0
+void hidma_ll_chstats(struct seq_file *s, void *llhndl, u32 tre_ch)
+{
+	struct hidma_lldev *lldev = llhndl;
+	struct hidma_tre *tre;
+	u32 length;
+	dma_addr_t src_start;
+	dma_addr_t dest_start;
+	u32 *tre_local;
+
+	if (unlikely(tre_ch >= lldev->nr_tres)) {
+		dev_err(lldev->dev, "invalid TRE number in chstats:%d",
+			tre_ch);
+		return;
+	}
+	tre = &lldev->trepool[tre_ch];
+	seq_printf(s, "------Channel %d -----\n", tre_ch);
+	seq_printf(s, "allocated=%d\n", atomic_read(&tre->allocated));
+	HIDMA_CHAN_SHOW(tre, queued);
+	seq_printf(s, "err_info=0x%x\n",
+		   lldev->tx_status_list[tre->chidx].err_info);
+	seq_printf(s, "err_code=0x%x\n",
+		   lldev->tx_status_list[tre->chidx].err_code);
+	HIDMA_CHAN_SHOW(tre, status);
+	HIDMA_CHAN_SHOW(tre, chidx);
+	HIDMA_CHAN_SHOW(tre, dma_sig);
+	seq_printf(s, "dev_name=%s\n", tre->dev_name);
+	seq_printf(s, "callback=%p\n", tre->callback);
+	seq_printf(s, "data=%p\n", tre->data);
+	HIDMA_CHAN_SHOW(tre, tre_index);
+
+	tre_local = &tre->tre_local[0];
+	src_start = tre_local[TRE_SRC_LOW_IDX];
+	src_start = ((u64)(tre_local[TRE_SRC_HI_IDX]) << 32) + src_start;
+	dest_start = tre_local[TRE_DEST_LOW_IDX];
+	dest_start += ((u64)(tre_local[TRE_DEST_HI_IDX]) << 32);
+	length = tre_local[TRE_LEN_IDX];
+
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma.txt new file +5 -0
+	seq_printf(s, "src=%pap\n", &src_start);
+	seq_printf(s, "dest=%pap\n", &dest_start);
+	seq_printf(s, "length=0x%x\n", length);
+}
+EXPORT_SYMBOL_GPL(hidma_ll_chstats);

Remove all the pointers here. I guess you can remove the entire debugfs file really ;-)

Quoted 2 lines

ok, I need some facility to print out stuff when problems happened. Would you rather use sysfs?

sysfs would be less appropriate, as that requires providing a stable ABI for user space. I think ftrace should provide what you need. Let me know if that doesn't work out.

Arnd

#9 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 10 lines · Arnd Bergmann
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Why ENODEV? Could you make this handle restarted system calls?

This is the self test code. It gets called from probe. If there is a problem with the device or system configuration, I don't want to enable this device. I can certainly return a different error code though. What's a good code?

I see. probe() is not restartable, so it cannot be -ERESTARTSYS.

Maybe better use wait_event_timeout and not handle the signals then. It will eventually time out if something goes wrong.

What about -EPROBE_DEFER? Isn't that "restartable"? Granted, it's only supposed to be used if the driver is dependent on another driver to probe, so I'm not sure it applies here. If the self-test fails, then it is possible that it could succeed later?

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
#7 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Timur Tabi
Quoted 12 lines · On Friday 30 October 2015 16:55:16 Timur Tabi wrote:
Quoted 9 lines · Sinan Kaya
Quoted 6 lines
    if (WARN_ON(!pdev->dev.dma_mask))
        return -ENXIO;

The dma mask has to always be set by the platform code before probe() is called. If it is not set, you are not allowed to perform DMA.

I tested this on an ACPI platform BTW when I was working on the initial implementation.

Quoted 6 lines

PowerPC sets the mask to 32 bits by default:

http://lxr.free-electrons.com/ident?i=arch_setup_pdev_archdata

Should we do something similar in ARM64? Today, we have to manually set the DMA mask in all drivers.

We set the dma mask from the 'dma-ranges' property of the parent device, but fall back to 32-bit because we did not manage to mandate this property in time for all arm64 machines to use.

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

#10 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Timur Tabi
Quoted 9 lines · On Friday 30 October 2015 17:36:45 Timur Tabi wrote:
Quoted 8 lines · Arnd Bergmann
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Why ENODEV? Could you make this handle restarted system calls?

This is the self test code. It gets called from probe. If there is a problem with the device or system configuration, I don't want to enable this device. I can certainly return a different error code though. What's a good code?

I see. probe() is not restartable, so it cannot be -ERESTARTSYS.

Quoted 7 lines
Quoted 2 lines

Maybe better use wait_event_timeout and not handle the signals then. It will eventually time out if something goes wrong.

What about -EPROBE_DEFER? Isn't that "restartable"? Granted, it's only supposed to be used if the driver is dependent on another driver to probe, so I'm not sure it applies here. If the self-test fails, then it is possible that it could succeed later?

No, this is different. The probe function can get called from all sorts of contexts (sys_init_module, device_create, deferred probing), and not all of them go back to user space when returning an error, so we cannot deliver a signal to the calling process this way.

Arnd

author
#11 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Arnd Bergmann
Quoted 3 lines · Arnd Bergmann

I missed that part. If the descriptor count is a hardware feature, just make that property mandatory. OTOH, if this is an optimization setting, better drop that property entirely.

I'm going to make this a module parameter instead and get rid of the constant. The reason, I have this default parameter today is that QEMU does not support passing device tree arguments for platform devices.

QEMU allows you to set memory and interrupt resources only for platform devices.

At least now, I can pass the argument via command line before starting QEMU.

I'll put checks that the value needs to come from either DTS/ACPI/command line.

Signature · 3 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#47 lore raw
In reply to Andy Shevchenko

Hi Andy,

Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Al Stone
Quoted 5 lines · Mark Rutland

On Fri, Oct 30, 2015 at 02:48:06PM -0400, Sinan Kaya wrote:

The CSRT is listed under "Want", not "Never" or "Don't Care", so Linaro have certainly not said that CSRT will not be supported. If anything, they have stated that the table should be supported.

Quoted 5 lines
Quoted 3 lines

"Want" means interesting, and probably useful, but no clear indication that anyone actually needs it. At one point, we thought we might use the CSRT for describing DMA, but it turns out we have not needed to.

Then you are going to have either 1 or 0 DMAC for slave devices, right?

I believe what Al means is that such hardware has not appeared (publicly) until this time and so such situation was theoretical and thus not covered by the Linaro wiki. Linaro had not prioritized CSRT because it didn't seem that the need to support it would arise soon.

Quoted 7 lines

The CSRT, unfortunately, the only way how to enumerate DMAC to be used by slave devices.
You may look into drivers/dma/acpi-dma.c for usage in Linux.

Yes, I know about _DSD, but I don't think it will provide soon any other official mechanisms to what we have now. Better to ask Rafael and Mika.

Thanks for the feedback. I agree that generally the plan is to use existing tables from x86 on arm64 when possible. Please see below.

Quoted 8 lines
Quoted 7 lines

However, let's make sure we're saying the same thing: the CSRT table is properly defined in the kernel include/acpi/actbl2.h file so one can read such a table and use it if they so choose. Nothing that we have done at Linaro in the arm64 part of the kernel relies on any of the content from the CSRT, nor does it preclude someone relying on that content. So, the CSRT is defined, and is usable, but is just not being used -- by Linaro -- at present.

Quoted 7 lines

This sounds clear.

Quoted 3 lines

If that needs to change, let me know; no one has asked us to use the CSRT for a DMA engine, and we have not been provided any hardware that requires it.

See above.

Here's, what I believe to be the summary:

1). QCOM are not implementing slave device support in their current HIDMA hardware, therefore the requirement for CSRT does not exist *at present* for this specific driver to be merged and the discussion in this sub-thread pertains only to a situation not affecting HIDMA.

2). A requirement upon the CSRT should be clarified in the various specifications. The SBBR[0] currently "recommends" CSRT but does not necessarily provide guidance about what kinds of system resources would be covered by that, and so there is a potential for this to be missed.

As one of the lead authors of certain ARM server specifications, I will contact those involved in such and ensure that this is addressed with a clarification in a future release.

Thanks for raising the concern,

Jon.

[0]
http://infocenter.arm.com/help/topic/com.arm.doc.den0044a/Server_Base_Boot_Requirements.pdf

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

author
#23 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Mark Rutland
Quoted 3 lines · Mark Rutland

The documentation above didn't state this was an 8-bit quantity, and you save nothing by doing this (all values in the binary format are padded to 4-byte alignment).

done.

Signature · 3 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
author
#27 lore raw
In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 4

Quoted 10 lines · On Thursday 29 October 2015 23:08:12 Sinan Kaya wrote:
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
new file mode 100644
index 0000000..81674ab
@@ -0,0 +1,42 @@
+Qualcomm Technologies HIDMA Management interface
+
+Required properties:
+- compatible: must contain "qcom,hidma_mgmt"

No underscores in the name please. Also try to be more specific, in case this device shows up in more than one SoC and they end up not being 100% compatible we want to be able to tell them apart.

ok

Quoted 14 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 16

Quoted 13 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +12 -0
+- reg: Address range for DMA device
+- interrupts: Should contain the one interrupt shared by all channels
+- nr-channels: Number of channels supported by this DMA controller.
+- max-write: Maximum write burst in bytes. A memcpy requested is
+  fragmented to multiples of this amount.
+- max-read: Maximum read burst in bytes. A memcpy request is
+  fragmented to multiples of this amount.
+- max-wxactions: Maximum write transactions to perform in a burst
+- max-rdactions: Maximum read transactions to perform in a burst
+- max-memset-limit: Maximum memset limit
+- ch-priority-#n: Priority of the channel
+- ch-weight-#n: Round robin weight of the channel
Quoted 2 lines

For the last two, you can just use a multi-cell property, using one cell per channel.

will look

Quoted 7 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 19

Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +3 -0
+
+#define MODULE_NAME			"hidma-mgmt"
+#define PREFIX				MODULE_NAME ": "

These can be removed, just use dev_info() etc for messages, to include a unique identifier.

got rid of them

Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +15 -0
+#define AUTOSUSPEND_TIMEOUT		2000
+
+#define HIDMA_RUNTIME_GET(dmadev)				\
+do {								\
+	atomic_inc(&(dmadev)->pm_counter);			\
+	TRC_PM(&(dmadev)->pdev->dev,				\
+		"%s:%d pm_runtime_get %d\n", __func__, __LINE__,\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_get_sync(&(dmadev)->pdev->dev);		\
+} while (0)
+
+#define HIDMA_RUNTIME_SET(dmadev)				\
+do {								\
+	atomic_dec(&(dmadev)->pm_counter);			\
+	TRC_PM(&(dmadev)->pdev->dev,				\
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 40

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+		"%s:%d pm_runtime_put_autosuspend:%d\n",	\
+		__func__, __LINE__,				\
+		atomic_read(&(dmadev)->pm_counter));		\
+	pm_runtime_mark_last_busy(&(dmadev)->pdev->dev);	\
+	pm_runtime_put_autosuspend(&(dmadev)->pdev->dev);	\
+} while (0)

Better use inline functions.

removed these

Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +9 -0
+struct qcom_hidma_mgmt_dev {
+	u8 max_wr_xactions;
+	u8 max_rd_xactions;
+	u8 max_memset_limit;
+	u16 max_write_request;
+	u16 max_read_request;
+	u16 nr_channels;
+	u32 chreset_timeout;
+	u32 sw_version;
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+	u8 *priority;
+	u8 *weight;
+
+	atomic_t	pm_counter;
+	/* Hardware device constants */
+	dma_addr_t dev_physaddr;

No need to store the physaddr, it's write-only here.

ok

Quoted 15 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 12 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +11 -0
+
+static unsigned int debug_pm;
+module_param(debug_pm, uint, 0644);
+MODULE_PARM_DESC(debug_pm,
+		 "debug runtime power management transitions (default: 0)");
+
+#define TRC_PM(...) do {			\
+		if (debug_pm)			\
+			dev_info(__VA_ARGS__);	\
+	} while (0)
+

Once you are done debugging the driver and have a final version, please remove these.

removed TRC_PM

Quoted 7 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+
+#define HIDMA_SHOW(dma, name) \
+		seq_printf(s, #name "=0x%x\n", dma->name)

Only used once, just remove.

ok

Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+#define HIDMA_READ_SHOW(dma, name, offset) \
+	do { \
+		u32 val; \
+		val = readl(dma->dev_virtaddr + offset); \
+		seq_printf(s, name "=0x%x\n", val); \
+	} while (0)

Inline function.

ok

Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +23 -0
+/**
+ * qcom_hidma_mgmt_info: display HIDMA device info
+ *
+ * Display the info for the current HIDMA device.
+ */
+static int qcom_hidma_mgmt_info(struct seq_file *s, void *unused)
+{
+	struct qcom_hidma_mgmt_dev *mgmtdev = s->private;
+	u32 val;
+	int i;
+
+	HIDMA_RUNTIME_GET(mgmtdev);
+	HIDMA_SHOW(mgmtdev, sw_version);
+
+	val = readl(mgmtdev->dev_virtaddr + CFG_OFFSET);
+	seq_printf(s, "ENABLE=%d\n", val & 0x1);
+
+	val = readl(mgmtdev->dev_virtaddr + CHRESET_TIMEOUUT_OFFSET);
+	seq_printf(s, "reset_timeout=%d\n", val & CHRESET_TIMEOUUT_MASK);
+
+	val = readl(mgmtdev->dev_virtaddr + MHICFG_OFFSET);
+	seq_printf(s, "nr_event_channel=%d\n",
+		(val >> NR_EV_CHANNEL_BIT_POS) & NR_CHANNEL_MASK);
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +5 -0
+	seq_printf(s, "nr_tr_channel=%d\n", (val & NR_CHANNEL_MASK));
+	seq_printf(s, "nr_virt_tr_channel=%d\n", mgmtdev->nr_channels);
+	seq_printf(s, "dev_virtaddr=%p\n", &mgmtdev->dev_virtaddr);
+	seq_printf(s, "dev_physaddr=%pap\n", &mgmtdev->dev_physaddr);
+	seq_printf(s, "dev_addrsize=%pap\n", &mgmtdev->dev_addrsize);

printing pointers is a security risk, just remove them if they are not essential here.

ok

Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +22 -0
+
+static int qcom_hidma_mgmt_err_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, qcom_hidma_mgmt_err, inode->i_private);
+}
+
+static const struct file_operations qcom_hidma_mgmt_err_fops = {
+	.open = qcom_hidma_mgmt_err_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
+static ssize_t qcom_hidma_mgmt_mhiderr_clr(struct file *file,
+	const char __user *user_buf, size_t count, loff_t *ppos)
+{
+	struct qcom_hidma_mgmt_dev *mgmtdev = file->f_inode->i_private;
+
+	HIDMA_RUNTIME_GET(mgmtdev);
+	writel(1, mgmtdev->dev_virtaddr + MHID_BUS_ERR_CLR_OFFSET);
+	HIDMA_RUNTIME_SET(mgmtdev);
+	return count;
Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +5 -0
+}
+
+static const struct file_operations qcom_hidma_mgmt_mhiderr_clrfops = {
+	.write = qcom_hidma_mgmt_mhiderr_clr,
+};

Is this really just a debugging interface? If anyone would do this for normal operation, it needs to be a proper API.

This will be used by the system admin to monitor/reset the execution state of the DMA channels. This will be the management interface. Debugfs is probably not the right choice. I originally had sysfs but than had some doubts. I'm open to suggestions.

Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +8 -0
+
+static void qcom_hidma_mgmt_debug_uninit(struct qcom_hidma_mgmt_dev *mgmtdev)
+{
+	debugfs_remove(mgmtdev->evt_ena);
+	debugfs_remove(mgmtdev->tre_errclr);
+	debugfs_remove(mgmtdev->msi_errclr);
+	debugfs_remove(mgmtdev->ode_errclr);
+	debugfs_remove(mgmtdev->ide_errclr);
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+	debugfs_remove(mgmtdev->evt_errclr);
+	debugfs_remove(mgmtdev->mhid_errclr);
+	debugfs_remove(mgmtdev->err);
+	debugfs_remove(mgmtdev->info);
+	debugfs_remove(mgmtdev->debugfs);
+}

I guess debugfs_remove_recursive() would do the job as well.

ok

Quoted 28 lines
Quoted 28 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +27 -0
+static int qcom_hidma_mgmt_debug_init(struct qcom_hidma_mgmt_dev *mgmtdev)
+{
+	int rc = 0;
+
+	mgmtdev->debugfs = debugfs_create_dir(dev_name(&mgmtdev->pdev->dev),
+						NULL);
+	if (!mgmtdev->debugfs) {
+		rc = -ENODEV;
+		return rc;
+	}
+
+	mgmtdev->info = debugfs_create_file("info", S_IRUGO,
+			mgmtdev->debugfs, mgmtdev, &qcom_hidma_mgmt_fops);
+	if (!mgmtdev->info) {
+		rc = -ENOMEM;
+		goto cleanup;
+	}
+
+	mgmtdev->err = debugfs_create_file("err", S_IRUGO,
+			mgmtdev->debugfs, mgmtdev,
+			&qcom_hidma_mgmt_err_fops);
+	if (!mgmtdev->err) {
+		rc = -ENOMEM;
+		goto cleanup;
+	}
+
+	mgmtdev->mhid_errclr = debugfs_create_file("mhiderrclr", S_IWUSR,
Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+			mgmtdev->debugfs, mgmtdev,
+			&qcom_hidma_mgmt_mhiderr_clrfops);
+	if (!mgmtdev->mhid_errclr) {
+		rc = -ENOMEM;
+		goto cleanup;
+	}

Maybe use a loop around an array here to avoid writing the same thing 10 times?

will do

Quoted 4 lines

Also, you could move the debugging code into a separate file and have a separate Kconfig symbol so users can disable this if they do not debug your driver but still want to use debugfs for other things.

I need these to be accessible all the time, maybe via sysfs or ioctl.

Quoted 7 lines
Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +5 -0
+static irqreturn_t qcom_hidma_mgmt_irq_handler(int irq, void *arg)
+{
+	/* TODO: handle irq here */
+	return IRQ_HANDLED;
+}
Quoted 10 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+	rc = devm_request_irq(&pdev->dev, irq, qcom_hidma_mgmt_irq_handler,
+		IRQF_SHARED, "qcom-hidmamgmt", mgmtdev);
+	if (rc) {
+		dev_err(&pdev->dev, "irq registration failed: %d\n", irq);
+		goto out;
+	}

If you create a shared handler, you must check whether there was an interrupt pending, otherwise you will lose interrupts for all other devices that share the same IRQ.

ok, I'll remove it for now. The interrupt handler is a to-do.

Quoted 14 lines

Better remove the handler completely here so you don't need to check it.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +7 -0
+
+	if (device_property_read_u16(&pdev->dev, "nr-channels",
+		&mgmtdev->nr_channels)) {
+		dev_err(&pdev->dev, "number of channels missing\n");
+		rc = -EINVAL;
+		goto out;
+	}

This should be a u32 name 'dma-channels' for consistency with the generic DMA binding.

ok

Quoted 2 lines

Also, try to avoid using u8 and u16 properties everywhere and just us u32 for consistency.

will do

Quoted 14 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 12 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +11 -0
+
+	for (i = 0; i < mgmtdev->nr_channels; i++) {
+		char name[30];
+
+		sprintf(name, "ch-priority-%d", i);
+		device_property_read_u8(&pdev->dev, name,
+			&mgmtdev->priority[i]);
+
+		sprintf(name, "ch-weight-%d", i);
+		device_property_read_u8(&pdev->dev, name,
+			&mgmtdev->weight[i]);

Per comment above, just read this as an array.

will look. While device tree syntax for arrays is easy, describing an array in DSM package looks really ugly. I tried to keep things simple. I'll spend some time on it.

Quoted 15 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 11 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+	dev_info(&pdev->dev,
+		"HI-DMA engine management driver registration complete\n");
+	platform_set_drvdata(pdev, mgmtdev);
+	HIDMA_RUNTIME_SET(mgmtdev);
+	return 0;
+out:
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_sync_suspend(&pdev->dev);
+	return rc;
+}

The rest of the probe function does not register any user interface aside from the debugging stuff. Can you explain in the changelog how you expect the driver to be used in a real system? Is there another driver coming?

I expect this driver to grow in functionality over time. Right now, it does the global init for the DMA. After that all channels execute on their own without depending on each other. Global init has to be done first before attempting to do any channel initialization.

There is also implied startup ordering requirements. I was doing this by using channel driver with the late binding to guarantee that.

As soon as I use module_platform_driver, the ordering gets reversed for some reason.

Quoted 32 lines
Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
+
+static const struct of_device_id qcom_hidma_mgmt_match[] = {
+	{ .compatible = "qcom,hidma_mgmt", },
+	{},

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+};
+MODULE_DEVICE_TABLE(of, qcom_hidma_mgmt_match);
+
+static struct platform_driver qcom_hidma_mgmt_driver = {
+	.probe = qcom_hidma_mgmt_probe,
+	.remove = qcom_hidma_mgmt_remove,
+	.driver = {
+		.name = MODULE_NAME,
+		.owner = THIS_MODULE,
+		.of_match_table = of_match_ptr(qcom_hidma_mgmt_match),

drop the .owner field and the of_match_ptr() macro to avoid warnings here.

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 11 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +11 -0
+static int __init qcom_hidma_mgmt_init(void)
+{
+	return platform_driver_register(&qcom_hidma_mgmt_driver);
+}
+device_initcall(qcom_hidma_mgmt_init);
+
+static void __exit qcom_hidma_mgmt_exit(void)
+{
+	platform_driver_unregister(&qcom_hidma_mgmt_driver);
+}
+module_exit(qcom_hidma_mgmt_exit);

module_platform_driver()

Quoted 2 lines

Arnd

thanks for the feedback.

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#28 lore raw
Quoted 11 lines · Sinan Kaya

I expect this driver to grow in functionality over time. Right now, it does the global init for the DMA. After that all channels execute on their own without depending on each other. Global init has to be done first before attempting to do any channel initialization.

There is also implied startup ordering requirements. I was doing this by using channel driver with the late binding to guarantee that.

As soon as I use module_platform_driver, the ordering gets reversed for some reason.

If you want to force two probe functions to be called in order, then that's what -EPROBE_DEFER is for.

Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.
#29 lore raw
In reply to Sinan Kaya
Quoted 11 lines · Sinan Kaya

I expect this driver to grow in functionality over time. Right now, it does the global init for the DMA. After that all channels execute on their own without depending on each other. Global init has to be done first before attempting to do any channel initialization.

There is also implied startup ordering requirements. I was doing this by using channel driver with the late binding to guarantee that.

As soon as I use module_platform_driver, the ordering gets reversed for some reason.

Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.
author
#50 lore raw
In reply to Mark Rutland
Quoted 18 lines · Mark Rutland
Quoted 17 lines · Sinan Kaya

The Qualcomm Technologies HIDMA device has been designed to support virtualization technology. The driver has been divided into two to follow the hardware design. The management driver is executed in hypervisor context and is the main managment for all channels provided by the device. The channel driver is exected in the guest OS context.

---
  .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  42 +
  drivers/dma/Kconfig                                |  11 +
  drivers/dma/Makefile                               |   1 +
  drivers/dma/qcom_hidma_mgmt.c                      | 868 +++++++++++++++++++++
  4 files changed, 922 insertions(+)

create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt create mode 100644 drivers/dma/qcom_hidma_mgmt.c

Quoted 13 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 4

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +4 -0
new file mode 100644
index 0000000..81674ab
@@ -0,0 +1,42 @@
+Qualcomm Technologies HIDMA Management interface
+
+Required properties:
+- compatible: must contain "qcom,hidma_mgmt"

s/_/-/ in property names and compatible strings.

done

Quoted 3 lines

Per your rationale for splitting the device nodes, surely the relationship between the two needs to be described?

I changed the commit message to make it more clear. I also added the same message to the device binding document for reference.

Quoted 5 lines

The GIC has a similar split, yet we use a single node, with the hypervisor portions being optional.

What if there were multiple instances?

The driver already supports multiple instances. It has been tested against 4 instances. I ended up having 4 management device entities managing 6 different channels each.

Quoted 10 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 11

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +7 -0
+- reg: Address range for DMA device
+- interrupts: Should contain the one interrupt shared by all channels
+- nr-channels: Number of channels supported by this DMA controller.
+- max-write: Maximum write burst in bytes. A memcpy requested is
+  fragmented to multiples of this amount.
+- max-read: Maximum read burst in bytes. A memcpy request is
+  fragmented to multiples of this amount.

Thse would be better named as max-read-burst-bytes and min-read-burst-bytes.

ok

Quoted 5 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 13

Quoted 3 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +2 -0
+- max-wxactions: Maximum write transactions to perform in a burst
+- max-rdactions: Maximum read transactions to perform in a burst

max-{write,read}-transactions

ok

Quoted 5 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 14

Quoted 2 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +1 -0
+- max-memset-limit: Maximum memset limit

I have no idea what this is meant to mean.

old stuff. no memset support anymore. will remove it.

Quoted 5 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt line 16

Quoted 2 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +2 -0
+- ch-priority-#n: Priority of the channel
+- ch-weight-#n: Round robin weight of the channel

These need better descriptions. They sound like configuration options.

ok.

Quoted 16 lines

[...]

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +6 -0
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_hidma_mgmt_acpi_ids[] = {
+	{"QCOM8060"},
+	{},
+};
+#endif

How do DMA engines work with ACPI?

How are client relationships defined?

THanks,
Mark.

Signature · 3 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
author
#48 lore raw
In reply to Jon Masters
Quoted 65 lines · Jon Masters

Hi Andy,

Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Al Stone
Quoted 5 lines · Mark Rutland

On Fri, Oct 30, 2015 at 02:48:06PM -0400, Sinan Kaya wrote:

The CSRT is listed under "Want", not "Never" or "Don't Care", so Linaro have certainly not said that CSRT will not be supported. If anything, they have stated that the table should be supported.

Quoted 5 lines
Quoted 3 lines

"Want" means interesting, and probably useful, but no clear indication that anyone actually needs it. At one point, we thought we might use the CSRT for describing DMA, but it turns out we have not needed to.

Then you are going to have either 1 or 0 DMAC for slave devices, right?

I believe what Al means is that such hardware has not appeared (publicly) until this time and so such situation was theoretical and thus not covered by the Linaro wiki. Linaro had not prioritized CSRT because it didn't seem that the need to support it would arise soon.

Quoted 7 lines

The CSRT, unfortunately, the only way how to enumerate DMAC to be used by slave devices.
You may look into drivers/dma/acpi-dma.c for usage in Linux.

Yes, I know about _DSD, but I don't think it will provide soon any other official mechanisms to what we have now. Better to ask Rafael and Mika.

Thanks for the feedback. I agree that generally the plan is to use existing tables from x86 on arm64 when possible. Please see below.

Quoted 8 lines
Quoted 7 lines

However, let's make sure we're saying the same thing: the CSRT table is properly defined in the kernel include/acpi/actbl2.h file so one can read such a table and use it if they so choose. Nothing that we have done at Linaro in the arm64 part of the kernel relies on any of the content from the CSRT, nor does it preclude someone relying on that content. So, the CSRT is defined, and is usable, but is just not being used -- by Linaro -- at present.

Quoted 7 lines

This sounds clear.

Quoted 3 lines

If that needs to change, let me know; no one has asked us to use the CSRT for a DMA engine, and we have not been provided any hardware that requires it.

See above.

Here's, what I believe to be the summary:

1). QCOM are not implementing slave device support in their current HIDMA hardware, therefore the requirement for CSRT does not exist *at present* for this specific driver to be merged and the discussion in this sub-thread pertains only to a situation not affecting HIDMA.

2). A requirement upon the CSRT should be clarified in the various specifications. The SBBR[0] currently "recommends" CSRT but does not necessarily provide guidance about what kinds of system resources would be covered by that, and so there is a potential for this to be missed.

As one of the lead authors of certain ARM server specifications, I will contact those involved in such and ensure that this is addressed with a clarification in a future release.

Quoted 7 lines

Thanks for raising the concern,

Jon.

[0]
http://infocenter.arm.com/help/topic/com.arm.doc.den0044a/Server_Base_Boot_Requirements.pdf

Apologies for creating confusion.

I tried using the dma-acpi.c implementation at the beginning. It didn't quite play well with what I was trying to do with HIDMA. Since the file header said Intel, I assumed it was an Intel specific implementation.

To confirm my suspicion, I looked at the Linaro wiki. I haven't seen CSRT in MUST tables.

I considered WANT meaning some spec work required similar to DMAR vs. IORT table.

Signature · 3 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
author
#12 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Arnd Bergmann
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Also, if you waste CPU cycles for hundreds of milliseconds, it's unlikely that the function is so performance critical that it requires writel_relaxed().

Just use writel() here.

ok, replaced writel_relaxed+wmb with writel.

Quoted 6 lines
Quoted 4 lines

The issue is not writel_relaxed vs. writel. After I issue reset, I need wait for some time to confirm reset was done. I can use readl_polling instead of mdelay if we don't like mdelay.

I meant that both _relaxed() and mdelay() are probably wrong here.

You are right about redundant writel_relaxed + wmb. They are effectively equal to writel.

However, after issuing the command; I still need to wait some amount of time until hardware acknowledges the commands like reset/enable/disable. These are relatively faster operations happening in microseconds. That's why, I have mdelay there.

I'll take a look at workqueues but it could turn out to be an overkill for few microseconds.

Quoted 49 lines

readl_polling() would avoid the part with _relaxed(), but if that can still take more than a few microseconds, you should try to sleep inbetween rather than burn CPU cycles.

Quoted 44 lines
Quoted 24 lines
Quoted 24 lines
drivers/dma/qcom_hidma_ll.c new file +24 -0
+/*
+ * The interrupt handler for HIDMA will try to consume as many pending
+ * EVRE from the event queue as possible. Each EVRE has an associated
+ * TRE that holds the user interface parameters. EVRE reports the
+ * result of the transaction. Hardware guarantees ordering between EVREs
+ * and TREs. We use last processed offset to figure out which TRE is
+ * associated with which EVRE. If two TREs are consumed by HW, the EVREs
+ * are in order in the event ring.
+ * This handler will do a one pass for consuming EVREs. Other EVREs may
+ * be delivered while we are working. It will try to consume incoming
+ * EVREs one more time and return.
+ * For unprocessed EVREs, hardware will trigger another interrupt until
+ * all the interrupt bits are cleared.
+ */
+static void hidma_ll_int_handler_internal(struct hidma_lldev *lldev)
+{
+	u32 status;
+	u32 enable;
+	u32 cause;
+	int repeat = 2;
+	unsigned long timeout;
+
+	status = readl_relaxed(lldev->evca + EVCA_IRQ_STAT_OFFSET);
+	enable = readl_relaxed(lldev->evca + EVCA_IRQ_EN_OFFSET);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	cause = status & enable;
+

Reading the status probably requires a readl() rather than readl_relaxed() to guarantee that the DMA data has arrived in memory by the time that the register data is seen by the CPU. If using readl_relaxed() here is a valid and required optimization, please add a comment to explain why it works and how much you gain.

I will add some description. This is a high speed peripheral. I don't like spreading barriers as candies inside the readl and writel unless I have to.

According to the barriers video, I watched on youtube this should be the rule for ordering.

"if you do two relaxed reads and check the results of the returned variables, ARM architecture guarantees that these two relaxed variables will get observed during the check."

Quoted 9 lines
Quoted 1 line

this is called implied ordering or something of that sort.

My point was a bit different: while it is guaranteed that the result of the readl_relaxed() is observed in order, they do not guarantee that a DMA from device to memory that was started by the device before the readl_relaxed() has arrived in memory by the time that the readl_relaxed() result is visible to the CPU and it starts accessing the memory.

I checked with the hardware designers. Hardware guarantees that by the time interrupt is observed, all data transactions in flight are delivered to their respective places and are visible to the CPU. I'll add a comment in the code about this.

Quoted 6 lines

In other words, when the hardware sends you data followed by an interrupt to tell you the data is there, your interrupt handler can tell the driver that is waiting for this data that the DMA is complete while the data itself is still in flight, e.g. waiting for an IOMMU to fetch page table entries.

There is HW guarantee for ordering.

On demand paging for IOMMU is only supported for PCIe via PRI (Page Request Interface) not for HIDMA. All other hardware instances work on pinned DMA addresses. I'll drop a note about this too to the code as well.

Quoted 36 lines
Quoted 7 lines
Quoted 5 lines

drivers/dma/qcom_hidma_ll.c line 435

Quoted 3 lines
drivers/dma/qcom_hidma_ll.c new file +3 -0
+	wmb();
+
+	mdelay(1);

Another workqueue? You should basically never call mdelay().

I'll use polled read instead.

Ok, but again make sure that you call msleep() or usleep_range() between the reads.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/dma/qcom_hidma_ll.c new file +5 -0
+static int hidma_ll_hw_start(void *llhndl)
+{
+	int rc = 0;
+	struct hidma_lldev *lldev = llhndl;
+	unsigned long irqflags;
Quoted 8 lines

drivers/dma/qcom_hidma_ll.c line 652

Quoted 5 lines
drivers/dma/qcom_hidma_ll.c new file +5 -0
+
+	spin_lock_irqsave(&lldev->lock, irqflags);
+	writel_relaxed(lldev->tre_write_offset,
+			lldev->trca + TRCA_DOORBELL_OFFSET);
+	spin_unlock_irqrestore(&lldev->lock, irqflags);

How does this work? The writel_relaxed() won't synchronize with either the DMA data or the spinlock.

Quoted 3 lines

mutex and spinlocks have barriers inside. See the youtube video.

https://www.youtube.com/watch?v=6ORn6_35kKo

I'm pretty sure these barriers only make sense to the CPU, so the spinlock guarantees that the access to lldev->tre_write_offset is protected, but not the access to lldev->trca, because that write is posted on the bus and might not complete until after the unlock. There is no "dsb(st)" in here:

static inline void arch_spin_unlock(arch_spinlock_t *lock)

Quoted 17 lines
{
         unsigned long tmp;

         asm volatile(ARM64_LSE_ATOMIC_INSN(
         /* LL/SC */
         "       ldrh    %w1, %0\n"
         "       add     %w1, %w1, #1\n"
         "       stlrh   %w1, %0",
         /* LSE atomics */
         "       mov     %w1, #1\n"
         "       nop\n"
         "       staddlh %w1, %0")
         : "=Q" (lock->owner), "=&r" (tmp)
         :
         : "memory");
}

ok. I'm changing it to readl. Thanks for the insight.

Quoted 69 lines
Quoted 10 lines
Quoted 6 lines

Also, your abstraction seem to go a little too far if the upper driver doesn't know what the lower driver calls its main device structure.

Or you can go further and just embed the struct hidma_lldev within the struct hidma_dev to save one?

That's how it was before. It got too complex and variables/spinlocks got intermixed. I borrowed the upper layer and it worked as it is. I rather keep all hardware stuff in another file and do not mix and match for safety.

Ok, then just use a forward declaration for the struct name so you can have a type-safe pointer but don't need to show the members.

Quoted 46 lines
Quoted 37 lines
Quoted 37 lines
drivers/dma/qcom_hidma_ll.c new file +37 -0
+void hidma_ll_chstats(struct seq_file *s, void *llhndl, u32 tre_ch)
+{
+	struct hidma_lldev *lldev = llhndl;
+	struct hidma_tre *tre;
+	u32 length;
+	dma_addr_t src_start;
+	dma_addr_t dest_start;
+	u32 *tre_local;
+
+	if (unlikely(tre_ch >= lldev->nr_tres)) {
+		dev_err(lldev->dev, "invalid TRE number in chstats:%d",
+			tre_ch);
+		return;
+	}
+	tre = &lldev->trepool[tre_ch];
+	seq_printf(s, "------Channel %d -----\n", tre_ch);
+	seq_printf(s, "allocated=%d\n", atomic_read(&tre->allocated));
+	HIDMA_CHAN_SHOW(tre, queued);
+	seq_printf(s, "err_info=0x%x\n",
+		   lldev->tx_status_list[tre->chidx].err_info);
+	seq_printf(s, "err_code=0x%x\n",
+		   lldev->tx_status_list[tre->chidx].err_code);
+	HIDMA_CHAN_SHOW(tre, status);
+	HIDMA_CHAN_SHOW(tre, chidx);
+	HIDMA_CHAN_SHOW(tre, dma_sig);
+	seq_printf(s, "dev_name=%s\n", tre->dev_name);
+	seq_printf(s, "callback=%p\n", tre->callback);
+	seq_printf(s, "data=%p\n", tre->data);
+	HIDMA_CHAN_SHOW(tre, tre_index);
+
+	tre_local = &tre->tre_local[0];
+	src_start = tre_local[TRE_SRC_LOW_IDX];
+	src_start = ((u64)(tre_local[TRE_SRC_HI_IDX]) << 32) + src_start;
+	dest_start = tre_local[TRE_DEST_LOW_IDX];
+	dest_start += ((u64)(tre_local[TRE_DEST_HI_IDX]) << 32);
+	length = tre_local[TRE_LEN_IDX];
+
Quoted 8 lines

drivers/dma/qcom_hidma_ll.c line 1106

Quoted 5 lines
drivers/dma/qcom_hidma_ll.c new file +5 -0
+	seq_printf(s, "src=%pap\n", &src_start);
+	seq_printf(s, "dest=%pap\n", &dest_start);
+	seq_printf(s, "length=0x%x\n", length);
+}
+EXPORT_SYMBOL_GPL(hidma_ll_chstats);

Remove all the pointers here. I guess you can remove the entire debugfs file really ;-)

Quoted 2 lines

ok, I need some facility to print out stuff when problems happened. Would you rather use sysfs?

sysfs would be less appropriate, as that requires providing a stable ABI for user space. I think ftrace should provide what you need. Let me know if that doesn't work out.

Arnd

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 4 lines · Sinan Kaya

However, after issuing the command; I still need to wait some amount of time until hardware acknowledges the commands like reset/enable/disable. These are relatively faster operations happening in microseconds. That's why, I have mdelay there.

Can you use readl_poll_timeout()?

Signature · 7 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#14 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 8 lines · Timur Tabi
Quoted 4 lines · Sinan Kaya

However, after issuing the command; I still need to wait some amount of time until hardware acknowledges the commands like reset/enable/disable. These are relatively faster operations happening in microseconds. That's why, I have mdelay there.

Can you use readl_poll_timeout()?

Yes, I'm changing them to readl_poll_timeout after looking at the workqueue vs. expected delay requirements. I decided to stick with polled read.

First, I missed the point here that mdelay is discouraged.
https://www.kernel.org/doc/Documentation/timers/timers-howto.txt

According to same document, msleep can sleep up to 20ms which is not what I want.

This code is trying to sleep 10ms maximum and treating longer durations as failures.

readl_poll_timeout calls usleep_range that seems to satisfy what I'm looking for.

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#15 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Sinan Kaya
Quoted 9 lines · On Sunday 01 November 2015 13:50:53 Sinan Kaya wrote:
Quoted 6 lines
Quoted 4 lines

The issue is not writel_relaxed vs. writel. After I issue reset, I need wait for some time to confirm reset was done. I can use readl_polling instead of mdelay if we don't like mdelay.

I meant that both _relaxed() and mdelay() are probably wrong here.

You are right about redundant writel_relaxed + wmb. They are effectively equal to writel.

Actually, writel() is wmb()+writel_relaxed(), not the other way round:

When sending a command to a device that can start a DMA transfer, the barrier is required to ensure that the DMA happens after previously written data has gone from the CPU write buffers into the memory that is used as the source for the transfer.

A barrier after the writel() has no effect, as MMIO writes are posted on the bus.

Quoted 7 lines

However, after issuing the command; I still need to wait some amount of time until hardware acknowledges the commands like reset/enable/disable. These are relatively faster operations happening in microseconds. That's why, I have mdelay there.

I'll take a look at workqueues but it could turn out to be an overkill for few microseconds.

Most devices are able to provide an interrupt for long-running commands. Are you sure that yours is unable to do this? If so, is this a design mistake or an implementation bug?

Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines

Reading the status probably requires a readl() rather than readl_relaxed() to guarantee that the DMA data has arrived in memory by the time that the register data is seen by the CPU. If using readl_relaxed() here is a valid and required optimization, please add a comment to explain why it works and how much you gain.

I will add some description. This is a high speed peripheral. I don't like spreading barriers as candies inside the readl and writel unless I have to.

According to the barriers video, I watched on youtube this should be the rule for ordering.

"if you do two relaxed reads and check the results of the returned variables, ARM architecture guarantees that these two relaxed variables will get observed during the check."

Quoted 9 lines
Quoted 1 line

this is called implied ordering or something of that sort.

My point was a bit different: while it is guaranteed that the result of the readl_relaxed() is observed in order, they do not guarantee that a DMA from device to memory that was started by the device before the readl_relaxed() has arrived in memory by the time that the readl_relaxed() result is visible to the CPU and it starts accessing the memory.

Quoted 4 lines

I checked with the hardware designers. Hardware guarantees that by the time interrupt is observed, all data transactions in flight are delivered to their respective places and are visible to the CPU. I'll add a comment in the code about this.

I'm curious about this. Does that mean the device is not meant for high-performance transfers and just synchronizes the bus before triggering the interrupt?

Quoted 11 lines
Quoted 6 lines

In other words, when the hardware sends you data followed by an interrupt to tell you the data is there, your interrupt handler can tell the driver that is waiting for this data that the DMA is complete while the data itself is still in flight, e.g. waiting for an IOMMU to fetch page table entries.

There is HW guarantee for ordering.

On demand paging for IOMMU is only supported for PCIe via PRI (Page Request Interface) not for HIDMA. All other hardware instances work on pinned DMA addresses. I'll drop a note about this too to the code as well.

I wasn't talking about paging, just fetching the IOTLB from the preloaded page tables in RAM. This can takes several uncached memory accesses, so it would generally be slow.

Arnd

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

author
#16 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · On Sunday 01 November 2015 13:50:53 Sinan Kaya wrote:
Quoted 5 lines
Quoted 4 lines

The issue is not writel_relaxed vs. writel. After I issue reset, I need wait for some time to confirm reset was done. I can use readl_polling instead of mdelay if we don't like mdelay.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I meant that both _relaxed() and mdelay() are probably wrong here.

You are right about redundant writel_relaxed + wmb. They are effectively equal to writel.

Actually, writel() is wmb()+writel_relaxed(), not the other way round:

I agree. Semantics... but important one since order matters this time.

Quoted 6 lines

When sending a command to a device that can start a DMA transfer, the barrier is required to ensure that the DMA happens after previously written data has gone from the CPU write buffers into the memory that is used as the source for the transfer.

Agreed.

Quoted 2 lines

A barrier after the writel() has no effect, as MMIO writes are posted on the bus.

I had two use cases in the original code. We are talking about start routine here. I was giving reference to enable/reset/disable uses above.

1. Start routine
--------------
spin_lock
writel_relaxed
spin_unlock

and

2. enable/reset/disable
--------------
writel_relaxed
wmb

I changed writel_relaxed to writel now in start routine and submitted the second version of the patchset yesterday. I hope you have received it. I was relying on the spinlocks before.

Quoted 6 lines
Quoted 6 lines

However, after issuing the command; I still need to wait some amount of time until hardware acknowledges the commands like reset/enable/disable. These are relatively faster operations happening in microseconds. That's why, I have mdelay there.

Quoted 6 lines
Quoted 2 lines

I'll take a look at workqueues but it could turn out to be an overkill for few microseconds.

Most devices are able to provide an interrupt for long-running commands. Are you sure that yours is unable to do this? If so, is this a design mistake or an implementation bug?

I think I was not clear on how long these command take. These command are really fast and get acknowledged at status register in few microseconds. That's why I choose polling.

I was waiting up to 10ms before and manually sleeping 1 milliseconds in between each using mdelay. I followed your suggestion and got rid of the mdelay. Then, I used polled read command which calls the usleep_range function as you suggested.

Hardware supports error interrupts but this is a SW design philosophy discussion. Why would you want to trigger an interrupt for few microseconds delay that only happens during the first time init from probe?

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 11 lines
Quoted 6 lines

Reading the status probably requires a readl() rather than readl_relaxed() to guarantee that the DMA data has arrived in memory by the time that the register data is seen by the CPU. If using readl_relaxed() here is a valid and required optimization, please add a comment to explain why it works and how much you gain.

I will add some description. This is a high speed peripheral. I don't like spreading barriers as candies inside the readl and writel unless I have to.

Quoted 8 lines

According to the barriers video, I watched on youtube this should be the rule for ordering.

"if you do two relaxed reads and check the results of the returned variables, ARM architecture guarantees that these two relaxed variables will get observed during the check."

this is called implied ordering or something of that sort.

My point was a bit different: while it is guaranteed that the result of the readl_relaxed() is observed in order, they do not guarantee that a DMA from device to memory that was started by the device before the readl_relaxed() has arrived in memory by the time that the readl_relaxed() result is visible to the CPU and it starts accessing the memory.

Quoted 8 lines
Quoted 4 lines

I checked with the hardware designers. Hardware guarantees that by the time interrupt is observed, all data transactions in flight are delivered to their respective places and are visible to the CPU. I'll add a comment in the code about this.

I'm curious about this. Does that mean the device is not meant for high-performance transfers and just synchronizes the bus before triggering the interrupt?

HIDMA meaning, as you probably guessed, is high performance DMA. We had several name iterations in the company and this was the one that sticked.

I'm a SW person. I don't have the expertise to go deeper into HW design.
I'm following the programming document. It says coherency and guaranteed interrupt ordering. High performance can mean how fast you can move data from one location to the other one vs. how fast you can queue up multiple requests and get acks in response.

I followed a simple design here. HW can take multiple requests simultaneously and give me an ack when it is finished with interrupt.

If there are requests in flight, other requests will get queued up in SW and will not be serviced until the previous requests get acknowledged. Then, as soon as HW stops processing; I queue a bunch of other requests and kick start it. Current SW design does not allow simultaneous SW queuing vs. HW processing. I can try this on the next iteration. This implementation, IMO, is good enough now and has been working reliably for a long time (since 2014).

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

In other words, when the hardware sends you data followed by an interrupt to tell you the data is there, your interrupt handler can tell the driver that is waiting for this data that the DMA is complete while the data itself is still in flight, e.g. waiting for an IOMMU to fetch page table entries.

There is HW guarantee for ordering.

Quoted 8 lines
Quoted 3 lines

On demand paging for IOMMU is only supported for PCIe via PRI (Page Request Interface) not for HIDMA. All other hardware instances work on pinned DMA addresses. I'll drop a note about this too to the code as well.

I wasn't talking about paging, just fetching the IOTLB from the preloaded page tables in RAM. This can takes several uncached memory accesses, so it would generally be slow.

I see.

HIDMA is not aware of IOMMU presence since it follows the DMA API. All IOMMU latency will be built into the data movement time. By the time interrupt happens, IOMMU lookups + data movement has already taken place.

Quoted 3 lines

Arnd

Signature · 3 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#17 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 16 lines · On Monday 02 November 2015 14:21:37 Sinan Kaya wrote:
Quoted 3 lines · Arnd Bergmann

On Sunday 01 November 2015 13:50:53 Sinan Kaya wrote:
A barrier after the writel() has no effect, as MMIO writes are posted on the bus.

I had two use cases in the original code. We are talking about start routine here. I was giving reference to enable/reset/disable uses above.

1. Start routine
--------------
spin_lock
writel_relaxed
spin_unlock

and

Quoted 8 lines

2. enable/reset/disable
--------------
writel_relaxed
wmb

I changed writel_relaxed to writel now in start routine and submitted the second version of the patchset yesterday. I hope you have received it. I was relying on the spinlocks before.

Ok

Quoted 17 lines
Quoted 6 lines
Quoted 6 lines

However, after issuing the command; I still need to wait some amount of time until hardware acknowledges the commands like reset/enable/disable. These are relatively faster operations happening in microseconds. That's why, I have mdelay there.

Quoted 6 lines
Quoted 2 lines

I'll take a look at workqueues but it could turn out to be an overkill for few microseconds.

Most devices are able to provide an interrupt for long-running commands. Are you sure that yours is unable to do this? If so, is this a design mistake or an implementation bug?

I think I was not clear on how long these command take. These command are really fast and get acknowledged at status register in few microseconds. That's why I choose polling.

Quoted 8 lines

I was waiting up to 10ms before and manually sleeping 1 milliseconds in between each using mdelay. I followed your suggestion and got rid of the mdelay. Then, I used polled read command which calls the usleep_range function as you suggested.

Hardware supports error interrupts but this is a SW design philosophy discussion. Why would you want to trigger an interrupt for few microseconds delay that only happens during the first time init from probe?

If you get called in sleeping context and can use usleep_range() for delaying, that is fine, but in effect that just means you generate another interrupt from the timer that is not synchronized to your device, and hide the complexity behind the usleep_range() function call.

My first choice would have been to use a struct completion to wait for the next interrupt here, which has similar complexity on the source code side, but never waits longer than necessary. If the hrtimer based method works for you, there is no need to change that.

Quoted 21 lines
Quoted 8 lines
Quoted 4 lines

I checked with the hardware designers. Hardware guarantees that by the time interrupt is observed, all data transactions in flight are delivered to their respective places and are visible to the CPU. I'll add a comment in the code about this.

I'm curious about this. Does that mean the device is not meant for high-performance transfers and just synchronizes the bus before triggering the interrupt?

HIDMA meaning, as you probably guessed, is high performance DMA. We had several name iterations in the company and this was the one that sticked.

I'm a SW person. I don't have the expertise to go deeper into HW design. I'm following the programming document. It says coherency and guaranteed interrupt ordering. High performance can mean how fast you can move data from one location to the other one vs. how fast you can queue up multiple requests and get acks in response.

I followed a simple design here. HW can take multiple requests simultaneously and give me an ack when it is finished with interrupt.

Quoted 7 lines

If there are requests in flight, other requests will get queued up in SW and will not be serviced until the previous requests get acknowledged. Then, as soon as HW stops processing; I queue a bunch of other requests and kick start it. Current SW design does not allow simultaneous SW queuing vs. HW processing. I can try this on the next iteration. This implementation, IMO, is good enough now and has been working reliably for a long time (since 2014).

Are you using message signaled interrupts then? Typically MSI guarantees ordering against DMA, but level or edge triggered interrupts by definition cannot (at least on PCI, but most other buses are the same way), because the DMA master has no insight into when a DMA is actually complete.

If you use MSI, please add a comment to the readl_relaxed() that it is safe because of that, otherwise the next person who tries to debug a problem with your driver has to look into this.

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

In other words, when the hardware sends you data followed by an interrupt to tell you the data is there, your interrupt handler can tell the driver that is waiting for this data that the DMA is complete while the data itself is still in flight, e.g. waiting for an IOMMU to fetch page table entries.

There is HW guarantee for ordering.

Quoted 8 lines
Quoted 3 lines

On demand paging for IOMMU is only supported for PCIe via PRI (Page Request Interface) not for HIDMA. All other hardware instances work on pinned DMA addresses. I'll drop a note about this too to the code as well.

I wasn't talking about paging, just fetching the IOTLB from the preloaded page tables in RAM. This can takes several uncached memory accesses, so it would generally be slow.

Quoted 5 lines

I see.

HIDMA is not aware of IOMMU presence since it follows the DMA API. All IOMMU latency will be built into the data movement time. By the time interrupt happens, IOMMU lookups + data movement has already taken place.

Ok.

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

#30 lore raw
In reply to Sinan Kaya
Quoted 34 lines · On Saturday 31 October 2015 02:51:46 Sinan Kaya wrote:
Quoted 24 lines · Arnd Bergmann
Quoted 23 lines · On Thursday 29 October 2015 23:08:12 Sinan Kaya wrote:
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +22 -0
+
+static int qcom_hidma_mgmt_err_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, qcom_hidma_mgmt_err, inode->i_private);
+}
+
+static const struct file_operations qcom_hidma_mgmt_err_fops = {
+	.open = qcom_hidma_mgmt_err_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
+static ssize_t qcom_hidma_mgmt_mhiderr_clr(struct file *file,
+	const char __user *user_buf, size_t count, loff_t *ppos)
+{
+	struct qcom_hidma_mgmt_dev *mgmtdev = file->f_inode->i_private;
+
+	HIDMA_RUNTIME_GET(mgmtdev);
+	writel(1, mgmtdev->dev_virtaddr + MHID_BUS_ERR_CLR_OFFSET);
+	HIDMA_RUNTIME_SET(mgmtdev);
+	return count;
Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +5 -0
+}
+
+static const struct file_operations qcom_hidma_mgmt_mhiderr_clrfops = {
+	.write = qcom_hidma_mgmt_mhiderr_clr,
+};

Is this really just a debugging interface? If anyone would do this for normal operation, it needs to be a proper API.

Quoted 4 lines

This will be used by the system admin to monitor/reset the execution state of the DMA channels. This will be the management interface. Debugfs is probably not the right choice. I originally had sysfs but than had some doubts. I'm open to suggestions.

User interface design is unfortunately always hard, and I don't have an obvious answer for you.

Using debugfs by definition means that you don't expect users to rely on ABI stability, so they should not write any automated scripts against the contents of the files.

With sysfs, the opposite is true: you need to maintain compatibility for as long as anyone might rely on the current interface, and it needs to be reviewed properly and documented in Documentation/ABI/.

Other options are to use ioctl(), netlink or your own virtual file system, but each of them has the same ABI requirements as sysfs.

Regardless of what you pick, you also need to consider how other drivers would use the same interface: If someone else has hardware that does the same thing, we want to be able to use the same tools to access it, so you should avoid having any hardware specific data in it and keep it as generic and extensible as possible. In this particular case, that probably means you should implement the user interfaces in the dmaengine core driver, and let the specific DMA driver provide callback function pointers along with the normal ones to fill that data.

Quoted 20 lines
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +6 -0
+	dev_info(&pdev->dev,
+		"HI-DMA engine management driver registration complete\n");
+	platform_set_drvdata(pdev, mgmtdev);
+	HIDMA_RUNTIME_SET(mgmtdev);
+	return 0;
+out:
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +4 -0
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_sync_suspend(&pdev->dev);
+	return rc;
+}

The rest of the probe function does not register any user interface aside from the debugging stuff. Can you explain in the changelog how you expect the driver to be used in a real system? Is there another driver coming?

I expect this driver to grow in functionality over time. Right now, it does the global init for the DMA. After that all channels execute on their own without depending on each other. Global init has to be done first before attempting to do any channel initialization.

Quoted 5 lines

There is also implied startup ordering requirements. I was doing this by using channel driver with the late binding to guarantee that.

As soon as I use module_platform_driver, the ordering gets reversed for some reason.

For the ordering requirements, it's probably best to export a symbol with the entry point and let the normal driver call into that. Using separate initcall levels is not something you should do in a normal device driver like this.

What is the relation between the device nodes for the two kinds of devices? Does it make sense to model the other one as a child device of this one? That way you would trivially do the ordering by not marking this one as 'compatible="simple-bus"' and triggering the registration of the child from the parent probe function.

Arnd

author
#31 lore raw
Quoted 54 lines · Arnd Bergmann
Quoted 34 lines · On Saturday 31 October 2015 02:51:46 Sinan Kaya wrote:
Quoted 24 lines · Arnd Bergmann
Quoted 23 lines · On Thursday 29 October 2015 23:08:12 Sinan Kaya wrote:
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +22 -0
+
+static int qcom_hidma_mgmt_err_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, qcom_hidma_mgmt_err, inode->i_private);
+}
+
+static const struct file_operations qcom_hidma_mgmt_err_fops = {
+	.open = qcom_hidma_mgmt_err_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
+static ssize_t qcom_hidma_mgmt_mhiderr_clr(struct file *file,
+	const char __user *user_buf, size_t count, loff_t *ppos)
+{
+	struct qcom_hidma_mgmt_dev *mgmtdev = file->f_inode->i_private;
+
+	HIDMA_RUNTIME_GET(mgmtdev);
+	writel(1, mgmtdev->dev_virtaddr + MHID_BUS_ERR_CLR_OFFSET);
+	HIDMA_RUNTIME_SET(mgmtdev);
+	return count;
Quoted 9 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +5 -0
+}
+
+static const struct file_operations qcom_hidma_mgmt_mhiderr_clrfops = {
+	.write = qcom_hidma_mgmt_mhiderr_clr,
+};

Is this really just a debugging interface? If anyone would do this for normal operation, it needs to be a proper API.

Quoted 4 lines

This will be used by the system admin to monitor/reset the execution state of the DMA channels. This will be the management interface. Debugfs is probably not the right choice. I originally had sysfs but than had some doubts. I'm open to suggestions.

User interface design is unfortunately always hard, and I don't have an obvious answer for you.

Using debugfs by definition means that you don't expect users to rely on ABI stability, so they should not write any automated scripts against the contents of the files.

With sysfs, the opposite is true: you need to maintain compatibility for as long as anyone might rely on the current interface, and it needs to be reviewed properly and documented in Documentation/ABI/.

Other options are to use ioctl(), netlink or your own virtual file system, but each of them has the same ABI requirements as sysfs.

Quoted 10 lines

Regardless of what you pick, you also need to consider how other drivers would use the same interface: If someone else has hardware that does the same thing, we want to be able to use the same tools to access it, so you should avoid having any hardware specific data in it and keep it as generic and extensible as possible. In this particular case, that probably means you should implement the user interfaces in the dmaengine core driver, and let the specific DMA driver provide callback function pointers along with the normal ones to fill that data.

Thanks, I'll think about this. I'm inclined towards sysfs.

Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +6 -0
+	dev_info(&pdev->dev,
+		"HI-DMA engine management driver registration complete\n");
+	platform_set_drvdata(pdev, mgmtdev);
+	HIDMA_RUNTIME_SET(mgmtdev);
+	return 0;
+out:
Quoted 8 lines

Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt

Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +4 -0
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_sync_suspend(&pdev->dev);
+	return rc;
+}

The rest of the probe function does not register any user interface aside from the debugging stuff. Can you explain in the changelog how you expect the driver to be used in a real system? Is there another driver coming?

I expect this driver to grow in functionality over time. Right now, it does the global init for the DMA. After that all channels execute on their own without depending on each other. Global init has to be done first before attempting to do any channel initialization.

There is also implied startup ordering requirements. I was doing this by using channel driver with the late binding to guarantee that.

Quoted 8 lines
Quoted 2 lines

As soon as I use module_platform_driver, the ordering gets reversed for some reason.

For the ordering requirements, it's probably best to export a symbol with the entry point and let the normal driver call into that. Using separate initcall levels is not something you should do in a normal device driver like this.

I figured this out. If the channel driver starts before the management driver; then channel reset fails. I'm handling this in the channel driver and am returning -EPROBE_DEFER. After that, management driver gets its chance to work. Then, the channel driver again. This change is in the v2 series.

Quoted 6 lines

What is the relation between the device nodes for the two kinds of devices? Does it make sense to model the other one as a child device of this one? That way you would trivially do the ordering by not marking this one as 'compatible="simple-bus"' and triggering the registration of the child from the parent probe function.

The required order is management driver first, channel drivers next. If the order is reversed, channel init fails. I handle this with deferred probing.

I tried to keep loose binding between the management driver due to QEMU.

QEMU auto-generates the devicetree entries. The guest machine just sees one devicetree object for the DMA channel but guest machine device-tree kernel does not have any management driver entity.

This requires DMA channel driver to work independently in the guest machine without dependencies.

Quoted 2 lines

Arnd

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#18 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

Are you using message signaled interrupts then?
Typically MSI guarantees
ordering against DMA, but level or edge triggered interrupts by definition cannot (at least on PCI, but most other buses are the same way), because the DMA master has no insight into when a DMA is actually complete.

If you use MSI, please add a comment to the readl_relaxed() that it is safe because of that, otherwise the next person who tries to debug a problem with your driver has to look into this.

No, using regular GIC SPI interrupts at this moment. I know that HW doesn't use any of the typical AHB/AXI ARM buses.

I'm familiar with how PCI endpoints works. While the first read in a typical PCI endpoint ISR flushes all outstanding requests traditionally to the destination, this concept does not apply here for this HW.

Signature · 3 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#19 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 11 lines · On Tuesday 03 November 2015 00:29:07 Sinan Kaya wrote:
Quoted 9 lines · Arnd Bergmann

Are you using message signaled interrupts then?
Typically MSI guarantees
ordering against DMA, but level or edge triggered interrupts by definition cannot (at least on PCI, but most other buses are the same way), because the DMA master has no insight into when a DMA is actually complete.

If you use MSI, please add a comment to the readl_relaxed() that it is safe because of that, otherwise the next person who tries to debug a problem with your driver has to look into this.

Quoted 7 lines

No, using regular GIC SPI interrupts at this moment. I know that HW doesn't use any of the typical AHB/AXI ARM buses.

I'm familiar with how PCI endpoints works. While the first read in a typical PCI endpoint ISR flushes all outstanding requests traditionally to the destination, this concept does not apply here for this HW.

Ok, got it.

Best add an explanation like the above in the interrupt handler, to prevent this from accidentally getting 'cleaned up' to use readl(), or copied into a driver that uses PCI ordering rules where it is actually wrong.

I think it should be done like this:

- anything that is not performance critical, use normal readl/writel
- in the fast path, add a comment to each readl_relaxed()/writel_relaxed() that is safe in this driver but that would not be safe in a PCI device
- For the ones that would be safe on PCI as weel, use readl_relaxed()/writel_relaxed() without a comment on each one, but clarify somewhere that these are all intentional.

Arnd

#32 lore raw
In reply to Sinan Kaya
Quoted 33 lines · On Monday 02 November 2015 23:45:17 Sinan Kaya wrote:
Quoted 22 lines · Arnd Bergmann
Quoted 6 lines · On Saturday 31 October 2015 02:51:46 Sinan Kaya wrote:
Quoted 1 line · Arnd Bergmann

On Thursday 29 October 2015 23:08:12 Sinan Kaya wrote:

This will be used by the system admin to monitor/reset the execution state of the DMA channels. This will be the management interface. Debugfs is probably not the right choice. I originally had sysfs but than had some doubts. I'm open to suggestions.

User interface design is unfortunately always hard, and I don't have an obvious answer for you.

Using debugfs by definition means that you don't expect users to rely on ABI stability, so they should not write any automated scripts against the contents of the files.

With sysfs, the opposite is true: you need to maintain compatibility for as long as anyone might rely on the current interface, and it needs to be reviewed properly and documented in Documentation/ABI/.

Other options are to use ioctl(), netlink or your own virtual file system, but each of them has the same ABI requirements as sysfs.

Quoted 10 lines

Regardless of what you pick, you also need to consider how other drivers would use the same interface: If someone else has hardware that does the same thing, we want to be able to use the same tools to access it, so you should avoid having any hardware specific data in it and keep it as generic and extensible as possible. In this particular case, that probably means you should implement the user interfaces in the dmaengine core driver, and let the specific DMA driver provide callback function pointers along with the normal ones to fill that data.

Quoted 1 line

Thanks, I'll think about this. I'm inclined towards sysfs.

Ok. Documentation/sysfs-rules.txt has a good introduction of how this is done.

Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

The rest of the probe function does not register any user interface aside from the debugging stuff. Can you explain in the changelog how you expect the driver to be used in a real system? Is there another driver coming?

I expect this driver to grow in functionality over time. Right now, it does the global init for the DMA. After that all channels execute on their own without depending on each other. Global init has to be done first before attempting to do any channel initialization.

There is also implied startup ordering requirements. I was doing this by using channel driver with the late binding to guarantee that.

Quoted 8 lines
Quoted 2 lines

As soon as I use module_platform_driver, the ordering gets reversed for some reason.

For the ordering requirements, it's probably best to export a symbol with the entry point and let the normal driver call into that. Using separate initcall levels is not something you should do in a normal device driver like this.

Quoted 5 lines

I figured this out. If the channel driver starts before the management driver; then channel reset fails. I'm handling this in the channel driver and am returning -EPROBE_DEFER. After that, management driver gets its chance to work. Then, the channel driver again. This change is in the v2 series.

If you change the order in the Makefile, the management driver should always get probed first if both are built-in. When the driver is a loadable module, the ordering should work because of the way that the modules are loaded. Using the deferred probing makes sense here, so that would just be an optimization to avoid it normally. Things can still get shuffled around e.g. if the management device is deferred itself and we end up probing the channel driver first.

Quoted 11 lines
Quoted 6 lines

What is the relation between the device nodes for the two kinds of devices? Does it make sense to model the other one as a child device of this one? That way you would trivially do the ordering by not marking this one as 'compatible="simple-bus"' and triggering the registration of the child from the parent probe function.

The required order is management driver first, channel drivers next. If the order is reversed, channel init fails. I handle this with deferred probing.

Quoted 8 lines

I tried to keep loose binding between the management driver due to QEMU.

QEMU auto-generates the devicetree entries. The guest machine just sees one devicetree object for the DMA channel but guest machine device-tree kernel does not have any management driver entity.

This requires DMA channel driver to work independently in the guest machine without dependencies.

You have a distinct "compatible" string for qemu, right? It sounds like this is not the same device if the dependencies are different, and you could just have two ways to probe the same device.

The split between the two drivers still feels a little awkward overall, it might be good to give it some more thought.

Would it work to describe the combination of the channel and management registers as a single device with a single driver, but the management parts being optional? That way, the management registers could be intergrated better into the dmaengine framework, to provide a consistent API to user space.

Arnd

#33 lore raw
Quoted 4 lines · Arnd Bergmann

If you change the order in the Makefile, the management driver should always get probed first if both are built-in. When the driver is a loadable module, the ordering should work because of the way that the modules are loaded.

This sounds like something that should be commented in the Makefile. Even if you use -EPROBE_DEFER and you re-order the Makefile only so that it's less likely to be a problem, that's still worthy of a comment.

Signature · 7 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#20 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

Ok, got it.

Best add an explanation like the above in the interrupt handler, to prevent this from accidentally getting 'cleaned up' to use readl(), or copied into a driver that uses PCI ordering rules where it is actually wrong.

I'm adding this disclaimer into the ISR routine.

/*
* Fine tuned for this HW...
*
* This ISR has been designed for this particular hardware. Relaxed read
* and write accessors are used for performance reasons due to interrupt
* delivery guarantees. Do not copy this code blindly and expect
* that to work.
*/

Quoted 9 lines

I think it should be done like this:

- anything that is not performance critical, use normal readl/writel
- in the fast path, add a comment to each readl_relaxed()/writel_relaxed() that is safe in this driver but that would not be safe in a PCI device
- For the ones that would be safe on PCI as weel, use readl_relaxed()/writel_relaxed() without a comment on each one, but clarify somewhere that these are all intentional.

Makes sense.

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#21 lore raw

Re: [PATCH 2/2] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 11 lines · On Tuesday 03 November 2015 16:07:34 Sinan Kaya wrote:
Quoted 7 lines · Arnd Bergmann

Ok, got it.

Best add an explanation like the above in the interrupt handler, to prevent this from accidentally getting 'cleaned up' to use readl(), or copied into a driver that uses PCI ordering rules where it is actually wrong.

I'm adding this disclaimer into the ISR routine.

Quoted 10 lines

/*
* Fine tuned for this HW...
*
* This ISR has been designed for this particular hardware. Relaxed read
* and write accessors are used for performance reasons due to interrupt
* delivery guarantees. Do not copy this code blindly and expect
* that to work.
*/

Sounds good.

Arnd

author
#34 lore raw
In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

You have a distinct "compatible" string for qemu, right? It sounds like this is not the same device if the dependencies are different, and you could just have two ways to probe the same device.

No, it is the same dma channel object that gets probed by the same name like the hypervisor. The channel object gets unbound from the hypervisor, it then gets bound to VFIO. Then, eventually QEMU takes over. The channel driver does not know under which OS it is running and it works in both environments as it is without any code changes at this moment.

Quoted 2 lines

The split between the two drivers still feels a little awkward overall, it might be good to give it some more thought.

I see. I'd like to keep the management driver as independent as possible from the channel driver for security and functionality reasons. I need to keep the management addresses and functionality in the hypervisor only.

Quoted 5 lines
Quoted 1 line

Would it work to describe the combination of the channel and management

registers as a single device with a single driver, but the management parts being optional? That way, the management registers could be intergrated better into the dmaengine framework, to provide a consistent API to user space.

I can compile both management driver and channel driver into the same module if it sounds better. I can probe one with channel and another with the management name. I just need to be careful about not sharing any kind of data structure between them otherwise virtualization will break.

I consider the management driver a client of the DMA engine API at this moment.

Signature · 7 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html