Skip to contentSkip to conversation

dma: add Qualcomm Technologies HIDMA driver

PATCH Superseded Sinan Kaya 2 participants 8 messages Nov 22, 2015 – Nov 23, 2015

Subsystems (4)

v6 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

v6 cover dma: add Qualcomm Technologies HIDMA driver

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 V5: (https://lkml.org/lkml/2015/11/15/135)
* none

Changes from V5: (https://lkml.org/lkml/2015/11/15/136)
* forgot to remove duplicate rc assignment.
* add missing _iomem from sparse warning.
* Add sysfs ABI documentation

Changes from V5: (https://lkml.org/lkml/2015/11/15/137)
* Remove pm lock in ISR as it is redundant caught in lockdep.
* sparse warning for missing _iomem.
* sparse warning for static required.

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                           | 710 ++++++++++++++++
 drivers/dma/qcom/hidma.h                           | 157 ++++
 drivers/dma/qcom/hidma_dbg.c                       | 225 +++++
 drivers/dma/qcom/hidma_ll.c                        | 930 +++++++++++++++++++++
 drivers/dma/qcom/hidma_mgmt.c                      | 305 +++++++
 drivers/dma/qcom/hidma_mgmt.h                      |  38 +
 drivers/dma/qcom/hidma_mgmt_sys.c                  | 231 +++++
 15 files changed, 2810 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 v6 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                       |  9 +++++++++
 drivers/dma/qcom/Makefile                      |  1 +
 drivers/dma/{qcom_bam_dma.c => qcom/bam_dma.c} |  4 ++--
 5 files changed, 15 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 +9 -0
new file mode 100644
index 0000000..17545df
@@ -0,0 +1,9 @@
+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
#2 lore raw

PATCH v6 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.

v6
------------
* forgot to remove duplicate rc assignment.
* add missing _iomem from sparse warning.

---
 .../ABI/testing/sysfs-platform-hidma-mgmt          |  97 +++++++
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  61 +++++
 drivers/dma/qcom/Kconfig                           |  10 +
 drivers/dma/qcom/Makefile                          |   1 +
 drivers/dma/qcom/hidma_mgmt.c                      | 305 +++++++++++++++++++++
 drivers/dma/qcom/hidma_mgmt.h                      |  38 +++
 drivers/dma/qcom/hidma_mgmt_sys.c                  | 231 ++++++++++++++++
 7 files changed, 743 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..f6f1ce1
@@ -0,0 +1,97 @@
+What:		/sys/devices/platform/hidma-mgmt*/channel*_priority
+		/sys/devices/platform/QCOM8060:*/channel*_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*/channel*_weight
+		/sys/devices/platform/QCOM8060:*/channel*__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 +10 -0
index 17545df..ebe5b8c 100644
@@ -7,3 +7,13 @@ config QCOM_BAM_DMA
 	  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 +305 -0

305 lines not on this page · raw message

drivers/dma/qcom/hidma_mgmt.h new file +38 -0
new file mode 100644
index 0000000..04340ff
@@ -0,0 +1,38 @@
+/*
+ * 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 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 +231 -0

231 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
#3 lore raw

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

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

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

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

Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-hidma-mgmt new file +2 -0
+What:          /sys/devices/platform/hidma-mgmt*/channel*_weight
+               /sys/devices/platform/QCOM8060:*/channel*__weight

Extra _ ?

Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +7 -0
+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.

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

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+
+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.

Hmm? Can lines be longer up to 76-78 characters?

drivers/dma/qcom/hidma_mgmt.c line 40

Quoted 5 lines
drivers/dma/qcom/hidma_mgmt.c new file +5 -0
+#define MAX_WR_XACTIONS_MASK           0x1F
+#define MAX_RD_XACTIONS_MASK           0x1F
+#define WEIGHT_MASK                    0x7F
+#define MAX_BUS_REQ_LEN_MASK           0xFFFF
+#define CHRESET_TIMEOUUT_MASK          0xFFFFF

GENMASK?

drivers/dma/qcom/hidma_mgmt.c line 56

Quoted 7 lines
drivers/dma/qcom/hidma_mgmt.c new file +7 -0
+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) ||

Someone likes parens.
I might agree with these cases, but below in assignments and combined operations the parens are indeed redundant.

drivers/dma/qcom/hidma_mgmt.c line 65

Quoted 9 lines
drivers/dma/qcom/hidma_mgmt.c new file +9 -0
+               (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)) {

Ditto.

Quoted 32 lines
drivers/dma/qcom/hidma_mgmt.c new file +32 -0
+               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 %d\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 %d\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;
+               }
+

drivers/dma/qcom/hidma_mgmt.c line 106

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt.c new file +9 -0
+               /* 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);

Ditto.

Quoted 1 line

+ val &= ~(MAX_BUS_REQ_LEN_MASK);

Ditto.

Quoted 1 line

+ val |= (mgmtdev->max_read_request);

Ditto.

drivers/dma/qcom/hidma_mgmt.c line 115

Quoted 8 lines
drivers/dma/qcom/hidma_mgmt.c new file +7 -0
+       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);

Ditto for all 3 above.

drivers/dma/qcom/hidma_mgmt.c line 123

Quoted 8 lines
drivers/dma/qcom/hidma_mgmt.c new file +8 -0
+       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++) {
+               val = readl(mgmtdev->virtaddr + QOS_N_OFFSET + (4 * i));

Ditto.

drivers/dma/qcom/hidma_mgmt.c line 128

Quoted 5 lines
drivers/dma/qcom/hidma_mgmt.c new file +5 -0
+               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));

Ditto.

drivers/dma/qcom/hidma_mgmt.c line 132

Quoted 4 lines
drivers/dma/qcom/hidma_mgmt.c new file +4 -0
+       }
+
+       val = readl(mgmtdev->virtaddr + CHRESET_TIMEOUT_OFFSET);
+       val &= ~CHRESET_TIMEOUUT_MASK;

Look here, you use it like it intuitively feels.

Quoted 1 line

+ val |= (mgmtdev->chreset_timeout_cycles & CHRESET_TIMEOUUT_MASK);

But here?

Quoted 12 lines
drivers/dma/qcom/hidma_mgmt.c new file +12 -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;

drivers/dma/qcom/hidma_mgmt.c line 155

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt.c new file +10 -0
+       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);

+empty line

Quoted 115 lines
drivers/dma/qcom/hidma_mgmt.c new file +115 -0
+       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,

drivers/dma/qcom/hidma_mgmt.c line 279

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt.c new file +9 -0
+                &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_disable(&pdev->dev);
+       pm_runtime_put_sync_suspend(&pdev->dev);

I'm not sure the sequence is logically correct, though it might work.

Quoted 156 lines
drivers/dma/qcom/hidma_mgmt.c new file +26 -0
+       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 +38 -0
new file mode 100644
index 0000000..04340ff
@@ -0,0 +1,38 @@
+/*
+ * 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 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 +80 -0
new file mode 100644
index 0000000..70d324e
@@ -0,0 +1,231 @@
+/*
+ * 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 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;

drivers/dma/qcom/hidma_mgmt_sys.c line 90

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +10 -0
+
+       tmp = mdev->weight[i];
+       mdev->weight[i] = val;
+       rc = hidma_mgmt_setup(mdev);
+       if (rc)
+               mdev->weight[i] = tmp;
+       return rc;
+}
+
+static struct fileinfo files[] = {

Perhaps hidma_mgmt_files ?

Quoted 32 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +32 -0
+       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)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct hidma_mgmt_dev *mdev = platform_get_drvdata(pdev);
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(files); i++) {
+               if (strcmp(attr->attr.name, files[i].name) == 0) {
+                       sprintf(buf, "%d\n", files[i].get(mdev));
+                       goto done;
+               }
+       }
+
+       for (i = 0; i < mdev->dma_channels; i++) {
+               char name[30];
+
+               sprintf(name, "channel%d_priority", i);
+               if (strcmp(attr->attr.name, name) == 0) {
+                       sprintf(buf, "%d\n", mdev->priority[i]);
+                       goto done;
+               }

drivers/dma/qcom/hidma_mgmt_sys.c line 132

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +10 -0
+
+               sprintf(name, "channel%d_weight", i);
+               if (strcmp(attr->attr.name, name) == 0) {
+                       sprintf(buf, "%d\n", mdev->weight[i]);
+                       goto done;
+               }
+       }
+
+done:
+       return strlen(buf);

buf might be uninitialized here. Have you got any warning from compiler?

Quoted 61 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +61 -0
+}
+
+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);
+       if (rc)
+               return rc;
+
+       for (i = 0; i < ARRAY_SIZE(files); i++) {
+               if (strcmp(attr->attr.name, files[i].name) == 0) {
+                       rc = files[i].set(mdev, tmp);
+                       if (rc)
+                               return rc;
+
+                       goto done;
+               }
+       }
+
+       for (i = 0; i < mdev->dma_channels; i++) {
+               char name[30];
+
+               sprintf(name, "channel%d_priority", i);
+               if (strcmp(attr->attr.name, name) == 0) {
+                       rc = set_priority(mdev, i, tmp);
+                       if (rc)
+                               return rc;
+                       goto done;
+               }
+
+               sprintf(name, "channel%d_weight", i);
+               if (strcmp(attr->attr.name, name) == 0) {
+                       rc = set_weight(mdev, i, 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;
+

drivers/dma/qcom/hidma_mgmt_sys.c line 203

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +10 -0
+       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);
+}
+
+

Extra empty line.

drivers/dma/qcom/hidma_mgmt_sys.c line 214

Quoted 11 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +11 -0
+int hidma_mgmt_init_sys(struct hidma_mgmt_dev *dev)
+{
+       unsigned int i;
+       int rc;
+
+       for (i = 0; i < ARRAY_SIZE(files); i++) {
+               rc = create_sysfs_entry(dev, files[i].name, files[i].mode);
+               if (rc)
+                       return rc;
+       }
+

Can it be like

/sys/?/DEVICExx/
channelYY/
attr1
attr2
?

?

I think it will be easier to handle in code and from user. (Similar way DMAEngine API does for slave DMA devices)

Quoted 17 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +17 -0
+       for (i = 0; i < dev->dma_channels; i++) {
+               char name[30];
+
+               sprintf(name, "channel%d_priority", i);
+               rc = create_sysfs_entry(dev, name, (S_IRUGO|S_IWUGO));
+               if (rc)
+                       return rc;
+
+               sprintf(name, "channel%d_weight", i);
+               rc = create_sysfs_entry(dev, name, (S_IRUGO|S_IWUGO));
+               if (rc)
+                       return rc;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(hidma_mgmt_init_sys);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

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

Quoted 16 lines · Sinan Kaya
Quoted 15 lines

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 8 lines

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

Quoted 6 lines

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

Documentation/ABI/testing/sysfs-platform-hidma-mgmt new file +2 -0
+What:          /sys/devices/platform/hidma-mgmt*/channel*_weight
+               /sys/devices/platform/QCOM8060:*/channel*__weight

Extra _ ?

Done.

Quoted 22 lines
Quoted 9 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +7 -0
+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.

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

Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt new file +10 -0
+
+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.

Hmm??? Can lines be longer up to 76-78 characters?

Quoted 7 lines

drivers/dma/qcom/hidma_mgmt.c line 40

Quoted 5 lines
drivers/dma/qcom/hidma_mgmt.c new file +5 -0
+#define MAX_WR_XACTIONS_MASK           0x1F
+#define MAX_RD_XACTIONS_MASK           0x1F
+#define WEIGHT_MASK                    0x7F
+#define MAX_BUS_REQ_LEN_MASK           0xFFFF
+#define CHRESET_TIMEOUUT_MASK          0xFFFFF

GENMASK?

done

Quoted 10 lines

drivers/dma/qcom/hidma_mgmt.c line 56

Quoted 8 lines
drivers/dma/qcom/hidma_mgmt.c new file +7 -0
+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) ||

Someone likes parens.

yes, I do. I don't trust compilers and also don't like to open holes for people making quick changes to code while ignoring the operator precedence for maintenance reasons.

Quoted 3 lines

I might agree with these cases, but below in assignments and combined operations the parens are indeed redundant.

OK. I think we are already in personal style of code zone now. I have already broken another review because you don't like for loops but rather have a while loop.

I'll leave ifs and change the assignments only. I'll need your reviewed-by once you are happy.

Quoted 54 lines

drivers/dma/qcom/hidma_mgmt.c line 65

Quoted 9 lines
drivers/dma/qcom/hidma_mgmt.c new file +9 -0
+               (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)) {

Ditto.

Quoted 41 lines
drivers/dma/qcom/hidma_mgmt.c new file +22 -0
+               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 %d\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 %d\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");

drivers/dma/qcom/hidma_mgmt.c new file +18 -0
+                       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);
Quoted 3 lines
Quoted 1 line

+ val |= (mgmtdev->max_write_request << MAX_BUS_WR_REQ_BIT_POS);

Ditto.

ok

Quoted 4 lines
Quoted 2 lines

+ val &= ~(MAX_BUS_REQ_LEN_MASK);

Ditto.

ok

Quoted 4 lines
Quoted 2 lines

+ val |= (mgmtdev->max_read_request);

Ditto.

ok

Quoted 11 lines

drivers/dma/qcom/hidma_mgmt.c line 115

Quoted 9 lines
drivers/dma/qcom/hidma_mgmt.c new file +7 -0
+       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);

Ditto for all 3 above.

alright

Quoted 47 lines

drivers/dma/qcom/hidma_mgmt.c line 123

Quoted 9 lines
drivers/dma/qcom/hidma_mgmt.c new file +8 -0
+       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++) {
+               val = readl(mgmtdev->virtaddr + QOS_N_OFFSET + (4 * i));

Ditto.

drivers/dma/qcom/hidma_mgmt.c line 128

Quoted 5 lines
drivers/dma/qcom/hidma_mgmt.c new file +5 -0
+               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));

Ditto.

drivers/dma/qcom/hidma_mgmt.c line 132

Quoted 4 lines
drivers/dma/qcom/hidma_mgmt.c new file +4 -0
+       }
+
+       val = readl(mgmtdev->virtaddr + CHRESET_TIMEOUT_OFFSET);
+       val &= ~CHRESET_TIMEOUUT_MASK;

Look here, you use it like it intuitively feels.

Quoted 1 line

+ val |= (mgmtdev->chreset_timeout_cycles & CHRESET_TIMEOUUT_MASK);

But here???

Quoted 16 lines
drivers/dma/qcom/hidma_mgmt.c new file +16 -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;
Quoted 8 lines

drivers/dma/qcom/hidma_mgmt.c line 155

Quoted 6 lines
drivers/dma/qcom/hidma_mgmt.c new file +6 -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);
+       pm_runtime_get_sync(&pdev->dev);

+empty line

added a new line for you. I don't know why.

Quoted 125 lines
Quoted 124 lines
drivers/dma/qcom/hidma_mgmt.c new file +69 -0
+       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);

drivers/dma/qcom/hidma_mgmt.c new file +7 -0
+       if (!mgmtdev->priority) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       mgmtdev->weight = devm_kcalloc(&pdev->dev,
+               mgmtdev->dma_channels, sizeof(*mgmtdev->weight),

GFP_KERNEL);

drivers/dma/qcom/hidma_mgmt.c new file +45 -0
+       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;
Quoted 6 lines

drivers/dma/qcom/hidma_mgmt.c line 279

Quoted 3 lines
drivers/dma/qcom/hidma_mgmt.c new file +3 -0
+out:
+       pm_runtime_disable(&pdev->dev);
+       pm_runtime_put_sync_suspend(&pdev->dev);

I'm not sure the sequence is logically correct, though it might work.

reversed

Quoted 162 lines
Quoted 162 lines
drivers/dma/qcom/hidma_mgmt.c new file +26 -0
+       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 +38 -0
new file mode 100644
index 0000000..04340ff
@@ -0,0 +1,38 @@
+/*
+ * 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 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 +58 -0
new file mode 100644
index 0000000..70d324e
@@ -0,0 +1,231 @@
+/*
+ * 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 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)

drivers/dma/qcom/hidma_mgmt_sys.c new file +26 -0
+{
+       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);
Quoted 8 lines

drivers/dma/qcom/hidma_mgmt_sys.c line 90

Quoted 6 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +6 -0
+       if (rc)
+               mdev->weight[i] = tmp;
+       return rc;
+}
+
+static struct fileinfo files[] = {

Perhaps hidma_mgmt_files ?

done

Quoted 11 lines
Quoted 11 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +10 -0
+       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)),
+};
+
Quoted 8 lines

drivers/dma/qcom/hidma_mgmt_sys.c line 107

Quoted 8 lines

+static ssize_t show_values(struct device *dev, struct device_attribute *attr,

drivers/dma/qcom/hidma_mgmt_sys.c new file +6 -0
+                               char *buf)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct hidma_mgmt_dev *mdev = platform_get_drvdata(pdev);
+       unsigned int i;
+

I'll initialize buf as

buf[0] = 0;

here.

Quoted 95 lines
Quoted 15 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +15 -0
+       for (i = 0; i < ARRAY_SIZE(files); i++) {
+               if (strcmp(attr->attr.name, files[i].name) == 0) {
+                       sprintf(buf, "%d\n", files[i].get(mdev));
+                       goto done;
+               }
+       }
+
+       for (i = 0; i < mdev->dma_channels; i++) {
+               char name[30];
+
+               sprintf(name, "channel%d_priority", i);
+               if (strcmp(attr->attr.name, name) == 0) {
+                       sprintf(buf, "%d\n", mdev->priority[i]);
+                       goto done;
+               }

drivers/dma/qcom/hidma_mgmt_sys.c line 132

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +10 -0
+
+               sprintf(name, "channel%d_weight", i);
+               if (strcmp(attr->attr.name, name) == 0) {
+                       sprintf(buf, "%d\n", mdev->weight[i]);
+                       goto done;
+               }
+       }
+
+done:
+       return strlen(buf);

buf might be uninitialized here. Have you got any warning from compiler?

Quoted 67 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +3 -0
+}
+
+static ssize_t set_values(struct device *dev, struct device_attribute

*attr,

drivers/dma/qcom/hidma_mgmt_sys.c new file +45 -0
+                               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);
+       if (rc)
+               return rc;
+
+       for (i = 0; i < ARRAY_SIZE(files); i++) {
+               if (strcmp(attr->attr.name, files[i].name) == 0) {
+                       rc = files[i].set(mdev, tmp);
+                       if (rc)
+                               return rc;
+
+                       goto done;
+               }
+       }
+
+       for (i = 0; i < mdev->dma_channels; i++) {
+               char name[30];
+
+               sprintf(name, "channel%d_priority", i);
+               if (strcmp(attr->attr.name, name) == 0) {
+                       rc = set_priority(mdev, i, tmp);
+                       if (rc)
+                               return rc;
+                       goto done;
+               }
+
+               sprintf(name, "channel%d_weight", i);
+               if (strcmp(attr->attr.name, name) == 0) {
+                       rc = set_weight(mdev, i, tmp);
+                       if (rc)
+                               return rc;
+               }
+       }
+done:
+       return count;
+}
+
+static int create_sysfs_entry(struct hidma_mgmt_dev *dev, char *name, int

mode)

drivers/dma/qcom/hidma_mgmt_sys.c new file +17 -0
+{
+       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;
Quoted 9 lines

drivers/dma/qcom/hidma_mgmt_sys.c line 203

Quoted 6 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +6 -0
+       sysfs_attr_init(&attrs->attr);
+
+       return device_create_file(&dev->pdev->dev, attrs);
+}
+
+

Extra empty line.

Removed

Quoted 14 lines

drivers/dma/qcom/hidma_mgmt_sys.c line 214

Quoted 11 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +11 -0
+int hidma_mgmt_init_sys(struct hidma_mgmt_dev *dev)
+{
+       unsigned int i;
+       int rc;
+
+       for (i = 0; i < ARRAY_SIZE(files); i++) {
+               rc = create_sysfs_entry(dev, files[i].name, files[i].mode);
+               if (rc)
+                       return rc;
+       }
+

Can it be like

Quoted 7 lines

/sys/???/DEVICExx/
channelYY/
attr1
attr2
???

?

I'll work on it. I didn't know that you are allowed to create subdirectories in sysfs. I was just creating attributes to keep it simple. But, your suggestion is cleaner.

Quoted 3 lines

I think it will be easier to handle in code and from user. (Similar way DMAEngine API does for slave DMA devices)

Now, the good stuff. Can you clarify your comment? I didn't understand it.

Quoted 23 lines
Quoted 8 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +7 -0
+       for (i = 0; i < dev->dma_channels; i++) {
+               char name[30];
+
+               sprintf(name, "channel%d_priority", i);
+               rc = create_sysfs_entry(dev, name, (S_IRUGO|S_IWUGO));
+               if (rc)
+                       return rc;

drivers/dma/qcom/hidma_mgmt_sys.c line 231

Quoted 10 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +10 -0
+
+               sprintf(name, "channel%d_weight", i);
+               rc = create_sysfs_entry(dev, name, (S_IRUGO|S_IWUGO));
+               if (rc)
+                       return rc;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(hidma_mgmt_init_sys);

--
With Best Regards,
Andy Shevchenko

#5 lore raw

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

Quoted 1 line · On Sun, Nov 22, 2015 at 9:52 PM, <[email protected]> wrote:
Quoted 1 line · Sinan Kaya

[]

Quoted 8 lines
Quoted 4 lines

drivers/dma/qcom/hidma_mgmt.c line 56

Quoted 2 lines
drivers/dma/qcom/hidma_mgmt.c new file +2 -0
+       if (!is_power_of_2(mgmtdev->max_write_request) ||
+               (mgmtdev->max_write_request < 128) ||

Someone likes parens.

yes, I do. I don't trust compilers and also don't like to open holes for people making quick changes to code while ignoring the operator precedence for maintenance reasons.

Btw in the other patch you did something like

var xyz;

? == (xyz)

which has nothing to do with operator precedence.

And if a compiler or static analyzer is in doubt it issues a warning / error.

Quoted 5 lines
Quoted 3 lines

I might agree with these cases, but below in assignments and combined operations the parens are indeed redundant.

OK. I think we are already in personal style of code zone now.

Yes and no.

Quoted 3 lines

I have already
broken another review because you don't like for loops but rather have a while loop.

In that case (IIRC) the for-loop use to be too verbose instead of simple (--i >= 0). For sake of readability and maintenance.

Quoted 2 lines

I'll leave ifs and change the assignments only. I'll need your reviewed-by once you are happy.

OK.

Quoted 9 lines
Quoted 7 lines

drivers/dma/qcom/hidma_mgmt.c line 155

Quoted 5 lines
drivers/dma/qcom/hidma_mgmt.c new file +5 -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);
+       pm_runtime_get_sync(&pdev->dev);

+empty line

added a new line for you. I don't know why.

Readability and logical break of the blocks: a) runtime PM, b) platform resource management.
Do you agree?

Quoted 6 lines
Quoted 6 lines

drivers/dma/qcom/hidma_mgmt.c line 161

Quoted 6 lines
drivers/dma/qcom/hidma_mgmt.c new file +6 -0
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       virtaddr = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(virtaddr)) {
+               rc = -ENOMEM;
+               goto out;
+       }

[]

Quoted 25 lines
Quoted 12 lines

drivers/dma/qcom/hidma_mgmt_sys.c line 214

Quoted 9 lines
drivers/dma/qcom/hidma_mgmt_sys.c new file +9 -0
+       unsigned int i;
+       int rc;
+
+       for (i = 0; i < ARRAY_SIZE(files); i++) {
+               rc = create_sysfs_entry(dev, files[i].name, files[i].mode);
+               if (rc)
+                       return rc;
+       }
+

Can it be like

Quoted 7 lines

/sys/?/DEVICExx/
channelYY/
attr1
attr2
?

?

I'll work on it. I didn't know that you are allowed to create subdirectories in sysfs. I was just creating attributes to keep it simple. But, your suggestion is cleaner.

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

I think it will be easier to handle in code and from user. (Similar way DMAEngine API does for slave DMA devices)

Now, the good stuff. Can you clarify your comment? I didn't understand it.

I meant that DMAEngine uses
/sys/class/dma
dmaYchannelX/
attr1
attr2
?

layout.

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

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

Quoted 21 lines
Quoted 16 lines
Quoted 10 lines

Can it be like

/sys/?/DEVICExx/
channelYY/
attr1
attr2
?

?

I'll work on it. I didn't know that you are allowed to create subdirectories in sysfs. I was just creating attributes to keep it simple. But, your suggestion is cleaner.

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

I think it will be easier to handle in code and from user. (Similar way DMAEngine API does for slave DMA devices)

Now, the good stuff. Can you clarify your comment? I didn't understand it.

Quoted 9 lines

I meant that DMAEngine uses
/sys/class/dma
dmaYchannelX/
attr1
attr2
?

layout.

I have posted v7 with this change.

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

PATCH v6 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.

v6
-----------
* Remove pm lock in ISR as it is redundant.
* sparse warning for missing _iomem.
* sparse warning for static required.

---
 .../devicetree/bindings/dma/qcom_hidma.txt         |  18 +
 drivers/dma/qcom/Kconfig                           |  10 +
 drivers/dma/qcom/Makefile                          |   2 +
 drivers/dma/qcom/hidma.c                           | 710 ++++++++++++++++
 drivers/dma/qcom/hidma.h                           | 157 ++++
 drivers/dma/qcom/hidma_dbg.c                       | 225 +++++
 drivers/dma/qcom/hidma_ll.c                        | 930 +++++++++++++++++++++
 7 files changed, 2052 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 +710 -0

710 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 +225 -0

225 lines not on this page · raw message

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

930 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