Skip to contentSkip to conversation

dma: add Qualcomm Technologies HIDMA driver

PATCH Superseded Sinan Kaya 4 participants 24 messages Nov 23, 2015 – Dec 17, 2015

Subsystems (4)

v7 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

v7 cover dma: add Qualcomm Technologies HIDMA 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.

1. HIDMA Management driver
2. HIDMA Channel driver

Each HIDMA HW consists of multiple channels. These channels share some set of common parameters. These parameters are initialized by the management driver during power up. Same management driver is used for monitoring the execution of the channels. Management driver can change the performance behavior dynamically such as bandwidth allocation and prioritization in the future.

The management driver is executed in hypervisor context and is the main management entity for all channels provided by the device.

Changes from V6: (https://lkml.org/lkml/2015/11/22/111)
* none

Changes from V6: (https://lkml.org/lkml/2015/11/22/112)
* remove extra _ in documentation
* remove extra parenthesis in assignments
* create subdirectories for channels in sysfs

Changes from V6: (https://lkml.org/lkml/2015/11/22/113)
* remove extra parenthesis

Sinan Kaya (3):
dma: qcom_bam_dma: move to qcom directory
dma: add Qualcomm Technologies HIDMA management driver
dma: add Qualcomm Technologies HIDMA channel driver

 .../ABI/testing/sysfs-platform-hidma-mgmt          |  97 +++
 .../devicetree/bindings/dma/qcom_hidma.txt         |  18 +
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  61 ++
 drivers/dma/Kconfig                                |  11 +-
 drivers/dma/Makefile                               |   2 +-
 drivers/dma/qcom/Kconfig                           |  29 +
 drivers/dma/qcom/Makefile                          |   4 +
 drivers/dma/{qcom_bam_dma.c => qcom/bam_dma.c}     |   4 +-
 drivers/dma/qcom/hidma.c                           | 706 ++++++++++++++++
 drivers/dma/qcom/hidma.h                           | 157 ++++
 drivers/dma/qcom/hidma_dbg.c                       | 217 +++++
 drivers/dma/qcom/hidma_ll.c                        | 924 +++++++++++++++++++++
 drivers/dma/qcom/hidma_mgmt.c                      | 308 +++++++
 drivers/dma/qcom/hidma_mgmt.h                      |  39 +
 drivers/dma/qcom/hidma_mgmt_sys.c                  | 299 +++++++
 15 files changed, 2864 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-hidma-mgmt
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma.txt
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt
 create mode 100644 drivers/dma/qcom/Kconfig
 create mode 100644 drivers/dma/qcom/Makefile
 rename drivers/dma/{qcom_bam_dma.c => qcom/bam_dma.c} (99%)
 create mode 100644 drivers/dma/qcom/hidma.c
 create mode 100644 drivers/dma/qcom/hidma.h
 create mode 100644 drivers/dma/qcom/hidma_dbg.c
 create mode 100644 drivers/dma/qcom/hidma_ll.c
 create mode 100644 drivers/dma/qcom/hidma_mgmt.c
 create mode 100644 drivers/dma/qcom/hidma_mgmt.h
 create mode 100644 drivers/dma/qcom/hidma_mgmt_sys.c
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
author
#1 lore raw

PATCH v7 1/3 dma: qcom_bam_dma: move to qcom directory

Creating a QCOM directory for all QCOM DMA source files.

---
 drivers/dma/Kconfig                            | 11 ++---------
 drivers/dma/Makefile                           |  2 +-
 drivers/dma/qcom/Kconfig                       |  8 ++++++++
 drivers/dma/qcom/Makefile                      |  1 +
 drivers/dma/{qcom_bam_dma.c => qcom/bam_dma.c} |  4 ++--
 5 files changed, 14 insertions(+), 12 deletions(-)
 create mode 100644 drivers/dma/qcom/Kconfig
 create mode 100644 drivers/dma/qcom/Makefile
 rename drivers/dma/{qcom_bam_dma.c => qcom/bam_dma.c} (99%)
drivers/dma/Kconfig +2 -9
index b458475..47b1b98 100644
@@ -408,15 +408,6 @@ config PXA_DMA
 	  16 to 32 channels for peripheral to memory or memory to memory
 	  transfers.
 
-config QCOM_BAM_DMA
-	tristate "QCOM BAM DMA support"
-	depends on ARCH_QCOM || (COMPILE_TEST && OF && ARM)
-	select DMA_ENGINE
-	select DMA_VIRTUAL_CHANNELS
-	---help---
-	  Enable support for the QCOM BAM DMA controller.  This controller
-	  provides DMA capabilities for a variety of on-chip devices.
-
 config SIRF_DMA
 	tristate "CSR SiRFprimaII/SiRFmarco DMA support"
 	depends on ARCH_SIRF
@@ -527,6 +518,8 @@ config ZX_DMA
 # driver files
 source "drivers/dma/bestcomm/Kconfig"
 
+source "drivers/dma/qcom/Kconfig"
+
 source "drivers/dma/dw/Kconfig"
 
 source "drivers/dma/hsu/Kconfig"
drivers/dma/Makefile +1 -1
index 7711a71..8dba90d 100644
@@ -52,7 +52,6 @@ obj-$(CONFIG_PCH_DMA) += pch_dma.o
 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_RENESAS_DMA) += sh/
 obj-$(CONFIG_SIRF_DMA) += sirf-dma.o
 obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o
@@ -66,4 +65,5 @@ obj-$(CONFIG_TI_EDMA) += edma.o
 obj-$(CONFIG_XGENE_DMA) += xgene-dma.o
 obj-$(CONFIG_ZX_DMA) += zx296702_dma.o
 
+obj-y += qcom/
 obj-y += xilinx/
drivers/dma/qcom/Kconfig new file +8 -0
new file mode 100644
index 0000000..f17c272
@@ -0,0 +1,8 @@
+config QCOM_BAM_DMA
+	tristate "QCOM BAM DMA support"
+	depends on ARCH_QCOM || (COMPILE_TEST && OF && ARM)
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	---help---
+	  Enable support for the QCOM BAM DMA controller.  This controller
+	  provides DMA capabilities for a variety of on-chip devices.
drivers/dma/qcom/Makefile new file +1 -0
new file mode 100644
index 0000000..f612ae3
@@ -0,0 +1 @@
+obj-$(CONFIG_QCOM_BAM_DMA) += bam_dma.o
drivers/dma/qcom/bam_dma.c renamed from drivers/dma/qcom_bam_dma.c +2 -2
similarity index 99%
rename from drivers/dma/qcom_bam_dma.c
rename to drivers/dma/qcom/bam_dma.c
index 5a250cd..b6f053d 100644
@@ -49,8 +49,8 @@
 #include <linux/clk.h>
 #include <linux/dmaengine.h>
 
-#include "dmaengine.h"
-#include "virt-dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
 
 struct bam_desc_hw {
 	u32 addr;		/* Buffer physical address */
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
author
#3 lore raw

Re: [PATCH V7 1/3] dma: qcom_bam_dma: move to qcom directory

Quoted 10 lines · Andy Gross
Quoted 4 lines · Sinan Kaya

Creating a QCOM directory for all QCOM DMA source files.

---

Kind of nice having a different directory.

thanks

Signature · 4 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
#4 lore raw

PATCH v7 2/3 dma: add Qualcomm Technologies HIDMA management driver

In reply to 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.

1. HIDMA Management driver
2. HIDMA Channel driver

Each HIDMA HW consists of multiple channels. These channels share some set of common parameters. These parameters are initialized by the management driver during power up. Same management driver is used for monitoring the execution of the channels. Management driver can change the performance behavior dynamically such as bandwidth allocation and prioritization.

The management driver is executed in hypervisor context and is the main management entity for all channels provided by the device.

---
 .../ABI/testing/sysfs-platform-hidma-mgmt          |  97 +++++++
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  61 ++++
 drivers/dma/qcom/Kconfig                           |  11 +
 drivers/dma/qcom/Makefile                          |   1 +
 drivers/dma/qcom/hidma_mgmt.c                      | 308 +++++++++++++++++++++
 drivers/dma/qcom/hidma_mgmt.h                      |  39 +++
 drivers/dma/qcom/hidma_mgmt_sys.c                  | 299 ++++++++++++++++++++
 7 files changed, 816 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-hidma-mgmt
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt
 create mode 100644 drivers/dma/qcom/hidma_mgmt.c
 create mode 100644 drivers/dma/qcom/hidma_mgmt.h
 create mode 100644 drivers/dma/qcom/hidma_mgmt_sys.c
Documentation/ABI/testing/sysfs-platform-hidma-mgmt new file +97 -0
new file mode 100644
index 0000000..4fc6876
@@ -0,0 +1,97 @@
+What:		/sys/devices/platform/hidma-mgmt*/chan*/priority
+		/sys/devices/platform/QCOM8060:*/chan*/priority
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains either 0 or 1 and indicates if the DMA channel is a
+		low priority (0) or high priority (1) channel.
+
+What:		/sys/devices/platform/hidma-mgmt*/chan*/weight
+		/sys/devices/platform/QCOM8060:*/chan*/weight
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains 0..15 and indicates the weight of the channel among
+		equal priority channels during round robin scheduling.
+
+What:		/sys/devices/platform/hidma-mgmt*/chreset_timeout_cycles
+		/sys/devices/platform/QCOM8060:*/chreset_timeout_cycles
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains the platform specific cycle value to wait after a
+		reset command is issued. If the value is chosen too short,
+		then the HW will issue a reset failure interrupt. The value
+		is platform specific and should not be changed without
+		consultance.
+
+What:		/sys/devices/platform/hidma-mgmt*/dma_channels
+		/sys/devices/platform/QCOM8060:*/dma_channels
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains the number of dma channels supported by one instance
+		of HIDMA hardware. The value may change from chip to chip.
+
+What:		/sys/devices/platform/hidma-mgmt*/hw_version_major
+		/sys/devices/platform/QCOM8060:*/hw_version_major
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Version number major for the hardware.
+
+What:		/sys/devices/platform/hidma-mgmt*/hw_version_minor
+		/sys/devices/platform/QCOM8060:*/hw_version_minor
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Version number minor for the hardware.
+
+What:		/sys/devices/platform/hidma-mgmt*/max_rd_xactions
+		/sys/devices/platform/QCOM8060:*/max_rd_xactions
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains a value between 0 and 31. Maximum number of
+		read transactions that can be issued back to back.
+		Choosing a higher number gives better performance but
+		can also cause performance reduction to other peripherals
+		sharing the same bus.
+
+What:		/sys/devices/platform/hidma-mgmt*/max_read_request
+		/sys/devices/platform/QCOM8060:*/max_read_request
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Size of each read request. The value needs to be a power
+		of two and can be between 128 and 1024.
+
+What:		/sys/devices/platform/hidma-mgmt*/max_wr_xactions
+		/sys/devices/platform/QCOM8060:*/max_wr_xactions
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains a value between 0 and 31. Maximum number of
+		write transactions that can be issued back to back.
+		Choosing a higher number gives better performance but
+		can also cause performance reduction to other peripherals
+		sharing the same bus.
+
+
+What:		/sys/devices/platform/hidma-mgmt*/max_write_request
+		/sys/devices/platform/QCOM8060:*/max_write_request
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Size of each write request. The value needs to be a power
+		of two and can be between 128 and 1024.
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +61 -0

61 lines not on this page · raw message

drivers/dma/qcom/Kconfig +11 -0
index f17c272..ebe5b8c 100644
@@ -6,3 +6,14 @@ config QCOM_BAM_DMA
 	---help---
 	  Enable support for the QCOM BAM DMA controller.  This controller
 	  provides DMA capabilities for a variety of on-chip devices.
+
+config QCOM_HIDMA_MGMT
+	tristate "Qualcomm Technologies HIDMA Management 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 channel driver can
+	  start managing the channels. In a virtualized environment,
+	  the guest OS would run QCOM_HIDMA channel driver and the
+	  hypervisor would run the QCOM_HIDMA_MGMT management driver.
drivers/dma/qcom/Makefile +1 -0
index f612ae3..1a5a96d 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_QCOM_BAM_DMA) += bam_dma.o
+obj-$(CONFIG_QCOM_HIDMA_MGMT) += hidma_mgmt.o hidma_mgmt_sys.o
drivers/dma/qcom/hidma_mgmt.c new file +308 -0

308 lines not on this page · raw message

drivers/dma/qcom/hidma_mgmt.h new file +39 -0
new file mode 100644
index 0000000..f7daf33
@@ -0,0 +1,39 @@
+/*
+ * Qualcomm Technologies HIDMA Management common header
+ *
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+struct hidma_mgmt_dev {
+	u8 hw_version_major;
+	u8 hw_version_minor;
+
+	u32 max_wr_xactions;
+	u32 max_rd_xactions;
+	u32 max_write_request;
+	u32 max_read_request;
+	u32 dma_channels;
+	u32 chreset_timeout_cycles;
+	u32 hw_version;
+	u32 *priority;
+	u32 *weight;
+
+	/* Hardware device constants */
+	void __iomem *virtaddr;
+	resource_size_t addrsize;
+
+	struct kobject **chroots;
+	struct platform_device *pdev;
+};
+
+int hidma_mgmt_init_sys(struct hidma_mgmt_dev *dev);
+int hidma_mgmt_setup(struct hidma_mgmt_dev *mgmtdev);
drivers/dma/qcom/hidma_mgmt_sys.c new file +299 -0

299 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
Reviewed-by on v7 2/3
#5 lore raw

Re: [PATCH V7 2/3] dma: add Qualcomm Technologies HIDMA management driver

Quoted 15 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.

1. HIDMA Management driver
2. HIDMA Channel driver

Each HIDMA HW consists of multiple channels. These channels share some set of common parameters. These parameters are initialized by the management driver during power up. Same management driver is used for monitoring the execution of the channels. Management driver can change the performance behavior dynamically such as bandwidth allocation and prioritization.

Quoted 4 lines

The management driver is executed in hypervisor context and is the main management entity for all channels provided by the device.

Thanks for an update!

Looks cool! Though still few errors spelling and style nitpicks (you may ignore them if you wish) below.

Quoted 176 lines
---
 .../ABI/testing/sysfs-platform-hidma-mgmt          |  97 +++++++
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  61 ++++
 drivers/dma/qcom/Kconfig                           |  11 +
 drivers/dma/qcom/Makefile                          |   1 +
 drivers/dma/qcom/hidma_mgmt.c                      | 308 +++++++++++++++++++++
 drivers/dma/qcom/hidma_mgmt.h                      |  39 +++
 drivers/dma/qcom/hidma_mgmt_sys.c                  | 299 ++++++++++++++++++++
 7 files changed, 816 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-hidma-mgmt
 create mode 100644 Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt
 create mode 100644 drivers/dma/qcom/hidma_mgmt.c
 create mode 100644 drivers/dma/qcom/hidma_mgmt.h
 create mode 100644 drivers/dma/qcom/hidma_mgmt_sys.c
Documentation/ABI/testing/sysfs-platform-hidma-mgmt new file +97 -0
new file mode 100644
index 0000000..4fc6876
@@ -0,0 +1,97 @@
+What:          /sys/devices/platform/hidma-mgmt*/chan*/priority
+               /sys/devices/platform/QCOM8060:*/chan*/priority
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Contains either 0 or 1 and indicates if the DMA channel is a
+               low priority (0) or high priority (1) channel.
+
+What:          /sys/devices/platform/hidma-mgmt*/chan*/weight
+               /sys/devices/platform/QCOM8060:*/chan*/weight
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Contains 0..15 and indicates the weight of the channel among
+               equal priority channels during round robin scheduling.
+
+What:          /sys/devices/platform/hidma-mgmt*/chreset_timeout_cycles
+               /sys/devices/platform/QCOM8060:*/chreset_timeout_cycles
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Contains the platform specific cycle value to wait after a
+               reset command is issued. If the value is chosen too short,
+               then the HW will issue a reset failure interrupt. The value
+               is platform specific and should not be changed without
+               consultance.
+
+What:          /sys/devices/platform/hidma-mgmt*/dma_channels
+               /sys/devices/platform/QCOM8060:*/dma_channels
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Contains the number of dma channels supported by one instance
+               of HIDMA hardware. The value may change from chip to chip.
+
+What:          /sys/devices/platform/hidma-mgmt*/hw_version_major
+               /sys/devices/platform/QCOM8060:*/hw_version_major
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Version number major for the hardware.
+
+What:          /sys/devices/platform/hidma-mgmt*/hw_version_minor
+               /sys/devices/platform/QCOM8060:*/hw_version_minor
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Version number minor for the hardware.
+
+What:          /sys/devices/platform/hidma-mgmt*/max_rd_xactions
+               /sys/devices/platform/QCOM8060:*/max_rd_xactions
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Contains a value between 0 and 31. Maximum number of
+               read transactions that can be issued back to back.
+               Choosing a higher number gives better performance but
+               can also cause performance reduction to other peripherals
+               sharing the same bus.
+
+What:          /sys/devices/platform/hidma-mgmt*/max_read_request
+               /sys/devices/platform/QCOM8060:*/max_read_request
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Size of each read request. The value needs to be a power
+               of two and can be between 128 and 1024.
+
+What:          /sys/devices/platform/hidma-mgmt*/max_wr_xactions
+               /sys/devices/platform/QCOM8060:*/max_wr_xactions
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Contains a value between 0 and 31. Maximum number of
+               write transactions that can be issued back to back.
+               Choosing a higher number gives better performance but
+               can also cause performance reduction to other peripherals
+               sharing the same bus.
+
+
+What:          /sys/devices/platform/hidma-mgmt*/max_write_request
+               /sys/devices/platform/QCOM8060:*/max_write_request
+Date:          Nov 2015
+KernelVersion: 4.4
+Contact:       "Sinan Kaya <[email protected]>"
+Description:
+               Size of each write request. The value needs to be a power
+               of two and can be between 128 and 1024.
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +51 -0
new file mode 100644
index 0000000..eb053b9
@@ -0,0 +1,61 @@
+Qualcomm Technologies HIDMA Management interface
+
+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
+management entity for all channels provided by the device.
+
+Each HIDMA HW consists of multiple channels. These channels
+share some set of common parameters. These parameters are
+initialized by the management driver during power up.
+Same management driver is used for monitoring the execution
+of the channels. Management driver can change the performance
+behavior dynamically such as bandwidth allocation and
+prioritization.
+
+All channel devices get probed in the hypervisor
+context during power up. They show up as DMA engine
+DMA channels. Then, before starting the virtualization; each
+channel device is unbound from the hypervisor by VFIO
+and assign to the guest machine for control.
+
+This management driver will  be used by the system
+admin to monitor/reset the execution state of the DMA
+channels. This will be the management interface.
+
+
+Required properties:
+- compatible: "qcom,hidma-mgmt-1.0";
+- reg: Address range for DMA device
+- dma-channels: Number of channels supported by this DMA controller.
+- max-write-burst-bytes: Maximum write burst in bytes. A memcpy requested is
+  fragmented to multiples of this amount.
+- max-read-burst-bytes: Maximum read burst in bytes. A memcpy request is
+  fragmented to multiples of this amount.
+- max-write-transactions: Maximum write transactions to perform in a burst
+- max-read-transactions: Maximum read transactions to perform in a burst
+- channel-reset-timeout-cycles: Channel reset timeout in cycles for this SOC.
+- channel-priority: Priority of the channel.
+  Each dma channel share the same HW bandwidth with other dma channels.
+  If two requests reach to the HW at the same time from a low priority and
+  high priority channel, high priority channel will claim the bus.
+  0=low priority, 1=high priority
+- channel-weight: Round robin weight of the channel
+  Since there are only two priority levels supported, scheduling among
+  the equal priority channels is done via weights.
+
+Example:
+
+       hidma-mgmt at f9984000 = {
+               compatible = "qcom,hidma-mgmt-1.0";

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

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +9 -0
+               reg = <0xf9984000 0x15000>;
+               dma-channels = 6;
+               max-write-burst-bytes = 1024;
+               max-read-burst-bytes = 1024;
+               max-write-transactions = 31;
+               max-read-transactions = 31;
+               channel-reset-timeout-cycles = 0x500;
 
+               channel-priority = < 1 1 0 0 0 0>;
+               channel-weight = < 1 13 10 3 4 5>;

I don't know if it's okay, but I saw format of arrays like <X Y Z> (no head space).

Quoted 64 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +1 -0
+       };
drivers/dma/qcom/Kconfig +11 -0
index f17c272..ebe5b8c 100644
@@ -6,3 +6,14 @@ config QCOM_BAM_DMA
        ---help---
          Enable support for the QCOM BAM DMA controller.  This controller
          provides DMA capabilities for a variety of on-chip devices.
+
+config QCOM_HIDMA_MGMT
+       tristate "Qualcomm Technologies HIDMA Management 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 channel driver can
+         start managing the channels. In a virtualized environment,
+         the guest OS would run QCOM_HIDMA channel driver and the
+         hypervisor would run the QCOM_HIDMA_MGMT management driver.
drivers/dma/qcom/Makefile +1 -0
index f612ae3..1a5a96d 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_QCOM_BAM_DMA) += bam_dma.o
+obj-$(CONFIG_QCOM_HIDMA_MGMT) += hidma_mgmt.o hidma_mgmt_sys.o
drivers/dma/qcom/hidma_mgmt.c new file +31 -0
new file mode 100644
index 0000000..ea78a4d
@@ -0,0 +1,308 @@
+/*
+ * Qualcomm Technologies HIDMA DMA engine Management interface
+ *
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/dmaengine.h>
+#include <linux/acpi.h>
+#include <linux/of.h>
+#include <linux/property.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
+#include <linux/pm_runtime.h>
+#include <linux/bitops.h>
+
+#include "hidma_mgmt.h"
+
+#define QOS_N_OFFSET                   0x300
+#define CFG_OFFSET                     0x400

drivers/dma/qcom/hidma_mgmt.c line 41

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt.c new file +10 -0
+#define MAX_BUS_REQ_LEN_OFFSET         0x41C
+#define MAX_XACTIONS_OFFSET            0x420
+#define HW_VERSION_OFFSET              0x424
+#define CHRESET_TIMEOUT_OFFSET         0x418
+
+#define MAX_WR_XACTIONS_MASK           GENMASK(4, 0)
+#define MAX_RD_XACTIONS_MASK           GENMASK(4, 0)
+#define WEIGHT_MASK                    GENMASK(6, 0)
+#define MAX_BUS_REQ_LEN_MASK           GENMASK(15, 0)
+#define CHRESET_TIMEOUUT_MASK          GENMASK(19, 0)

Spelling?

Quoted 83 lines
drivers/dma/qcom/hidma_mgmt.c new file +83 -0
+
+#define MAX_WR_XACTIONS_BIT_POS        16
+#define MAX_BUS_WR_REQ_BIT_POS         16
+#define WRR_BIT_POS                    8
+#define PRIORITY_BIT_POS               15
+
+#define AUTOSUSPEND_TIMEOUT            2000
+#define MAX_CHANNEL_WEIGHT             15
+
+int hidma_mgmt_setup(struct hidma_mgmt_dev *mgmtdev)
+{
+       unsigned int i;
+       u32 val;
+
+       if (!is_power_of_2(mgmtdev->max_write_request) ||
+               (mgmtdev->max_write_request < 128) ||
+               (mgmtdev->max_write_request > 1024)) {
+               dev_err(&mgmtdev->pdev->dev, "invalid write request %d\n",
+                       mgmtdev->max_write_request);
+               return -EINVAL;
+       }
+
+       if (!is_power_of_2(mgmtdev->max_read_request) ||
+               (mgmtdev->max_read_request < 128) ||
+               (mgmtdev->max_read_request > 1024)) {
+               dev_err(&mgmtdev->pdev->dev, "invalid read request %d\n",
+                       mgmtdev->max_read_request);
+               return  -EINVAL;
+       }
+
+       if (mgmtdev->max_wr_xactions > MAX_WR_XACTIONS_MASK) {
+               dev_err(&mgmtdev->pdev->dev,
+                       "max_wr_xactions cannot be bigger than %ld\n",
+                       MAX_WR_XACTIONS_MASK);
+               return -EINVAL;
+       }
+
+       if (mgmtdev->max_rd_xactions > MAX_RD_XACTIONS_MASK) {
+               dev_err(&mgmtdev->pdev->dev,
+                       "max_rd_xactions cannot be bigger than %ld\n",
+                       MAX_RD_XACTIONS_MASK);
+               return -EINVAL;
+       }
+
+       for (i = 0; i < mgmtdev->dma_channels; i++) {
+               if (mgmtdev->priority[i] > 1) {
+                       dev_err(&mgmtdev->pdev->dev,
+                               "priority can be 0 or 1\n");
+                       return -EINVAL;
+               }
+
+               if (mgmtdev->weight[i] > MAX_CHANNEL_WEIGHT) {
+                       dev_err(&mgmtdev->pdev->dev,
+                               "max value of weight can be %d.\n",
+                               MAX_CHANNEL_WEIGHT);
+                       return -EINVAL;
+               }
+
+               /* weight needs to be at least one */
+               if (mgmtdev->weight[i] == 0)
+                       mgmtdev->weight[i] = 1;
+       }
+
+       pm_runtime_get_sync(&mgmtdev->pdev->dev);
+       val = readl(mgmtdev->virtaddr + MAX_BUS_REQ_LEN_OFFSET);
+       val &= ~(MAX_BUS_REQ_LEN_MASK << MAX_BUS_WR_REQ_BIT_POS);
+       val |= mgmtdev->max_write_request << MAX_BUS_WR_REQ_BIT_POS;
+       val &= ~MAX_BUS_REQ_LEN_MASK;
+       val |= mgmtdev->max_read_request;
+       writel(val, mgmtdev->virtaddr + MAX_BUS_REQ_LEN_OFFSET);
+
+       val = readl(mgmtdev->virtaddr + MAX_XACTIONS_OFFSET);
+       val &= ~(MAX_WR_XACTIONS_MASK << MAX_WR_XACTIONS_BIT_POS);
+       val |= mgmtdev->max_wr_xactions << MAX_WR_XACTIONS_BIT_POS;
+       val &= ~MAX_RD_XACTIONS_MASK;
+       val |= mgmtdev->max_rd_xactions;
+       writel(val, mgmtdev->virtaddr + MAX_XACTIONS_OFFSET);
+
+       mgmtdev->hw_version = readl(mgmtdev->virtaddr + HW_VERSION_OFFSET);
+       mgmtdev->hw_version_major = (mgmtdev->hw_version >> 28) & 0xF;
+       mgmtdev->hw_version_minor = (mgmtdev->hw_version >> 16) & 0xF;
+
+       for (i = 0; i < mgmtdev->dma_channels; i++) {

drivers/dma/qcom/hidma_mgmt.c line 134

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt.c new file +10 -0
+               val = readl(mgmtdev->virtaddr + QOS_N_OFFSET + (4 * i));
+               val &= ~(1 << PRIORITY_BIT_POS);
+               val |= (mgmtdev->priority[i] & 0x1) << PRIORITY_BIT_POS;
+               val &= ~(WEIGHT_MASK << WRR_BIT_POS);
+               val |= (mgmtdev->weight[i] & WEIGHT_MASK) << WRR_BIT_POS;
+               writel(val, mgmtdev->virtaddr + QOS_N_OFFSET + (4 * i));
+       }
+
+       val = readl(mgmtdev->virtaddr + CHRESET_TIMEOUT_OFFSET);
+       val &= ~CHRESET_TIMEOUUT_MASK;

Ditto. _TIMEOUT_?

drivers/dma/qcom/hidma_mgmt.c line 135

Quoted 1 line
drivers/dma/qcom/hidma_mgmt.c new file +1 -0
+       val |= mgmtdev->chreset_timeout_cycles & CHRESET_TIMEOUUT_MASK;

Ditto.

Quoted 333 lines
drivers/dma/qcom/hidma_mgmt.c new file +173 -0
+       writel(val, mgmtdev->virtaddr + CHRESET_TIMEOUT_OFFSET);
+
+       pm_runtime_mark_last_busy(&mgmtdev->pdev->dev);
+       pm_runtime_put_autosuspend(&mgmtdev->pdev->dev);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(hidma_mgmt_setup);
+
+static int hidma_mgmt_probe(struct platform_device *pdev)
+{
+       struct hidma_mgmt_dev *mgmtdev;
+       struct resource *res;
+       void __iomem *virtaddr;
+       int irq;
+       int rc;
+       u32 val;
+
+       pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
+       pm_runtime_use_autosuspend(&pdev->dev);
+       pm_runtime_set_active(&pdev->dev);
+       pm_runtime_enable(&pdev->dev);
+       pm_runtime_get_sync(&pdev->dev);
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       virtaddr = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(virtaddr)) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               dev_err(&pdev->dev, "irq resources not found\n");
+               rc = irq;
+               goto out;
+       }
+
+       mgmtdev = devm_kzalloc(&pdev->dev, sizeof(*mgmtdev), GFP_KERNEL);
+       if (!mgmtdev) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       mgmtdev->pdev = pdev;
+       mgmtdev->addrsize = resource_size(res);
+       mgmtdev->virtaddr = virtaddr;
+
+       rc = device_property_read_u32(&pdev->dev, "dma-channels",
+                               &mgmtdev->dma_channels);
+       if (rc) {
+               dev_err(&pdev->dev, "number of channels missing\n");
+               goto out;
+       }
+
+       rc = device_property_read_u32(&pdev->dev,
+                               "channel-reset-timeout-cycles",
+                               &mgmtdev->chreset_timeout_cycles);
+       if (rc) {
+               dev_err(&pdev->dev, "channel reset timeout missing\n");
+               goto out;
+       }
+
+       rc = device_property_read_u32(&pdev->dev, "max-write-burst-bytes",
+                               &mgmtdev->max_write_request);
+       if (rc) {
+               dev_err(&pdev->dev, "max-write-burst-bytes missing\n");
+               goto out;
+       }
+
+       rc = device_property_read_u32(&pdev->dev, "max-read-burst-bytes",
+                               &mgmtdev->max_read_request);
+       if (rc) {
+               dev_err(&pdev->dev, "max-read-burst-bytes missing\n");
+               goto out;
+       }
+
+       rc = device_property_read_u32(&pdev->dev, "max-write-transactions",
+                               &mgmtdev->max_wr_xactions);
+       if (rc) {
+               dev_err(&pdev->dev, "max-write-transactions missing\n");
+               goto out;
+       }
+
+       rc = device_property_read_u32(&pdev->dev, "max-read-transactions",
+                               &mgmtdev->max_rd_xactions);
+       if (rc) {
+               dev_err(&pdev->dev, "max-read-transactions missing\n");
+               goto out;
+       }
+
+       mgmtdev->priority = devm_kcalloc(&pdev->dev,
+               mgmtdev->dma_channels, sizeof(*mgmtdev->priority), GFP_KERNEL);
+       if (!mgmtdev->priority) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       mgmtdev->weight = devm_kcalloc(&pdev->dev,
+               mgmtdev->dma_channels, sizeof(*mgmtdev->weight), GFP_KERNEL);
+       if (!mgmtdev->weight) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       rc = device_property_read_u32_array(&pdev->dev, "channel-priority",
+                               mgmtdev->priority, mgmtdev->dma_channels);
+       if (rc) {
+               dev_err(&pdev->dev, "channel-priority missing\n");
+               goto out;
+       }
+
+       rc = device_property_read_u32_array(&pdev->dev, "channel-weight",
+                               mgmtdev->weight, mgmtdev->dma_channels);
+       if (rc) {
+               dev_err(&pdev->dev, "channel-weight missing\n");
+               goto out;
+       }
+
+       rc = hidma_mgmt_setup(mgmtdev);
+       if (rc) {
+               dev_err(&pdev->dev, "setup failed\n");
+               goto out;
+       }
+
+       /* start the HW */
+       val = readl(mgmtdev->virtaddr + CFG_OFFSET);
+       val |= 1;
+       writel(val, mgmtdev->virtaddr + CFG_OFFSET);
+
+       rc = hidma_mgmt_init_sys(mgmtdev);
+       if (rc) {
+               dev_err(&pdev->dev, "sysfs setup failed\n");
+               goto out;
+       }
+
+       dev_info(&pdev->dev,
+                "HW rev: %d.%d @ %pa with %d physical channels\n",
+                mgmtdev->hw_version_major, mgmtdev->hw_version_minor,
+                &res->start, mgmtdev->dma_channels);
+
+       platform_set_drvdata(pdev, mgmtdev);
+       pm_runtime_mark_last_busy(&pdev->dev);
+       pm_runtime_put_autosuspend(&pdev->dev);
+       return 0;
+out:
+       pm_runtime_put_sync_suspend(&pdev->dev);
+       pm_runtime_disable(&pdev->dev);
+       return rc;
+}
+
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id hidma_mgmt_acpi_ids[] = {
+       {"QCOM8060"},
+       {},
+};
+#endif
+
+static const struct of_device_id hidma_mgmt_match[] = {
+       { .compatible = "qcom,hidma-mgmt-1.0", },
+       {},
+};
+MODULE_DEVICE_TABLE(of, hidma_mgmt_match);
+
+static struct platform_driver hidma_mgmt_driver = {
+       .probe = hidma_mgmt_probe,
+       .driver = {
+               .name = "hidma-mgmt",
+               .of_match_table = hidma_mgmt_match,
+               .acpi_match_table = ACPI_PTR(hidma_mgmt_acpi_ids),
+       },
+};
+module_platform_driver(hidma_mgmt_driver);
+MODULE_LICENSE("GPL v2");
drivers/dma/qcom/hidma_mgmt.h new file +39 -0
new file mode 100644
index 0000000..f7daf33
@@ -0,0 +1,39 @@
+/*
+ * Qualcomm Technologies HIDMA Management common header
+ *
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+struct hidma_mgmt_dev {
+       u8 hw_version_major;
+       u8 hw_version_minor;
+
+       u32 max_wr_xactions;
+       u32 max_rd_xactions;
+       u32 max_write_request;
+       u32 max_read_request;
+       u32 dma_channels;
+       u32 chreset_timeout_cycles;
+       u32 hw_version;
+       u32 *priority;
+       u32 *weight;
+
+       /* Hardware device constants */
+       void __iomem *virtaddr;
+       resource_size_t addrsize;
+
+       struct kobject **chroots;
+       struct platform_device *pdev;
+};
+
+int hidma_mgmt_init_sys(struct hidma_mgmt_dev *dev);
+int hidma_mgmt_setup(struct hidma_mgmt_dev *mgmtdev);
drivers/dma/qcom/hidma_mgmt_sys.c new file +109 -0
new file mode 100644
index 0000000..a4a6414
@@ -0,0 +1,299 @@
+/*
+ * Qualcomm Technologies HIDMA Management SYS interface
+ *
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/sysfs.h>
+#include <linux/platform_device.h>
+
+#include "hidma_mgmt.h"
+
+struct hidma_chan_attr {
+       struct hidma_mgmt_dev *mdev;
+       int index;
+       struct kobj_attribute attr;
+};
+
+struct hidma_mgmt_fileinfo {
+       char *name;
+       int mode;
+       int (*get)(struct hidma_mgmt_dev *mdev);
+       int (*set)(struct hidma_mgmt_dev *mdev, u64 val);
+};
+
+#define IMPLEMENT_GETSET(name)                                 \
+static int get_##name(struct hidma_mgmt_dev *mdev)             \
+{                                                              \
+       return mdev->name;                                      \
+}                                                              \
+static int set_##name(struct hidma_mgmt_dev *mdev, u64 val)    \
+{                                                              \
+       u64 tmp;                                                \
+       int rc;                                                 \
+                                                               \
+       tmp = mdev->name;                                       \
+       mdev->name = val;                                       \
+       rc = hidma_mgmt_setup(mdev);                            \
+       if (rc)                                                 \
+               mdev->name = tmp;                               \
+       return rc;                                              \
+}
+
+#define DECLARE_ATTRIBUTE(name, mode)                          \
+       {#name, mode, get_##name, set_##name}
+
+IMPLEMENT_GETSET(hw_version_major)
+IMPLEMENT_GETSET(hw_version_minor)
+IMPLEMENT_GETSET(max_wr_xactions)
+IMPLEMENT_GETSET(max_rd_xactions)
+IMPLEMENT_GETSET(max_write_request)
+IMPLEMENT_GETSET(max_read_request)
+IMPLEMENT_GETSET(dma_channels)
+IMPLEMENT_GETSET(chreset_timeout_cycles)
+
+static int set_priority(struct hidma_mgmt_dev *mdev, unsigned int i, u64 val)
+{
+       u64 tmp;
+       int rc;
+
+       if (i > mdev->dma_channels)
+               return -EINVAL;
+
+       tmp = mdev->priority[i];
+       mdev->priority[i] = val;
+       rc = hidma_mgmt_setup(mdev);
+       if (rc)
+               mdev->priority[i] = tmp;
+       return rc;
+}
+
+static int set_weight(struct hidma_mgmt_dev *mdev, unsigned int i, u64 val)
+{
+       u64 tmp;
+       int rc;
+
+       if (i > mdev->dma_channels)
+               return -EINVAL;
+
+       tmp = mdev->weight[i];
+       mdev->weight[i] = val;
+       rc = hidma_mgmt_setup(mdev);
+       if (rc)
+               mdev->weight[i] = tmp;
+       return rc;
+}
+
+static struct hidma_mgmt_fileinfo hidma_mgmt_files[] = {
+       DECLARE_ATTRIBUTE(hw_version_major, S_IRUGO),
+       DECLARE_ATTRIBUTE(hw_version_minor, S_IRUGO),
+       DECLARE_ATTRIBUTE(dma_channels, S_IRUGO),
+       DECLARE_ATTRIBUTE(chreset_timeout_cycles, S_IRUGO),
+       DECLARE_ATTRIBUTE(max_wr_xactions, (S_IRUGO|S_IWUGO)),
+       DECLARE_ATTRIBUTE(max_rd_xactions, (S_IRUGO|S_IWUGO)),
+       DECLARE_ATTRIBUTE(max_write_request, (S_IRUGO|S_IWUGO)),
+       DECLARE_ATTRIBUTE(max_read_request, (S_IRUGO|S_IWUGO)),
+};
+
+static ssize_t show_values(struct device *dev, struct device_attribute *attr,
+                               char *buf)
+{

drivers/dma/qcom/hidma_mgmt_sys.c line 119

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +10 -0
+       struct platform_device *pdev = to_platform_device(dev);
+       struct hidma_mgmt_dev *mdev = platform_get_drvdata(pdev);
+       unsigned int i;
+
+       buf[0] = 0;
+
+       for (i = 0; i < ARRAY_SIZE(hidma_mgmt_files); i++) {
+               if (strcmp(attr->attr.name, hidma_mgmt_files[i].name) == 0) {
+                       sprintf(buf, "%d\n", hidma_mgmt_files[i].get(mdev));
+                       goto done;

break; ?

Quoted 16 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +16 -0
+               }
+       }
+done:
+       return strlen(buf);
+}
+
+static ssize_t set_values(struct device *dev, struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct hidma_mgmt_dev *mdev = platform_get_drvdata(pdev);
+       unsigned long tmp;
+       unsigned int i;
+       int rc;
+
+       rc = kstrtoul(buf, 0, &tmp);

drivers/dma/qcom/hidma_mgmt_sys.c line 145

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +10 -0
+       if (rc)
+               return rc;
+
+       for (i = 0; i < ARRAY_SIZE(hidma_mgmt_files); i++) {
+               if (strcmp(attr->attr.name, hidma_mgmt_files[i].name) == 0) {
+                       rc = hidma_mgmt_files[i].set(mdev, tmp);
+                       if (rc)
+                               return rc;
+
+                       goto done;

Ditto.

Quoted 163 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +154 -1
+               }
+       }
+done:
+       return count;
+}
+
+static ssize_t show_values_channel(struct kobject *kobj,
+               struct kobj_attribute *attr, char *buf)
+{
+       struct hidma_chan_attr *chattr;
+       struct hidma_mgmt_dev *mdev;
+
+       buf[0] = 0;
+       chattr =  container_of(attr, struct hidma_chan_attr, attr);
+       mdev =  chattr->mdev;
+       if (strcmp(attr->attr.name, "priority") == 0) {
+               sprintf(buf, "%d\n", mdev->priority[chattr->index]);
+               goto done;
+       }
+
+       if (strcmp(attr->attr.name, "weight") == 0) {
+               sprintf(buf, "%d\n", mdev->weight[chattr->index]);
+               goto done;
+       }
+
+done:
+       return strlen(buf);
+}
+
+static ssize_t set_values_channel(struct kobject *kobj,
+               struct kobj_attribute *attr, const char *buf, size_t count)
+{
+       struct hidma_chan_attr *chattr;
+       struct hidma_mgmt_dev *mdev;
+       unsigned long tmp;
+       int rc;
+
+       chattr =  container_of(attr, struct hidma_chan_attr, attr);
+       mdev =  chattr->mdev;
+
+       rc = kstrtoul(buf, 0, &tmp);
+       if (rc)
+               return rc;
+
+       if (strcmp(attr->attr.name, "priority") == 0) {
+               rc = set_priority(mdev, chattr->index, tmp);
+               if (rc)
+                       return rc;
+               goto done;
+       }
+
+       if (strcmp(attr->attr.name, "weight") == 0) {
+               rc = set_weight(mdev, chattr->index, tmp);
+               if (rc)
+                       return rc;
+       }
+done:
+       return count;
+}
+
+static int create_sysfs_entry(struct hidma_mgmt_dev *dev, char *name, int mode)
+{
+       struct device_attribute *attrs;
+       char *name_copy;
+
+       attrs = devm_kmalloc(&dev->pdev->dev,
+                       sizeof(struct device_attribute), GFP_KERNEL);
+       if (!attrs)
+               return -ENOMEM;
+
+       name_copy = devm_kstrdup(&dev->pdev->dev, name, GFP_KERNEL);
+       if (!name_copy)
+               return -ENOMEM;
+
+       attrs->attr.name = name_copy;
+       attrs->attr.mode = mode;
+       attrs->show      = show_values;
+       attrs->store     = set_values;
+       sysfs_attr_init(&attrs->attr);
+
+       return device_create_file(&dev->pdev->dev, attrs);
+}
+
+static int create_sysfs_entry_channel(struct hidma_mgmt_dev *mdev, char *name,
+                               int mode, int index, struct kobject *parent)
+{
+       struct hidma_chan_attr *chattr;
+       char *name_copy;
+
+       chattr = devm_kmalloc(&mdev->pdev->dev, sizeof(*chattr), GFP_KERNEL);
+       if (!chattr)
+               return -ENOMEM;
+
+       name_copy = devm_kstrdup(&mdev->pdev->dev, name, GFP_KERNEL);
+       if (!name_copy)
+               return -ENOMEM;
+
+       chattr->mdev = mdev;
+       chattr->index = index;
+       chattr->attr.attr.name = name_copy;
+       chattr->attr.attr.mode = mode;
+       chattr->attr.show = show_values_channel;
+       chattr->attr.store = set_values_channel;
+       sysfs_attr_init(&chattr->attr.attr);
+
+       return sysfs_create_file(parent, &chattr->attr.attr);
+}
+
+int hidma_mgmt_init_sys(struct hidma_mgmt_dev *mdev)
+{
+       unsigned int i;
+       int rc;
+       int required;
+
+       required = sizeof(*mdev->chroots) * mdev->dma_channels;
+       mdev->chroots = devm_kmalloc(&mdev->pdev->dev, required, GFP_KERNEL);
+       if (!mdev->chroots)
+               return -ENOMEM;
+
+       /* create each channel directory here */
+       for (i = 0; i < mdev->dma_channels; i++) {
+               char name[10];
+
+               snprintf(name, sizeof(name), "chan%d", i);
+               mdev->chroots[i] = kobject_create_and_add(name,
+                                               &mdev->pdev->dev.kobj);
+               if (!mdev->chroots[i])
+                       return -ENOMEM;
+       }
+
+       /* populate common parameters */
+       for (i = 0; i < ARRAY_SIZE(hidma_mgmt_files); i++) {
+               rc = create_sysfs_entry(mdev, hidma_mgmt_files[i].name,
+                                       hidma_mgmt_files[i].mode);
+               if (rc)
+                       return rc;
+       }
+
+       /* populate parameters that are per channel */
+       for (i = 0; i < mdev->dma_channels; i++) {
+               rc = create_sysfs_entry_channel(mdev, "priority",
+                               (S_IRUGO|S_IWUGO), i, mdev->chroots[i]);
+               if (rc)
+                       return rc;
+
+               rc = create_sysfs_entry_channel(mdev, "weight",
+                               (S_IRUGO|S_IWUGO), i, mdev->chroots[i]);
+               if (rc)
+                       return rc;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(hidma_mgmt_init_sys);
--

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 linux-kernel" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#6 lore raw

Re: [PATCH V7 2/3] dma: add Qualcomm Technologies HIDMA management driver

Quoted 6 lines · Andy Shevchenko

Thanks for an update!

Looks cool! Though still few errors spelling and style nitpicks (you may ignore them if you wish) below.

Thanks, I'll post an updated version next week.

Signature · 4 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
#7 lore raw

Re: [PATCH V7 2/3] dma: add Qualcomm Technologies HIDMA management driver

In reply to Sinan Kaya

Documentation/ABI/testing/sysfs-platform-hidma-mgmt line 8

Quoted 10 lines · Sinan Kaya

+++ b/Documentation/ABI/testing/sysfs-platform-hidma-mgmt

Documentation/ABI/testing/sysfs-platform-hidma-mgmt new file +8 -0
@@ -0,0 +1,97 @@
+What:		/sys/devices/platform/hidma-mgmt*/chan*/priority
+		/sys/devices/platform/QCOM8060:*/chan*/priority
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains either 0 or 1 and indicates if the DMA channel is a
+		low priority (0) or high priority (1) channel.

What is purpose of adding sysfs entries here ?

Quoted 11 lines
drivers/dma/qcom/hidma_mgmt.c new file +11 -0
+
+#define QOS_N_OFFSET			0x300
+#define CFG_OFFSET			0x400
+#define MAX_BUS_REQ_LEN_OFFSET		0x41C
+#define MAX_XACTIONS_OFFSET		0x420
+#define HW_VERSION_OFFSET		0x424
+#define CHRESET_TIMEOUT_OFFSET		0x418
+
+#define MAX_WR_XACTIONS_MASK		GENMASK(4, 0)
+#define MAX_RD_XACTIONS_MASK		GENMASK(4, 0)
+#define WEIGHT_MASK			GENMASK(6, 0)

drivers/dma/qcom/hidma_mgmt.c line 49

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt.c new file +10 -0
+#define MAX_BUS_REQ_LEN_MASK		GENMASK(15, 0)
+#define CHRESET_TIMEOUUT_MASK		GENMASK(19, 0)
+
+#define MAX_WR_XACTIONS_BIT_POS	16
+#define MAX_BUS_WR_REQ_BIT_POS		16
+#define WRR_BIT_POS			8
+#define PRIORITY_BIT_POS		15
+
+#define AUTOSUSPEND_TIMEOUT		2000
+#define MAX_CHANNEL_WEIGHT		15

These names are quite generic and prone to collide with generic names, please prefix them with your driver name

Review line 31

Quoted 2 lines
(quoted diff) +2 -0
+}
+EXPORT_SYMBOL_GPL(hidma_mgmt_setup);

Why is this exported or rather who would be users of this?

drivers/dma/qcom/hidma_mgmt.c line 156

Quoted 13 lines
drivers/dma/qcom/hidma_mgmt.c new file +13 -0
+static int hidma_mgmt_probe(struct platform_device *pdev)
+{
+	struct hidma_mgmt_dev *mgmtdev;
+	struct resource *res;
+	void __iomem *virtaddr;
+	int irq;
+	int rc;
+	u32 val;
+
+	pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);

at this time pm core will treat device as fully enabled and pm methods can be invoked, but you are not ready yet right. Typically these are done at the end of the probe unless you have a reason...

drivers/dma/qcom/hidma_mgmt_sys.c line 108

Quoted 2 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +2 -0
+static ssize_t show_values(struct device *dev, struct device_attribute *attr,
+				char *buf)

Please fix the coding style here and other places as well. Specifically please read Chapter 2

Signature · 1 line
~Vinod
author
#8 lore raw

Re: [PATCH V7 2/3] dma: add Qualcomm Technologies HIDMA management driver

Quoted 15 lines · Vinod Koul

Documentation/ABI/testing/sysfs-platform-hidma-mgmt line 8

Quoted 10 lines · Sinan Kaya

+++ b/Documentation/ABI/testing/sysfs-platform-hidma-mgmt

Documentation/ABI/testing/sysfs-platform-hidma-mgmt new file +8 -0
@@ -0,0 +1,97 @@
+What:		/sys/devices/platform/hidma-mgmt*/chan*/priority
+		/sys/devices/platform/QCOM8060:*/chan*/priority
+Date:		Nov 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains either 0 or 1 and indicates if the DMA channel is a
+		low priority (0) or high priority (1) channel.

What is purpose of adding sysfs entries here ?

The goal is to run hidma channels in the guest machines and have management driver adjust the runtime characteristics of the channels such as round robing weight, priority, max read request etc. All of these are runtime configurable.

There will be a userspace application that will configure this on behalf of the system administrator via sysfs. System administrator will decide how to allocate hardware resources to the guest machines.

Quoted 16 lines
Quoted 16 lines
drivers/dma/qcom/hidma_mgmt.c new file +16 -0
+
+#define QOS_N_OFFSET			0x300
+#define CFG_OFFSET			0x400
+#define MAX_BUS_REQ_LEN_OFFSET		0x41C
+#define MAX_XACTIONS_OFFSET		0x420
+#define HW_VERSION_OFFSET		0x424
+#define CHRESET_TIMEOUT_OFFSET		0x418
+
+#define MAX_WR_XACTIONS_MASK		GENMASK(4, 0)
+#define MAX_RD_XACTIONS_MASK		GENMASK(4, 0)
+#define WEIGHT_MASK			GENMASK(6, 0)
+#define MAX_BUS_REQ_LEN_MASK		GENMASK(15, 0)
+#define CHRESET_TIMEOUUT_MASK		GENMASK(19, 0)
+
+#define MAX_WR_XACTIONS_BIT_POS	16
+#define MAX_BUS_WR_REQ_BIT_POS		16
Quoted 9 lines

drivers/dma/qcom/hidma_mgmt.c line 49

Quoted 5 lines
drivers/dma/qcom/hidma_mgmt.c new file +5 -0
+#define WRR_BIT_POS			8
+#define PRIORITY_BIT_POS		15
+
+#define AUTOSUSPEND_TIMEOUT		2000
+#define MAX_CHANNEL_WEIGHT		15

These names are quite generic and prone to collide with generic names, please prefix them with your driver name

OK

Quoted 4 lines

Review line 31

Quoted 2 lines
(quoted diff) +2 -0
+}
+EXPORT_SYMBOL_GPL(hidma_mgmt_setup);

Why is this exported or rather who would be users of this?

This driver consists of two files as hidma_mgmt.c and hidma_mgmt_sys.c. I'm calling hidma_mgmt_setup from the hidma_mgmt_sys.c file when a parameter such as priority and weight is changed to reconfigure the hardware. I got linker errors without this export as this function is in hidma_mgmt.c file.

Quoted 10 lines
Quoted 10 lines
drivers/dma/qcom/hidma_mgmt.c new file +9 -0
+static int hidma_mgmt_probe(struct platform_device *pdev)
+{
+	struct hidma_mgmt_dev *mgmtdev;
+	struct resource *res;
+	void __iomem *virtaddr;
+	int irq;
+	int rc;
+	u32 val;
+
Quoted 8 lines

drivers/dma/qcom/hidma_mgmt.c line 156

Quoted 4 lines
drivers/dma/qcom/hidma_mgmt.c new file +4 -0
+	pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);

at this time pm core will treat device as fully enabled and pm methods can be invoked, but you are not ready yet right. Typically these are done at the end of the probe unless you have a reason...

I need it here because the clocks are declared as ACPI power resources. The kernel is turning off all power resources during initialization. In order for this code to touch the hardware, I need to call enable so that clocks are enabled once again.

Quoted 5 lines

drivers/dma/qcom/hidma_mgmt_sys.c line 108

Quoted 3 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +2 -0
+static ssize_t show_values(struct device *dev, struct device_attribute *attr,
+				char *buf)

Please fix the coding style here and other places as well.

what's the problem here?

Quoted 3 lines

Specifically
please read Chapter 2

Why is checkpatch not complaining about any of the coding style issues? I'm checking my code with checkpatch before submitting. Is there any other tool that would catch this?

Signature · 4 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
#9 lore raw

Re: [PATCH V7 2/3] dma: add Qualcomm Technologies HIDMA management driver

Quoted 18 lines · Sinan Kaya
Quoted 9 lines
Quoted 9 lines
drivers/dma/qcom/hidma_mgmt.c new file +9 -0
+static int hidma_mgmt_probe(struct platform_device *pdev)
+{
+	struct hidma_mgmt_dev *mgmtdev;
+	struct resource *res;
+	void __iomem *virtaddr;
+	int irq;
+	int rc;
+	u32 val;
+
Quoted 8 lines

drivers/dma/qcom/hidma_mgmt.c line 156

Quoted 4 lines
drivers/dma/qcom/hidma_mgmt.c new file +4 -0
+	pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);

at this time pm core will treat device as fully enabled and pm methods can be invoked, but you are not ready yet right. Typically these are done at the end of the probe unless you have a reason...

Quoted 4 lines

I need it here because the clocks are declared as ACPI power resources. The kernel is turning off all power resources during initialization. In order for this code to touch the hardware, I need to call enable so that clocks are enabled once again.

The question is are you ready in your driver routines to be invoked by pm core?

Quoted 9 lines
Quoted 6 lines

drivers/dma/qcom/hidma_mgmt_sys.c line 108

Quoted 4 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +2 -0
+static ssize_t show_values(struct device *dev, struct device_attribute *attr,
+				char *buf)

Please fix the coding style here and other places as well.

what's the problem here?

Quoted 7 lines
Quoted 3 lines

Specifically
please read Chapter 2

Why is checkpatch not complaining about any of the coding style issues? I'm checking my code with checkpatch before submitting. Is there any other tool that would catch this?

So did you read the Chapter 2.. Quoting here

"Statements longer than 80 columns will be broken into sensible chunks, unless
exceeding 80 columns significantly increases readability and does not hide information. Descendants are always substantially shorter than the parent and
are placed substantially to the right. The same applies to function headers with a long argument list. However, never break user-visible strings such as printk messages, because that breaks the ability to grep for them."

Your breaking lines is not placed substantially to the right.. I do not think checkpatch is checking this..

Signature · 1 line
~Vinod
author
#10 lore raw

Re: [PATCH V7 2/3] dma: add Qualcomm Technologies HIDMA management driver

Quoted 20 lines · Vinod Koul
Quoted 18 lines · Sinan Kaya
Quoted 17 lines

drivers/dma/qcom/hidma_mgmt.c line 156

Quoted 13 lines
drivers/dma/qcom/hidma_mgmt.c new file +13 -0
+static int hidma_mgmt_probe(struct platform_device *pdev)
+{
+	struct hidma_mgmt_dev *mgmtdev;
+	struct resource *res;
+	void __iomem *virtaddr;
+	int irq;
+	int rc;
+	u32 val;
+
+	pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);

at this time pm core will treat device as fully enabled and pm methods can be invoked, but you are not ready yet right. Typically these are done at the end of the probe unless you have a reason...

Quoted 8 lines
Quoted 4 lines

I need it here because the clocks are declared as ACPI power resources. The kernel is turning off all power resources during initialization. In order for this code to touch the hardware, I need to call enable so that clocks are enabled once again.

The question is are you ready in your driver routines to be invoked by pm core?

I don't have any support for suspend and resume PM APIs. The only PM interface I support is PM runtime. PM can turn on/off the clocks based on the reference counts it maintains after get/set APIs. Since PM is turning off the clocks during power up before my driver load, I do need to grab this lock to re-enable it during HW initialization. Then, let PM turn off the clocks again after the AUTOSUSPEND_TIMEOUT when I'm done.

Is there any other interaction with the PM that I'm not aware of?

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

drivers/dma/qcom/hidma_mgmt_sys.c line 108

Quoted 4 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +2 -0
+static ssize_t show_values(struct device *dev, struct device_attribute *attr,
+				char *buf)

Please fix the coding style here and other places as well.

what's the problem here?

Quoted 3 lines

Specifically
please read Chapter 2

Quoted 6 lines
Quoted 3 lines

Why is checkpatch not complaining about any of the coding style issues? I'm checking my code with checkpatch before submitting. Is there any other tool that would catch this?

So did you read the Chapter 2.. Quoting here

I did read the chapter 2. Maybe, my lack of native english speaking but I don't get from this sentence that function parameters need to be aligned to the opening paranthesis.

Quoted 4 lines

Descendants are always substantially shorter than the parent
and are placed substantially to the right. The same applies to function headers with a long argument list.

I ran Lindent and manually cleaned up the junk it introduced. The result is this

static ssize_t show_values(struct device *dev, struct device_attribute *attr,
char *buf)

Quoted 3 lines

Your breaking lines is not placed substantially to the right.. I do not think checkpatch is checking this..

Signature · 4 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
#11 lore raw

Re: [PATCH V7 2/3] dma: add Qualcomm Technologies HIDMA management driver

Quoted 30 lines · Sinan Kaya
Quoted 20 lines · Vinod Koul
Quoted 18 lines · Sinan Kaya
Quoted 17 lines

drivers/dma/qcom/hidma_mgmt.c line 156

Quoted 13 lines
drivers/dma/qcom/hidma_mgmt.c new file +13 -0
+static int hidma_mgmt_probe(struct platform_device *pdev)
+{
+	struct hidma_mgmt_dev *mgmtdev;
+	struct resource *res;
+	void __iomem *virtaddr;
+	int irq;
+	int rc;
+	u32 val;
+
+	pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);

at this time pm core will treat device as fully enabled and pm methods can be invoked, but you are not ready yet right. Typically these are done at the end of the probe unless you have a reason...

Quoted 8 lines
Quoted 4 lines

I need it here because the clocks are declared as ACPI power resources. The kernel is turning off all power resources during initialization. In order for this code to touch the hardware, I need to call enable so that clocks are enabled once again.

The question is are you ready in your driver routines to be invoked by pm core?

Quoted 8 lines

I don't have any support for suspend and resume PM APIs. The only PM interface I support is PM runtime. PM can turn on/off the clocks based on the reference counts it maintains after get/set APIs. Since PM is turning off the clocks during power up before my driver load, I do need to grab this lock to re-enable it during HW initialization. Then, let PM turn off the clocks again after the AUTOSUSPEND_TIMEOUT when I'm done.

Is there any other interaction with the PM that I'm not aware of?

No this is fine. The the runtime_resume will be onvoked and it will request resources are those set before you enable the device?

Signature · 1 line
~Vinod
author
#12 lore raw

Re: [PATCH V7 2/3] dma: add Qualcomm Technologies HIDMA management driver

Quoted 38 lines · Vinod Koul
Quoted 37 lines · Sinan Kaya
Quoted 20 lines · Vinod Koul
Quoted 18 lines · Sinan Kaya
Quoted 17 lines

drivers/dma/qcom/hidma_mgmt.c line 156

Quoted 13 lines
drivers/dma/qcom/hidma_mgmt.c new file +13 -0
+static int hidma_mgmt_probe(struct platform_device *pdev)
+{
+	struct hidma_mgmt_dev *mgmtdev;
+	struct resource *res;
+	void __iomem *virtaddr;
+	int irq;
+	int rc;
+	u32 val;
+
+	pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);

at this time pm core will treat device as fully enabled and pm methods can be invoked, but you are not ready yet right. Typically these are done at the end of the probe unless you have a reason...

Quoted 8 lines
Quoted 4 lines

I need it here because the clocks are declared as ACPI power resources. The kernel is turning off all power resources during initialization. In order for this code to touch the hardware, I need to call enable so that clocks are enabled once again.

The question is are you ready in your driver routines to be invoked by pm core?

I don't have any support for suspend and resume PM APIs. The only PM interface I support is PM runtime. PM can turn on/off the clocks based on the reference counts it maintains after get/set APIs. Since PM is turning off the clocks during power up before my driver load, I do need to grab this lock to re-enable it during HW initialization. Then, let PM turn off the clocks again after the AUTOSUSPEND_TIMEOUT when I'm done.

Quoted 5 lines
Quoted 1 line

Is there any other interaction with the PM that I'm not aware of?

No this is fine. The the runtime_resume will be onvoked and it will request resources are those set before you enable the device?

Yes, the only resource that this device needs for power management is the ACPI power resources. The device does not support suspend/resume via traditional _PS0 and _PS3 calls. ACPI power resources are initialized during power up while ACPI is being enumerated.

The probing of the HIDMA driver happens much afterwards.

Signature · 4 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
#13 lore raw

PATCH v7 3/3 dma: add Qualcomm Technologies HIDMA channel driver

In reply to 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. The hardware only supports memcpy/memset and this driver only support memcpy interface. HW and driver doesn't support slave interface.

---
 .../devicetree/bindings/dma/qcom_hidma.txt         |  18 +
 drivers/dma/qcom/Kconfig                           |  10 +
 drivers/dma/qcom/Makefile                          |   2 +
 drivers/dma/qcom/hidma.c                           | 706 ++++++++++++++++
 drivers/dma/qcom/hidma.h                           | 157 ++++
 drivers/dma/qcom/hidma_dbg.c                       | 217 +++++
 drivers/dma/qcom/hidma_ll.c                        | 924 +++++++++++++++++++++
 7 files changed, 2034 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_dbg.c
 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..d18c8fc
@@ -0,0 +1,18 @@
+Qualcomm Technologies HIDMA Channel driver
+
+Required properties:
+- compatible: must contain "qcom,hidma-1.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: dma-controller at 0x5c050000 {
+		compatible = "qcom,hidma-1.0";
+		reg = <0 0x5c050000 0x0 0x1000>,
+		      <0 0x5c0b0000 0x0 0x1000>;
+		interrupts = <0 389 0>;
+		desc-count = <10>;
+		event-channel = <4>;
+	};
drivers/dma/qcom/Kconfig +10 -0
index ebe5b8c..5588e1c 100644
@@ -17,3 +17,13 @@ config QCOM_HIDMA_MGMT
 	  start managing the channels. In a virtualized environment,
 	  the guest OS would run QCOM_HIDMA channel driver and the
 	  hypervisor would run the QCOM_HIDMA_MGMT management driver.
+
+config QCOM_HIDMA
+	tristate "Qualcomm Technologies HIDMA Channel support"
+	select DMA_ENGINE
+	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 interface. The core is not intended for general
+	  purpose slave DMA.
drivers/dma/qcom/Makefile +2 -0
index 1a5a96d..f702df1 100644
@@ -1,2 +1,4 @@
 obj-$(CONFIG_QCOM_BAM_DMA) += bam_dma.o
 obj-$(CONFIG_QCOM_HIDMA_MGMT) += hidma_mgmt.o hidma_mgmt_sys.o
+obj-$(CONFIG_QCOM_HIDMA) +=  hdma.o
+hdma-objs        := hidma_ll.o hidma.o hidma_dbg.o
drivers/dma/qcom/hidma.c new file +706 -0

706 lines not on this page · raw message

drivers/dma/qcom/hidma.h new file +157 -0

157 lines not on this page · raw message

drivers/dma/qcom/hidma_dbg.c new file +217 -0

217 lines not on this page · raw message

drivers/dma/qcom/hidma_ll.c new file +924 -0

924 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
#14 lore raw

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

Quoted 7 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. The hardware only supports memcpy/memset and this driver only support memcpy interface. HW and driver doesn't support slave interface.

Quoted 9 lines
---
 .../devicetree/bindings/dma/qcom_hidma.txt         |  18 +
 drivers/dma/qcom/Kconfig                           |  10 +
 drivers/dma/qcom/Makefile                          |   2 +
 drivers/dma/qcom/hidma.c                           | 706 ++++++++++++++++
 drivers/dma/qcom/hidma.h                           | 157 ++++
 drivers/dma/qcom/hidma_dbg.c                       | 217 +++++
 drivers/dma/qcom/hidma_ll.c                        | 924 +++++++++++++++++++++
 7 files changed, 2034 insertions(+)

This was one of the reasons for slow review of this. I started few times but large patches made this getting pushed back

Pls help reviewers by splitting your code which looking at this could have been done

Quoted 11 lines
drivers/dma/qcom/hidma.c new file +11 -0
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/of_dma.h>

drivers/dma/qcom/hidma.c line 65

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+#include <linux/property.h>
+#include <linux/delay.h>
+#include <linux/highmem.h>
+#include <linux/io.h>
+#include <linux/sched.h>
+#include <linux/wait.h>
+#include <linux/acpi.h>
+#include <linux/irq.h>
+#include <linux/atomic.h>
+#include <linux/pm_runtime.h>

Do you need so many headers...?

drivers/dma/qcom/hidma.c line 120

Quoted 2 lines
drivers/dma/qcom/hidma.c new file +2 -0
+MODULE_PARM_DESC(event_channel_idx,
+		"event channel index array for the notifications");

Can you explain this parameter in detail pls

Quoted 14 lines
drivers/dma/qcom/hidma.c new file +14 -0
+static void hidma_callback(void *data)
+{
+	struct hidma_desc *mdesc = data;
+	struct hidma_chan *mchan = to_hidma_chan(mdesc->desc.chan);
+	struct dma_device *ddev = mchan->chan.device;
+	struct hidma_dev *dmadev = to_hidma_dev(ddev);
+	unsigned long irqflags;
+	bool queued = false;
+
+	spin_lock_irqsave(&mchan->lock, irqflags);
+	if (mdesc->node.next) {
+		/* Delete from the active list, add to completed list */
+		list_move_tail(&mdesc->node, &mchan->completed);
+		queued = true;

drivers/dma/qcom/hidma.c line 196

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+	}
+	spin_unlock_irqrestore(&mchan->lock, irqflags);
+
+	hidma_process_completed(dmadev);
+
+	if (queued) {
+		pm_runtime_mark_last_busy(dmadev->ddev.dev);
+		pm_runtime_put_autosuspend(dmadev->ddev.dev);
+	}
+}

Callback is typically referred to client callback upon dma completion, can you explain what you are trying to do here

Quoted 13 lines
drivers/dma/qcom/hidma.c new file +13 -0
+static int hidma_chan_init(struct hidma_dev *dmadev, u32 dma_sig)
+{
+	struct hidma_chan *mchan;
+	struct dma_device *ddev;
+
+	mchan = devm_kzalloc(dmadev->ddev.dev, sizeof(*mchan), GFP_KERNEL);
+	if (!mchan)
+		return -ENOMEM;
+
+	ddev = &dmadev->ddev;
+	mchan->dma_sig = dma_sig;
+	mchan->dmadev = dmadev;
+	mchan->chan.device = ddev;

drivers/dma/qcom/hidma.c line 220

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+	dma_cookie_init(&mchan->chan);
+
+	INIT_LIST_HEAD(&mchan->free);
+	INIT_LIST_HEAD(&mchan->prepared);
+	INIT_LIST_HEAD(&mchan->active);
+	INIT_LIST_HEAD(&mchan->completed);
+
+	spin_lock_init(&mchan->lock);
+	list_add_tail(&mchan->chan.device_node, &ddev->channels);
+	dmadev->ddev.chancnt++;

Have you looked at vchan implementation and moving list handling to this layer ?

drivers/dma/qcom/hidma.c line 230

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+	return 0;
+}
+
+static void hidma_issue_pending(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	struct hidma_dev *dmadev = mchan->dmadev;
+
+	/* PM will be released in hidma_callback function. */
+	pm_runtime_get_sync(dmadev->ddev.dev);

Oh no, this is not allowed. pm_runtime_get_sync() can sleep and issue_pending can be invoked from atomic context.

drivers/dma/qcom/hidma.c line 241

Quoted 8 lines
drivers/dma/qcom/hidma.c new file +8 -0
+static enum dma_status hidma_tx_status(struct dma_chan *dmach,
+			dma_cookie_t cookie, struct dma_tx_state *txstate)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	enum dma_status ret;
+
+	if (mchan->paused)
+		ret = DMA_PAUSED;

This is not quite right. The status query is for a descriptor and NOT for channel. Here if the descriptor queried was running then it would be paused for the rest pending txn, it would be DMA_IN_PROGRESS.

drivers/dma/qcom/hidma.c line 261

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+static dma_cookie_t hidma_tx_submit(struct dma_async_tx_descriptor *txd)
+{
+	struct hidma_chan *mchan = to_hidma_chan(txd->chan);
+	struct hidma_dev *dmadev = mchan->dmadev;
+	struct hidma_desc *mdesc;
+	unsigned long irqflags;
+	dma_cookie_t cookie;
+
+	if (!hidma_ll_isenabled(dmadev->lldev))
+		return -ENODEV;

is this not too late for this check, you should fail this on prepare method

Quoted 6 lines
drivers/dma/qcom/hidma.c new file +6 -0
+static int hidma_alloc_chan_resources(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	struct hidma_dev *dmadev = mchan->dmadev;
+	struct hidma_desc *mdesc, *tmp;
+	unsigned long irqflags;

drivers/dma/qcom/hidma.c line 293

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+	LIST_HEAD(descs);
+	unsigned int i;
+	int rc = 0;
+
+	if (mchan->allocated)
+		return 0;
+
+	/* Alloc descriptors for this channel */
+	for (i = 0; i < dmadev->nr_descriptors; i++) {
+		mdesc = kzalloc(sizeof(struct hidma_desc), GFP_KERNEL);

GFP_NOWAIT pls, this can be called from atomic context

drivers/dma/qcom/hidma.c line 299

Quoted 6 lines
drivers/dma/qcom/hidma.c new file +6 -0
+		if (!mdesc) {
+			rc = -ENOMEM;
+			break;
+		}
+		dma_async_tx_descriptor_init(&mdesc->desc, dmach);
+		mdesc->desc.flags = DMA_CTRL_ACK;

what is the purpose of setting this flag here

drivers/dma/qcom/hidma.c line 341

Quoted 13 lines
drivers/dma/qcom/hidma.c new file +13 -0
+static void hidma_free_chan_resources(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	struct hidma_dev *mdma = mchan->dmadev;
+	struct hidma_desc *mdesc, *tmp;
+	unsigned long irqflags;
+	LIST_HEAD(descs);
+
+	if (!list_empty(&mchan->prepared) || !list_empty(&mchan->active) ||
+		!list_empty(&mchan->completed)) {
+		/*
+		 * We have unfinished requests waiting.
+		 * Terminate the request from the hardware.

that sounds as bug.. free should be called when txn are completed/aborted

drivers/dma/qcom/hidma.c line 347

Quoted 6 lines
drivers/dma/qcom/hidma.c new file +6 -0
+		 */
+		hidma_cleanup_pending_tre(mdma->lldev, ERR_INFO_SW,
+					ERR_CODE_UNEXPECTED_TERMINATE);
+
+		/* Give enough time for completions to be called. */
+		msleep(100);

should we not poll/read after delay, also we are still in atomic context

drivers/dma/qcom/hidma.c line 351

Quoted 4 lines
drivers/dma/qcom/hidma.c new file +4 -0
+	}
+
+	spin_lock_irqsave(&mchan->lock, irqflags);
+	/* Channel must be idle */

sorry I do not like that assumption

Quoted 4 lines
drivers/dma/qcom/hidma.c new file +4 -0
+	/* return all user requests */
+	list_for_each_entry_safe(mdesc, tmp, &list, node) {
+		struct dma_async_tx_descriptor *txd = &mdesc->desc;
+		dma_async_tx_callback callback = mdesc->desc.callback;

drivers/dma/qcom/hidma.c line 444

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+		void *param = mdesc->desc.callback_param;
+		enum dma_status status;
+
+		dma_descriptor_unmap(txd);
+
+		status = hidma_ll_status(dmadev->lldev, mdesc->tre_ch);
+		/*
+		 * The API requires that no submissions are done from a
+		 * callback, so we don't need to drop the lock here
+		 */

That is correct assumption for async_tx and which is deprecated now. In fact the converse is true for rest!

Quoted 7 lines
drivers/dma/qcom/hidma.c new file +7 -0
+static int hidma_pause(struct dma_chan *chan)
+{
+	struct hidma_chan *mchan;
+	struct hidma_dev *dmadev;
+
+	mchan = to_hidma_chan(chan);
+	dmadev = to_hidma_dev(mchan->chan.device);

drivers/dma/qcom/hidma.c line 479

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+	if (!mchan->paused) {
+		pm_runtime_get_sync(dmadev->ddev.dev);
+		if (hidma_ll_pause(dmadev->lldev))
+			dev_warn(dmadev->ddev.dev, "channel did not stop\n");
+		mchan->paused = true;
+		pm_runtime_mark_last_busy(dmadev->ddev.dev);
+		pm_runtime_put_autosuspend(dmadev->ddev.dev);
+	}
+	return 0;
+}

This is interesting, we associate pause/resume for slave dma ops and not for memcpy ops, what is the reason for adding pause/resume here?

drivers/dma/qcom/hidma.c line 676

Quoted 13 lines
drivers/dma/qcom/hidma.c new file +13 -0
+static int hidma_remove(struct platform_device *pdev)
+{
+	struct hidma_dev *dmadev = platform_get_drvdata(pdev);
+
+	pm_runtime_get_sync(dmadev->ddev.dev);
+	dma_async_device_unregister(&dmadev->ddev);
+	hidma_debug_uninit(dmadev);
+	hidma_ll_uninit(dmadev->lldev);
+	hidma_free(dmadev);
+
+	dev_info(&pdev->dev, "HI-DMA engine removed\n");
+	pm_runtime_put_sync_suspend(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);

and your irq is still active and can invoke your irq handler!

drivers/dma/qcom/hidma.c line 683

Quoted 7 lines
drivers/dma/qcom/hidma.c new file +7 -0
+
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id hidma_acpi_ids[] = {
+	{"QCOM8061"},

Qcom and ACPI, that is v interesting combination !

Signature · 1 line
~Vinod
author
#15 lore raw

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

Quoted 18 lines · Vinod Koul
Quoted 7 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. The hardware only supports memcpy/memset and this driver only support memcpy interface. HW and driver doesn't support slave interface.

Quoted 9 lines
---
 .../devicetree/bindings/dma/qcom_hidma.txt         |  18 +
 drivers/dma/qcom/Kconfig                           |  10 +
 drivers/dma/qcom/Makefile                          |   2 +
 drivers/dma/qcom/hidma.c                           | 706 ++++++++++++++++
 drivers/dma/qcom/hidma.h                           | 157 ++++
 drivers/dma/qcom/hidma_dbg.c                       | 217 +++++
 drivers/dma/qcom/hidma_ll.c                        | 924 +++++++++++++++++++++
 7 files changed, 2034 insertions(+)
Quoted 5 lines

This was one of the reasons for slow review of this. I started few times but large patches made this getting pushed back

Pls help reviewers by splitting your code which looking at this could have been done

I have split the debugfs support from this patch to its own patch. Any other idea on how else you'd break the code? I can take one more step and separate the lower layer from the OS layer by using stub functions on the initial commit.

Quoted 16 lines
Quoted 16 lines
drivers/dma/qcom/hidma.c new file +15 -0
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/of_dma.h>
+#include <linux/property.h>
+#include <linux/delay.h>
+#include <linux/highmem.h>
+#include <linux/io.h>
Quoted 8 lines

drivers/dma/qcom/hidma.c line 65

Quoted 6 lines
drivers/dma/qcom/hidma.c new file +6 -0
+#include <linux/sched.h>
+#include <linux/wait.h>
+#include <linux/acpi.h>
+#include <linux/irq.h>
+#include <linux/atomic.h>
+#include <linux/pm_runtime.h>

Do you need so many headers...?

probably not, let me see what I can do about them.

Quoted 5 lines

drivers/dma/qcom/hidma.c line 120

Quoted 3 lines
drivers/dma/qcom/hidma.c new file +2 -0
+MODULE_PARM_DESC(event_channel_idx,
+		"event channel index array for the notifications");

Can you explain this parameter in detail pls

OK. I added the following comment to the code.

/*
* Each DMA channel is associated with an event channel for interrupt
* delivery. The event channel index usually comes from the firmware through
* ACPI/DT. When a HIDMA channel is executed in the guest machine
context (QEMU)
* the device tree gets auto-generated based on the memory and IRQ resources
* this driver uses on the host machine. Any device specific parameter
such as
* event-channel gets ignored by the QEMU.
* We are using this command line parameter to pass the event channel
index to
* the guest machine.
*/
s

Quoted 20 lines
Quoted 20 lines
drivers/dma/qcom/hidma.c new file +19 -0
+static void hidma_callback(void *data)
+{
+	struct hidma_desc *mdesc = data;
+	struct hidma_chan *mchan = to_hidma_chan(mdesc->desc.chan);
+	struct dma_device *ddev = mchan->chan.device;
+	struct hidma_dev *dmadev = to_hidma_dev(ddev);
+	unsigned long irqflags;
+	bool queued = false;
+
+	spin_lock_irqsave(&mchan->lock, irqflags);
+	if (mdesc->node.next) {
+		/* Delete from the active list, add to completed list */
+		list_move_tail(&mdesc->node, &mchan->completed);
+		queued = true;
+	}
+	spin_unlock_irqrestore(&mchan->lock, irqflags);
+
+	hidma_process_completed(dmadev);
+
Quoted 8 lines

drivers/dma/qcom/hidma.c line 196

Quoted 5 lines
drivers/dma/qcom/hidma.c new file +5 -0
+	if (queued) {
+		pm_runtime_mark_last_busy(dmadev->ddev.dev);
+		pm_runtime_put_autosuspend(dmadev->ddev.dev);
+	}
+}

Callback is typically referred to client callback upon dma completion, can you explain what you are trying to do here

When a DMA transfer completes, the hidma_callback function in the hidma.c file gets called from the lower layer (hidma_ll.c) in order to move this request from active queue into the completed queue.

hidma_process_completed eventually calls the "client callback" in it.

The PM stuff is for guaranteeing that clocks are not turned off while HW is working on it.

I grab the PM lock in issue pending and release it in the hidma_callback.

Quoted 19 lines
Quoted 19 lines
drivers/dma/qcom/hidma.c new file +18 -0
+static int hidma_chan_init(struct hidma_dev *dmadev, u32 dma_sig)
+{
+	struct hidma_chan *mchan;
+	struct dma_device *ddev;
+
+	mchan = devm_kzalloc(dmadev->ddev.dev, sizeof(*mchan), GFP_KERNEL);
+	if (!mchan)
+		return -ENOMEM;
+
+	ddev = &dmadev->ddev;
+	mchan->dma_sig = dma_sig;
+	mchan->dmadev = dmadev;
+	mchan->chan.device = ddev;
+	dma_cookie_init(&mchan->chan);
+
+	INIT_LIST_HEAD(&mchan->free);
+	INIT_LIST_HEAD(&mchan->prepared);
+	INIT_LIST_HEAD(&mchan->active);
Quoted 8 lines

drivers/dma/qcom/hidma.c line 220

Quoted 5 lines
drivers/dma/qcom/hidma.c new file +5 -0
+	INIT_LIST_HEAD(&mchan->completed);
+
+	spin_lock_init(&mchan->lock);
+	list_add_tail(&mchan->chan.device_node, &ddev->channels);
+	dmadev->ddev.chancnt++;

Have you looked at vchan implementation and moving list handling to this layer ?

I'll add vchan support later on another revision. The original code had vchan support in it. It became a terminology mess. So, I removed it for the moment.

Using vchan, I can take multiple clients and serve them in a single channel later.

Quoted 14 lines

drivers/dma/qcom/hidma.c line 230

Quoted 11 lines
drivers/dma/qcom/hidma.c new file +10 -0
+	return 0;
+}
+
+static void hidma_issue_pending(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	struct hidma_dev *dmadev = mchan->dmadev;
+
+	/* PM will be released in hidma_callback function. */
+	pm_runtime_get_sync(dmadev->ddev.dev);

Oh no, this is not allowed. pm_runtime_get_sync() can sleep and issue_pending can be invoked from atomic context.

OK. I didn't know that. I'll try pm_runtime_get first. If it fails, I'll post a task to do the real job with pm_runtime_get_sync.

The clocks may be off by the time the request is made. I need to grab the PM lock before accessing the HW registers.

Quoted 13 lines

drivers/dma/qcom/hidma.c line 241

Quoted 9 lines
drivers/dma/qcom/hidma.c new file +8 -0
+static enum dma_status hidma_tx_status(struct dma_chan *dmach,
+			dma_cookie_t cookie, struct dma_tx_state *txstate)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	enum dma_status ret;
+
+	if (mchan->paused)
+		ret = DMA_PAUSED;

This is not quite right. The status query is for a descriptor and NOT for channel. Here if the descriptor queried was running then it would be paused for the rest pending txn, it would be DMA_IN_PROGRESS.

The channel can be paused by the hypervisor. If it is paused, then no other transaction will go through including the pending requests. That's why, I'm checking the state first.

Quoted 14 lines

drivers/dma/qcom/hidma.c line 261

Quoted 11 lines
drivers/dma/qcom/hidma.c new file +10 -0
+static dma_cookie_t hidma_tx_submit(struct dma_async_tx_descriptor *txd)
+{
+	struct hidma_chan *mchan = to_hidma_chan(txd->chan);
+	struct hidma_dev *dmadev = mchan->dmadev;
+	struct hidma_desc *mdesc;
+	unsigned long irqflags;
+	dma_cookie_t cookie;
+
+	if (!hidma_ll_isenabled(dmadev->lldev))
+		return -ENODEV;

is this not too late for this check, you should fail this on prepare method

The channels can be paused by the hypervisor at runtime after the guest OS boot. The client might have allocated the channels during guest machine boot. If a channel is paused and client makes a request, client will never get the callback. By placing this check, I'm looking at the runtime status of the channel and rejecting the transmit request right ahead.

Quoted 12 lines
Quoted 12 lines
drivers/dma/qcom/hidma.c new file +10 -0
+static int hidma_alloc_chan_resources(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	struct hidma_dev *dmadev = mchan->dmadev;
+	struct hidma_desc *mdesc, *tmp;
+	unsigned long irqflags;
+	LIST_HEAD(descs);
+	unsigned int i;
+	int rc = 0;
+
Quoted 8 lines

drivers/dma/qcom/hidma.c line 293

Quoted 6 lines
drivers/dma/qcom/hidma.c new file +6 -0
+	if (mchan->allocated)
+		return 0;
+
+	/* Alloc descriptors for this channel */
+	for (i = 0; i < dmadev->nr_descriptors; i++) {
+		mdesc = kzalloc(sizeof(struct hidma_desc), GFP_KERNEL);

GFP_NOWAIT pls, this can be called from atomic context

I'll change it, but why would anyone allocate a channel in an interrupt handler?

Quoted 9 lines

drivers/dma/qcom/hidma.c line 299

Quoted 7 lines
drivers/dma/qcom/hidma.c new file +6 -0
+		if (!mdesc) {
+			rc = -ENOMEM;
+			break;
+		}
+		dma_async_tx_descriptor_init(&mdesc->desc, dmach);
+		mdesc->desc.flags = DMA_CTRL_ACK;

what is the purpose of setting this flag here

It means that the code only supports interrupt. Maybe, you can correct me here. I couldn't see a very useful info about the DMA engine flags. My understanding is that DMA_CTRL_ACK means user wants an interrupt based callback.

If DMA_CTRL_ACK is not specified, then user wants to poll for the results. The current code only supports the interrupt based delivery for callbacks. Polling support is another to-do in my list for small sized transfers.

Quoted 16 lines
Quoted 4 lines
drivers/dma/qcom/hidma.c new file +3 -0
+static void hidma_free_chan_resources(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);

drivers/dma/qcom/hidma.c line 341

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+	struct hidma_dev *mdma = mchan->dmadev;
+	struct hidma_desc *mdesc, *tmp;
+	unsigned long irqflags;
+	LIST_HEAD(descs);
+
+	if (!list_empty(&mchan->prepared) || !list_empty(&mchan->active) ||
+		!list_empty(&mchan->completed)) {
+		/*
+		 * We have unfinished requests waiting.
+		 * Terminate the request from the hardware.

that sounds as bug.. free should be called when txn are completed/aborted

Let me see what other drivers are doing...

Quoted 26 lines

drivers/dma/qcom/hidma.c line 347

Quoted 7 lines
drivers/dma/qcom/hidma.c new file +6 -0
+		 */
+		hidma_cleanup_pending_tre(mdma->lldev, ERR_INFO_SW,
+					ERR_CODE_UNEXPECTED_TERMINATE);
+
+		/* Give enough time for completions to be called. */
+		msleep(100);

should we not poll/read after delay, also we are still in atomic context

drivers/dma/qcom/hidma.c line 351

Quoted 4 lines
drivers/dma/qcom/hidma.c new file +4 -0
+	}
+
+	spin_lock_irqsave(&mchan->lock, irqflags);
+	/* Channel must be idle */

sorry I do not like that assumption

Quoted 9 lines
drivers/dma/qcom/hidma.c new file +9 -0
+	/* return all user requests */
+	list_for_each_entry_safe(mdesc, tmp, &list, node) {
+		struct dma_async_tx_descriptor *txd = &mdesc->desc;
+		dma_async_tx_callback callback = mdesc->desc.callback;
+		void *param = mdesc->desc.callback_param;
+		enum dma_status status;
+
+		dma_descriptor_unmap(txd);
+
Quoted 8 lines

drivers/dma/qcom/hidma.c line 444

Quoted 5 lines
drivers/dma/qcom/hidma.c new file +5 -0
+		status = hidma_ll_status(dmadev->lldev, mdesc->tre_ch);
+		/*
+		 * The API requires that no submissions are done from a
+		 * callback, so we don't need to drop the lock here
+		 */

That is correct assumption for async_tx and which is deprecated now. In fact the converse is true for rest!

I copied this function from another driver. The cookie/unmap business seemed scary to me. Can you point me to a good/recent implementation if this is deprecated?

Quoted 13 lines
Quoted 13 lines
drivers/dma/qcom/hidma.c new file +12 -0
+static int hidma_pause(struct dma_chan *chan)
+{
+	struct hidma_chan *mchan;
+	struct hidma_dev *dmadev;
+
+	mchan = to_hidma_chan(chan);
+	dmadev = to_hidma_dev(mchan->chan.device);
+	if (!mchan->paused) {
+		pm_runtime_get_sync(dmadev->ddev.dev);
+		if (hidma_ll_pause(dmadev->lldev))
+			dev_warn(dmadev->ddev.dev, "channel did not stop\n");
+		mchan->paused = true;
Quoted 8 lines

drivers/dma/qcom/hidma.c line 222

Quoted 5 lines
drivers/dma/qcom/hidma.c new file +5 -0
+		pm_runtime_mark_last_busy(dmadev->ddev.dev);
+		pm_runtime_put_autosuspend(dmadev->ddev.dev);
+	}
+	return 0;
+}

This is interesting, we associate pause/resume for slave dma ops and not for memcpy ops, what is the reason for adding pause/resume here?

Why is it limited to the slave device only? I can queue a bunch of requests. I can pause and resume their execution with the current implementation.

Quoted 17 lines
Quoted 4 lines
drivers/dma/qcom/hidma.c new file +3 -0
+static int hidma_remove(struct platform_device *pdev)
+{
+	struct hidma_dev *dmadev = platform_get_drvdata(pdev);

drivers/dma/qcom/hidma.c line 676

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+
+	pm_runtime_get_sync(dmadev->ddev.dev);
+	dma_async_device_unregister(&dmadev->ddev);
+	hidma_debug_uninit(dmadev);
+	hidma_ll_uninit(dmadev->lldev);
+	hidma_free(dmadev);
+
+	dev_info(&pdev->dev, "HI-DMA engine removed\n");
+	pm_runtime_put_sync_suspend(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);

and your irq is still active and can invoke your irq handler!

why? I shutdown the IRQ in hidma_ll_uninit and request the interrupt with devm_request_irq. As soon as this driver is removed, the interrupt should be released by the managed code.

Quoted 10 lines

drivers/dma/qcom/hidma.c line 683

Quoted 7 lines
drivers/dma/qcom/hidma.c new file +7 -0
+
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id hidma_acpi_ids[] = {
+	{"QCOM8061"},

Qcom and ACPI, that is v interesting combination !

Thanks for the detailed review.

Signature · 4 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
#16 lore raw

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

Quoted 4 lines · Sinan Kaya

I have split the debugfs support from this patch to its own patch. Any other idea on how else you'd break the code? I can take one more step and separate the lower layer from the OS layer by using stub functions on the initial commit.

Yes the ll.c can be a separate patch and no need to add placeholders as makefile can be last

Quoted 14 lines
Quoted 13 lines

drivers/dma/qcom/hidma.c line 241

Quoted 9 lines
drivers/dma/qcom/hidma.c new file +8 -0
+static enum dma_status hidma_tx_status(struct dma_chan *dmach,
+			dma_cookie_t cookie, struct dma_tx_state *txstate)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	enum dma_status ret;
+
+	if (mchan->paused)
+		ret = DMA_PAUSED;

This is not quite right. The status query is for a descriptor and NOT for channel. Here if the descriptor queried was running then it would be paused for the rest pending txn, it would be DMA_IN_PROGRESS.

Quoted 3 lines

The channel can be paused by the hypervisor. If it is paused, then no other transaction will go through including the pending requests. That's why, I'm checking the state first.

You are missing the point. Channel can be paused, yes but the descriptor is in queue and is not paused. The descriptor running is paused, yes. There is subtle difference between these

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/dma/qcom/hidma.c new file +5 -0
+static dma_cookie_t hidma_tx_submit(struct dma_async_tx_descriptor *txd)
+{
+	struct hidma_chan *mchan = to_hidma_chan(txd->chan);
+	struct hidma_dev *dmadev = mchan->dmadev;
+	struct hidma_desc *mdesc;
Quoted 8 lines

drivers/dma/qcom/hidma.c line 261

Quoted 5 lines
drivers/dma/qcom/hidma.c new file +5 -0
+	unsigned long irqflags;
+	dma_cookie_t cookie;
+
+	if (!hidma_ll_isenabled(dmadev->lldev))
+		return -ENODEV;

is this not too late for this check, you should fail this on prepare method

Quoted 6 lines

The channels can be paused by the hypervisor at runtime after the guest OS boot. The client might have allocated the channels during guest machine boot. If a channel is paused and client makes a request, client will never get the callback. By placing this check, I'm looking at the runtime status of the channel and rejecting the transmit request right ahead.

In this case you have request already given to you, here the request is submitted to the pending queue, if hypervisor has paused you, so the entire txn queue is paused. But from API semantics I would argue that this should be accepted and suffer the same fate as already submitted txns

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/dma/qcom/hidma.c new file +10 -0
+static int hidma_alloc_chan_resources(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	struct hidma_dev *dmadev = mchan->dmadev;
+	struct hidma_desc *mdesc, *tmp;
+	unsigned long irqflags;
+	LIST_HEAD(descs);
+	unsigned int i;
+	int rc = 0;
+
Quoted 8 lines

drivers/dma/qcom/hidma.c line 293

Quoted 6 lines
drivers/dma/qcom/hidma.c new file +6 -0
+	if (mchan->allocated)
+		return 0;
+
+	/* Alloc descriptors for this channel */
+	for (i = 0; i < dmadev->nr_descriptors; i++) {
+		mdesc = kzalloc(sizeof(struct hidma_desc), GFP_KERNEL);

GFP_NOWAIT pls, this can be called from atomic context

Quoted 2 lines

I'll change it, but why would anyone allocate a channel in an interrupt handler?

remember this is dmaengine, where people traditionally wanted to offload from cpu and were not allowed to sleep.

I think am okay with this one..

Quoted 11 lines
Quoted 10 lines

drivers/dma/qcom/hidma.c line 299

Quoted 8 lines
drivers/dma/qcom/hidma.c new file +6 -0
+		if (!mdesc) {
+			rc = -ENOMEM;
+			break;
+		}
+		dma_async_tx_descriptor_init(&mdesc->desc, dmach);
+		mdesc->desc.flags = DMA_CTRL_ACK;

what is the purpose of setting this flag here

Quoted 4 lines

It means that the code only supports interrupt. Maybe, you can correct me here. I couldn't see a very useful info about the DMA engine flags. My understanding is that DMA_CTRL_ACK means user wants an interrupt based callback.

Right user wants, you are not user though

Quoted 5 lines

If DMA_CTRL_ACK is not specified, then user wants to poll for the results. The current code only supports the interrupt based delivery for callbacks. Polling support is another to-do in my list for small sized transfers.

See the documentation for flags and usage. The point here is that user should set this. I know some old driver do this but that is not right

Quoted 83 lines
Quoted 17 lines
Quoted 5 lines
drivers/dma/qcom/hidma.c new file +3 -0
+static void hidma_free_chan_resources(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);

drivers/dma/qcom/hidma.c line 341

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+	struct hidma_dev *mdma = mchan->dmadev;
+	struct hidma_desc *mdesc, *tmp;
+	unsigned long irqflags;
+	LIST_HEAD(descs);
+
+	if (!list_empty(&mchan->prepared) || !list_empty(&mchan->active) ||
+		!list_empty(&mchan->completed)) {
+		/*
+		 * We have unfinished requests waiting.
+		 * Terminate the request from the hardware.

that sounds as bug.. free should be called when txn are completed/aborted

Let me see what other drivers are doing...

Quoted 26 lines

drivers/dma/qcom/hidma.c line 347

Quoted 7 lines
drivers/dma/qcom/hidma.c new file +6 -0
+		 */
+		hidma_cleanup_pending_tre(mdma->lldev, ERR_INFO_SW,
+					ERR_CODE_UNEXPECTED_TERMINATE);
+
+		/* Give enough time for completions to be called. */
+		msleep(100);

should we not poll/read after delay, also we are still in atomic context

drivers/dma/qcom/hidma.c line 351

Quoted 4 lines
drivers/dma/qcom/hidma.c new file +4 -0
+	}
+
+	spin_lock_irqsave(&mchan->lock, irqflags);
+	/* Channel must be idle */

sorry I do not like that assumption

Quoted 9 lines
drivers/dma/qcom/hidma.c new file +9 -0
+	/* return all user requests */
+	list_for_each_entry_safe(mdesc, tmp, &list, node) {
+		struct dma_async_tx_descriptor *txd = &mdesc->desc;
+		dma_async_tx_callback callback = mdesc->desc.callback;
+		void *param = mdesc->desc.callback_param;
+		enum dma_status status;
+
+		dma_descriptor_unmap(txd);
+
Quoted 8 lines

drivers/dma/qcom/hidma.c line 444

Quoted 5 lines
drivers/dma/qcom/hidma.c new file +5 -0
+		status = hidma_ll_status(dmadev->lldev, mdesc->tre_ch);
+		/*
+		 * The API requires that no submissions are done from a
+		 * callback, so we don't need to drop the lock here
+		 */

That is correct assumption for async_tx and which is deprecated now. In fact the converse is true for rest!

I copied this function from another driver. The cookie/unmap business seemed scary to me. Can you point me to a good/recent implementation if this is deprecated?

Quoted 13 lines
Quoted 13 lines
drivers/dma/qcom/hidma.c new file +12 -0
+static int hidma_pause(struct dma_chan *chan)
+{
+	struct hidma_chan *mchan;
+	struct hidma_dev *dmadev;
+
+	mchan = to_hidma_chan(chan);
+	dmadev = to_hidma_dev(mchan->chan.device);
+	if (!mchan->paused) {
+		pm_runtime_get_sync(dmadev->ddev.dev);
+		if (hidma_ll_pause(dmadev->lldev))
+			dev_warn(dmadev->ddev.dev, "channel did not stop\n");
+		mchan->paused = true;
Quoted 8 lines

drivers/dma/qcom/hidma.c line 222

Quoted 5 lines
drivers/dma/qcom/hidma.c new file +5 -0
+		pm_runtime_mark_last_busy(dmadev->ddev.dev);
+		pm_runtime_put_autosuspend(dmadev->ddev.dev);
+	}
+	return 0;
+}

This is interesting, we associate pause/resume for slave dma ops and not for memcpy ops, what is the reason for adding pause/resume here?

Quoted 3 lines

Why is it limited to the slave device only? I can queue a bunch of requests. I can pause and resume their execution with the current implementation.

Traditionally no one paused memcpy... People want the copy to be done with as fast as possible :)

Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
drivers/dma/qcom/hidma.c new file +3 -0
+static int hidma_remove(struct platform_device *pdev)
+{
+	struct hidma_dev *dmadev = platform_get_drvdata(pdev);

drivers/dma/qcom/hidma.c line 676

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+
+	pm_runtime_get_sync(dmadev->ddev.dev);
+	dma_async_device_unregister(&dmadev->ddev);
+	hidma_debug_uninit(dmadev);
+	hidma_ll_uninit(dmadev->lldev);
+	hidma_free(dmadev);
+
+	dev_info(&pdev->dev, "HI-DMA engine removed\n");
+	pm_runtime_put_sync_suspend(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);

and your irq is still active and can invoke your irq handler!

Quoted 3 lines

why? I shutdown the IRQ in hidma_ll_uninit and request the interrupt with devm_request_irq. As soon as this driver is removed, the interrupt should be released by the managed code.

but there is a delay between that and free getting called. Since you don't free up explicitly you can still have irq and tasklets scheduled.

Recommendation is that free up irq or ensure none are scheduled and disabled

Signature · 1 line
~Vinod
author
#17 lore raw

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

Quoted 9 lines · Vinod Koul
Quoted 4 lines · Sinan Kaya

I have split the debugfs support from this patch to its own patch. Any other idea on how else you'd break the code? I can take one more step and separate the lower layer from the OS layer by using stub functions on the initial commit.

Yes the ll.c can be a separate patch and no need to add placeholders as makefile can be last

ok. I'll create a new patch file with the Makefile and hidma_ll.c only.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

drivers/dma/qcom/hidma.c line 241

Quoted 9 lines
drivers/dma/qcom/hidma.c new file +8 -0
+static enum dma_status hidma_tx_status(struct dma_chan *dmach,
+			dma_cookie_t cookie, struct dma_tx_state *txstate)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	enum dma_status ret;
+
+	if (mchan->paused)
+		ret = DMA_PAUSED;

This is not quite right. The status query is for a descriptor and NOT for channel. Here if the descriptor queried was running then it would be paused for the rest pending txn, it would be DMA_IN_PROGRESS.

Quoted 7 lines
Quoted 3 lines

The channel can be paused by the hypervisor. If it is paused, then no other transaction will go through including the pending requests. That's why, I'm checking the state first.

You are missing the point. Channel can be paused, yes but the descriptor is in queue and is not paused. The descriptor running is paused, yes. There is subtle difference between these

I'll follow your recommendation. PAUSE for the currently active descriptor and DMA_IN_PROGRESS for the rest.

Quoted 22 lines
Quoted 15 lines
Quoted 14 lines

drivers/dma/qcom/hidma.c line 261

Quoted 11 lines
drivers/dma/qcom/hidma.c new file +10 -0
+static dma_cookie_t hidma_tx_submit(struct dma_async_tx_descriptor *txd)
+{
+	struct hidma_chan *mchan = to_hidma_chan(txd->chan);
+	struct hidma_dev *dmadev = mchan->dmadev;
+	struct hidma_desc *mdesc;
+	unsigned long irqflags;
+	dma_cookie_t cookie;
+
+	if (!hidma_ll_isenabled(dmadev->lldev))
+		return -ENODEV;

is this not too late for this check, you should fail this on prepare method

Quoted 6 lines

The channels can be paused by the hypervisor at runtime after the guest OS boot. The client might have allocated the channels during guest machine boot. If a channel is paused and client makes a request, client will never get the callback. By placing this check, I'm looking at the runtime status of the channel and rejecting the transmit request right ahead.

Quoted 2 lines

In this case you have request already given to you, here the request is submitted to the pending queue,

No, it is not. Putting into the pending queue is done after this check not before.

I'm rejecting the queue request directly here as HIDMA channel is no longer functional. I'd rather do active error handling rather than passive error handling. Debugging of passive faults are much more difficult.

Quoted 48 lines

if hypervisor has paused you, so the entire
txn queue is paused. But from API semantics I would argue that this should be accepted and suffer the same fate as already submitted txns

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/dma/qcom/hidma.c new file +10 -0
+static int hidma_alloc_chan_resources(struct dma_chan *dmach)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	struct hidma_dev *dmadev = mchan->dmadev;
+	struct hidma_desc *mdesc, *tmp;
+	unsigned long irqflags;
+	LIST_HEAD(descs);
+	unsigned int i;
+	int rc = 0;
+
Quoted 8 lines

drivers/dma/qcom/hidma.c line 293

Quoted 6 lines
drivers/dma/qcom/hidma.c new file +6 -0
+	if (mchan->allocated)
+		return 0;
+
+	/* Alloc descriptors for this channel */
+	for (i = 0; i < dmadev->nr_descriptors; i++) {
+		mdesc = kzalloc(sizeof(struct hidma_desc), GFP_KERNEL);

GFP_NOWAIT pls, this can be called from atomic context

Quoted 2 lines

I'll change it, but why would anyone allocate a channel in an interrupt handler?

remember this is dmaengine, where people traditionally wanted to offload from cpu and were not allowed to sleep.

I think am okay with this one..

Quoted 11 lines
Quoted 10 lines

drivers/dma/qcom/hidma.c line 299

Quoted 8 lines
drivers/dma/qcom/hidma.c new file +6 -0
+		if (!mdesc) {
+			rc = -ENOMEM;
+			break;
+		}
+		dma_async_tx_descriptor_init(&mdesc->desc, dmach);
+		mdesc->desc.flags = DMA_CTRL_ACK;

what is the purpose of setting this flag here

Quoted 7 lines
Quoted 4 lines

It means that the code only supports interrupt. Maybe, you can correct me here. I couldn't see a very useful info about the DMA engine flags. My understanding is that DMA_CTRL_ACK means user wants an interrupt based callback.

Right user wants, you are not user though

Fair enough.

Quoted 9 lines
Quoted 5 lines

If DMA_CTRL_ACK is not specified, then user wants to poll for the results. The current code only supports the interrupt based delivery for callbacks. Polling support is another to-do in my list for small sized transfers.

See the documentation for flags and usage. The point here is that user should set this. I know some old driver do this but that is not right

I'll remove it.

Quoted 24 lines
Quoted 20 lines
Quoted 19 lines
Quoted 6 lines
drivers/dma/qcom/hidma.c new file +3 -0
+static int hidma_remove(struct platform_device *pdev)
+{
+	struct hidma_dev *dmadev = platform_get_drvdata(pdev);

drivers/dma/qcom/hidma.c line 676

Quoted 10 lines
drivers/dma/qcom/hidma.c new file +10 -0
+
+	pm_runtime_get_sync(dmadev->ddev.dev);
+	dma_async_device_unregister(&dmadev->ddev);
+	hidma_debug_uninit(dmadev);
+	hidma_ll_uninit(dmadev->lldev);
+	hidma_free(dmadev);
+
+	dev_info(&pdev->dev, "HI-DMA engine removed\n");
+	pm_runtime_put_sync_suspend(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);

and your irq is still active and can invoke your irq handler!

Quoted 3 lines

why? I shutdown the IRQ in hidma_ll_uninit and request the interrupt with devm_request_irq. As soon as this driver is removed, the interrupt should be released by the managed code.

Quoted 6 lines

but there is a delay between that and free getting called. Since you don't free up explicitly you can still have irq and tasklets scheduled.

Recommendation is that free up irq or ensure none are scheduled and disabled

I looked at other drivers. They seem to be disabling the IRQ right after unregistering the DMA device from DMA engine. I'll follow the same by adding an explicit dma_free_irq call into hidma_remove function.

Signature · 4 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
#18 lore raw

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

Quoted 18 lines · Sinan Kaya
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 17 lines
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines

drivers/dma/qcom/hidma.c line 241

Quoted 9 lines
drivers/dma/qcom/hidma.c new file +8 -0
+static enum dma_status hidma_tx_status(struct dma_chan *dmach,
+			dma_cookie_t cookie, struct dma_tx_state *txstate)
+{
+	struct hidma_chan *mchan = to_hidma_chan(dmach);
+	enum dma_status ret;
+
+	if (mchan->paused)
+		ret = DMA_PAUSED;

This is not quite right. The status query is for a descriptor and NOT for channel. Here if the descriptor queried was running then it would be paused for the rest pending txn, it would be DMA_IN_PROGRESS.

The channel can be paused by the hypervisor. If it is paused, then no other transaction will go through including the pending requests. That's why, I'm checking the state first.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

You are missing the point. Channel can be paused, yes but the descriptor is in queue and is not paused. The descriptor running is paused, yes. There is subtle difference between these

I'll follow your recommendation. PAUSE for the currently active descriptor and DMA_IN_PROGRESS for the rest.

I'm now confused.

I looked at several DMA driver implementations.

1. They call dma_cookie_status function to see if the job is done.
2. If done, they return right ahead.
3. Otherwise, dma_cookie_status returns DMA_IN_PROGRESS.
4. Next the code checks if the channel is paused and return value is DMA_IN_PROGRESS. The code changes return code to DMA_PAUSED.

Whereas, I was returning paused first before even checking if the descriptor is done. Are you OK with the sequence 1..4 above?

Signature · 4 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 V7 3/3] dma: add Qualcomm Technologies HIDMA channel driver

Quoted 11 lines · Sinan Kaya
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

You are missing the point. Channel can be paused, yes but the descriptor is in queue and is not paused. The descriptor running is paused, yes. There is subtle difference between these

I'll follow your recommendation. PAUSE for the currently active descriptor and DMA_IN_PROGRESS for the rest.

I'm now confused.

I looked at several DMA driver implementations.

Quoted 8 lines

1. They call dma_cookie_status function to see if the job is done.
2. If done, they return right ahead.
3. Otherwise, dma_cookie_status returns DMA_IN_PROGRESS.
4. Next the code checks if the channel is paused and return value is DMA_IN_PROGRESS. The code changes return code to DMA_PAUSED.

Whereas, I was returning paused first before even checking if the descriptor is done. Are you OK with the sequence 1..4 above?

Yes am okay with this with slight change in 4.

You should set to PAUSED only for current descriptor and not for the ones in queue

Signature · 1 line
~Vinod
author
#20 lore raw

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

Quoted 18 lines · Vinod Koul
Quoted 17 lines · Sinan Kaya
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

You are missing the point. Channel can be paused, yes but the descriptor is in queue and is not paused. The descriptor running is paused, yes. There is subtle difference between these

I'll follow your recommendation. PAUSE for the currently active descriptor and DMA_IN_PROGRESS for the rest.

I'm now confused.

I looked at several DMA driver implementations.

1. They call dma_cookie_status function to see if the job is done.
2. If done, they return right ahead.
3. Otherwise, dma_cookie_status returns DMA_IN_PROGRESS.
4. Next the code checks if the channel is paused and return value is DMA_IN_PROGRESS. The code changes return code to DMA_PAUSED.

Quoted 8 lines
Quoted 2 lines

Whereas, I was returning paused first before even checking if the descriptor is done. Are you OK with the sequence 1..4 above?

Yes am okay with this with slight change in 4.

You should set to PAUSED only for current descriptor and not for the ones in queue

OK, I'll work on it.

Signature · 4 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
#21 lore raw

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

In reply to Vinod Koul
Quoted 18 lines · Vinod Koul
Quoted 17 lines · Sinan Kaya
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

You are missing the point. Channel can be paused, yes but the descriptor is in queue and is not paused. The descriptor running is paused, yes. There is subtle difference between these

I'll follow your recommendation. PAUSE for the currently active descriptor and DMA_IN_PROGRESS for the rest.

I'm now confused.

I looked at several DMA driver implementations.

1. They call dma_cookie_status function to see if the job is done.
2. If done, they return right ahead.
3. Otherwise, dma_cookie_status returns DMA_IN_PROGRESS.
4. Next the code checks if the channel is paused and return value is DMA_IN_PROGRESS. The code changes return code to DMA_PAUSED.

Quoted 8 lines
Quoted 2 lines

Whereas, I was returning paused first before even checking if the descriptor is done. Are you OK with the sequence 1..4 above?

Yes am okay with this with slight change in 4.

You should set to PAUSED only for current descriptor and not for the ones in queue

OK. I'll post a new version with this. Is there any other comment that needed to be addressed?

Signature · 4 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
#22 lore raw

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

Quoted 22 lines · Sinan Kaya
Quoted 21 lines · Vinod Koul
Quoted 19 lines · Sinan Kaya
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

You are missing the point. Channel can be paused, yes but the descriptor is in queue and is not paused. The descriptor running is paused, yes. There is subtle difference between these

I'll follow your recommendation. PAUSE for the currently active descriptor and DMA_IN_PROGRESS for the rest.

I'm now confused.

I looked at several DMA driver implementations.

1. They call dma_cookie_status function to see if the job is done.
2. If done, they return right ahead.
3. Otherwise, dma_cookie_status returns DMA_IN_PROGRESS.
4. Next the code checks if the channel is paused and return value is DMA_IN_PROGRESS. The code changes return code to DMA_PAUSED.

Whereas, I was returning paused first before even checking if the descriptor is done. Are you OK with the sequence 1..4 above?

Quoted 8 lines
Quoted 5 lines

Yes am okay with this with slight change in 4.

You should set to PAUSED only for current descriptor and not for the ones in queue

OK. I'll post a new version with this. Is there any other comment that needed to be addressed?

Looks okay to me

Signature · 1 line
~Vinod
author
#23 lore raw

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

Quoted 25 lines · Vinod Koul
Quoted 24 lines · Sinan Kaya
Quoted 23 lines · Vinod Koul
Quoted 11 lines · Sinan Kaya
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

You are missing the point. Channel can be paused, yes but the descriptor is in queue and is not paused. The descriptor running is paused, yes. There is subtle difference between these

I'll follow your recommendation. PAUSE for the currently active descriptor and DMA_IN_PROGRESS for the rest.

I'm now confused.

I looked at several DMA driver implementations.

Quoted 8 lines

1. They call dma_cookie_status function to see if the job is done.
2. If done, they return right ahead.
3. Otherwise, dma_cookie_status returns DMA_IN_PROGRESS.
4. Next the code checks if the channel is paused and return value is DMA_IN_PROGRESS. The code changes return code to DMA_PAUSED.

Whereas, I was returning paused first before even checking if the descriptor is done. Are you OK with the sequence 1..4 above?

Yes am okay with this with slight change in 4.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

You should set to PAUSED only for current descriptor and not for the ones in queue

OK. I'll post a new version with this. Is there any other comment that needed to be addressed?

Looks okay to me

Vinod, Mark;
Just posted a new series (V10) https://lkml.org/lkml/2015/12/17/447 that addresses Mark Rutland and your concern.

Can you please review the series and queue for inclusion if you are OK? Sinan

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