Skip to contentSkip to conversation

dma: add Qualcomm Technologies HIDMA driver

PATCH Superseded Sinan Kaya 3 participants 9 messages Mar 11, 2016 – Mar 27, 2016

Subsystems (5)

v15 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

v15 cover dma: add Qualcomm Technologies HIDMA driver

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 host context and is the main management entity for all channels provided by the device.

------------------------
What's new
------------------------
- Coding style corrections.
- Correct OF node lookup.

------------------------
Git repos
------------------------
QEMU Support
https://www.codeaurora.org/cgit/quic/qemu/qemu/log/?h=v2.5.0-sriov

------------------------
History of Changes
------------------------
dma: qcom_hidma: add support for object hierarchy Changes from V14: (https://lkml.org/lkml/2016/2/4/1089)
* use correct node (child) to read dma attribute.

dma: qcom_hidma: implement lower level hardware interface Changes from V14: (https://lkml.org/lkml/2016/2/4/1086)
* renamed constants as HIDMA_xyz

dma: qcom_hidma: add support for object hierarchy Changes from V14: (https://lkml.org/lkml/2016/2/4/1089)
* renamed constants as HIDMA_xyz

Sinan Kaya (4):
dma: qcom_hidma: implement lower level hardware interface
dma: qcom_hidma: add debugfs hooks
dma: qcom_hidma: add support for object hierarchy
dma: qcom_hidma: read the channel id from HW

 Documentation/ABI/testing/sysfs-platform-hidma     |   9 +
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |   3 -
 drivers/dma/qcom/*Backtrace*                       |   4 +
 drivers/dma/qcom/Makefile                          |   2 +
 drivers/dma/qcom/hidma.c                           |  81 +-
 drivers/dma/qcom/hidma.h                           |  20 +-
 drivers/dma/qcom/hidma_dbg.c                       | 219 +++++
 drivers/dma/qcom/hidma_ll.c                        | 918 +++++++++++++++++++++
 drivers/dma/qcom/hidma_mgmt.c                      | 111 ++-
 9 files changed, 1313 insertions(+), 54 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-hidma
 create mode 100644 drivers/dma/qcom/*Backtrace*
 create mode 100644 drivers/dma/qcom/hidma_dbg.c
 create mode 100644 drivers/dma/qcom/hidma_ll.c
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH v15 1/4 dma: qcom_hidma: implement lower level hardware interface

This patch implements the hardware hooks for the HIDMA channel driver.

The main functions of interest are:
- hidma_ll_init
- hidma_ll_request
- hidma_ll_queue_request
- hidma_ll_hw_start

OS layer calls the hidma_ll_init function during probe to set up the hardware. At this moment, the number of supported descriptors are also given. On each request, a descriptor is allocated from the free pool and filled in with the transfer parameters. Multiple requests can be queued into the hardware via the OS interface. When client is ready for requests to be executed, start method is called.

Completions are delivered via callbacks via tasklet.

---
 drivers/dma/qcom/*Backtrace* |   4 +
 drivers/dma/qcom/Makefile    |   2 +
 drivers/dma/qcom/hidma.h     |  18 +-
 drivers/dma/qcom/hidma_ll.c  | 918 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 933 insertions(+), 9 deletions(-)
 create mode 100644 drivers/dma/qcom/*Backtrace*
 create mode 100644 drivers/dma/qcom/hidma_ll.c
drivers/dma/qcom/*Backtrace* new file +4 -0
new file mode 100644
index 0000000..7c9a216
@@ -0,0 +1,4 @@
+Debugger entered--Lisp error: (void-variable wq)
+  eval(wq nil)
+  eval-expression(wq nil)
+  call-interactively(eval-expression nil nil)
drivers/dma/qcom/Makefile +2 -0
index bfea699..6bf9267 100644
@@ -1,3 +1,5 @@
 obj-$(CONFIG_QCOM_BAM_DMA) += bam_dma.o
 obj-$(CONFIG_QCOM_HIDMA_MGMT) += hdma_mgmt.o
 hdma_mgmt-objs	 := hidma_mgmt.o hidma_mgmt_sys.o
+obj-$(CONFIG_QCOM_HIDMA) +=  hdma.o
+hdma-objs        := hidma_ll.o hidma.o
drivers/dma/qcom/hidma.h +9 -9
index 231e306..667ab37 100644
@@ -20,13 +20,13 @@
 #include <linux/interrupt.h>
 #include <linux/dmaengine.h>
 
-#define TRE_SIZE			32 /* each TRE is 32 bytes  */
-#define TRE_CFG_IDX			0
-#define TRE_LEN_IDX			1
-#define TRE_SRC_LOW_IDX		2
-#define TRE_SRC_HI_IDX			3
-#define TRE_DEST_LOW_IDX		4
-#define TRE_DEST_HI_IDX		5
+#define HIDMA_TRE_SIZE			32 /* each TRE is 32 bytes  */
+#define HIDMA_TRE_CFG_IDX		0
+#define HIDMA_TRE_LEN_IDX		1
+#define HIDMA_TRE_SRC_LOW_IDX		2
+#define HIDMA_TRE_SRC_HI_IDX		3
+#define HIDMA_TRE_DEST_LOW_IDX		4
+#define HIDMA_TRE_DEST_HI_IDX		5
 
 struct hidma_tx_status {
 	u8 err_info;			/* error record in this transfer    */
@@ -37,13 +37,13 @@ struct hidma_tre {
 	atomic_t allocated;		/* if this channel is allocated	    */
 	bool queued;			/* flag whether this is pending     */
 	u16 status;			/* status			    */
-	u32 chidx;			/* index of the tre		    */
+	u32 idx;			/* index of the tre		    */
 	u32 dma_sig;			/* signature of the tre		    */
 	const char *dev_name;		/* name of the device		    */
 	void (*callback)(void *data);	/* requester callback		    */
 	void *data;			/* Data associated with this channel*/
 	struct hidma_lldev *lldev;	/* lldma device pointer		    */
-	u32 tre_local[TRE_SIZE / sizeof(u32) + 1]; /* TRE local copy        */
+	u32 tre_local[HIDMA_TRE_SIZE / sizeof(u32) + 1]; /* TRE local copy  */
 	u32 tre_index;			/* the offset where this was written*/
 	u32 int_flags;			/* interrupt flags		    */
 };
drivers/dma/qcom/hidma_ll.c new file +918 -0

918 lines not on this page · raw message

Signature · 1 line
1.8.2.1
author
#2 lore raw

PATCH v15 2/4 dma: qcom_hidma: add debugfs hooks

In reply to Sinan Kaya

Add debugfs hooks for debugging the execution behavior of the DMA channel. The debugfs hooks get initialized by the probe function and uninitialized by the remove function.

A stats file is created in debugfs. The stats file will show the information about each HIDMA channel as well as each asynchronous job queued and completed at a given time.

---
 drivers/dma/qcom/Makefile    |   2 +-
 drivers/dma/qcom/hidma.c     |   3 +
 drivers/dma/qcom/hidma.h     |   2 +
 drivers/dma/qcom/hidma_dbg.c | 219 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 225 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/qcom/hidma_dbg.c
drivers/dma/qcom/Makefile +1 -1
index 6bf9267..4bfc38b 100644
@@ -2,4 +2,4 @@ obj-$(CONFIG_QCOM_BAM_DMA) += bam_dma.o
 obj-$(CONFIG_QCOM_HIDMA_MGMT) += hdma_mgmt.o
 hdma_mgmt-objs	 := hidma_mgmt.o hidma_mgmt_sys.o
 obj-$(CONFIG_QCOM_HIDMA) +=  hdma.o
-hdma-objs        := hidma_ll.o hidma.o
+hdma-objs        := hidma_ll.o hidma.o hidma_dbg.o
drivers/dma/qcom/hidma.c +3 -0
index f8960f1..833db9e 100644
@@ -681,6 +681,7 @@ static int hidma_probe(struct platform_device *pdev)
 
 	dmadev->irq = chirq;
 	tasklet_init(&dmadev->task, hidma_issue_task, (unsigned long)dmadev);
+	hidma_debug_init(dmadev);
 	dev_info(&pdev->dev, "HI-DMA engine driver registration complete\n");
 	platform_set_drvdata(pdev, dmadev);
 	pm_runtime_mark_last_busy(dmadev->ddev.dev);
@@ -689,6 +690,7 @@ static int hidma_probe(struct platform_device *pdev)
 	return 0;
 
 uninit:
+	hidma_debug_uninit(dmadev);
 	hidma_ll_uninit(dmadev->lldev);
 dmafree:
 	if (dmadev)
@@ -706,6 +708,7 @@ static int hidma_remove(struct platform_device *pdev)
 	pm_runtime_get_sync(dmadev->ddev.dev);
 	dma_async_device_unregister(&dmadev->ddev);
 	devm_free_irq(dmadev->ddev.dev, dmadev->irq, dmadev->lldev);
+	hidma_debug_uninit(dmadev);
 	hidma_ll_uninit(dmadev->lldev);
 	hidma_free(dmadev);
 
drivers/dma/qcom/hidma.h +2 -0
index 667ab37..6c74928 100644
@@ -157,4 +157,6 @@ int hidma_ll_uninit(struct hidma_lldev *llhndl);
 irqreturn_t hidma_ll_inthandler(int irq, void *arg);
 void hidma_cleanup_pending_tre(struct hidma_lldev *llhndl, u8 err_info,
 				u8 err_code);
+int hidma_debug_init(struct hidma_dev *dmadev);
+void hidma_debug_uninit(struct hidma_dev *dmadev);
 #endif
drivers/dma/qcom/hidma_dbg.c new file +219 -0

219 lines not on this page · raw message

Signature · 1 line
1.8.2.1
author
#3 lore raw

PATCH v15 3/4 dma: qcom_hidma: add support for object hierarchy

In reply to Sinan Kaya

In order to create a relationship model between the channels and the management object, we are adding support for object hierarchy to the drivers. This patch simplifies the userspace application development. We will not have to traverse different firmware paths based on device tree or ACPI based kernels.

No matter what flavor of kernel is used, objects will be represented as platform devices.

The new layout is as follows:

hidmam_10: hidma-mgmt@0x5A000000 {
	compatible = "qcom,hidma-mgmt-1.0";
	...

	hidma_10: hidma@0x5a010000 {
			compatible = "qcom,hidma-1.0";
			...
	}
}

The hidma_mgmt_init detects each instance of the hidma-mgmt-1.0 objects in device tree and calls into the channel driver to create platform devices for each child of the management object.

---
 Documentation/ABI/testing/sysfs-platform-hidma |   9 ++
 drivers/dma/qcom/hidma.c                       |  39 ++++++++-
 drivers/dma/qcom/hidma_mgmt.c                  | 111 ++++++++++++++++++++++++-
 3 files changed, 155 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-hidma
Documentation/ABI/testing/sysfs-platform-hidma new file +9 -0
new file mode 100644
index 0000000..d364415
@@ -0,0 +1,9 @@
+What:		/sys/devices/platform/hidma-*/chid
+		/sys/devices/platform/QCOM8061:*/chid
+Date:		Dec 2015
+KernelVersion:	4.4
+Contact:	"Sinan Kaya <[email protected]>"
+Description:
+		Contains the ID of the channel within the HIDMA instance.
+		It is used to associate a given HIDMA channel with the
+		priority and weight calls in the management interface.
drivers/dma/qcom/hidma.c +38 -1
index 833db9e..ac20bdb 100644
@@ -549,6 +549,43 @@ static irqreturn_t hidma_chirq_handler(int chirq, void *arg)
 	return hidma_ll_inthandler(chirq, lldev);
 }
 
+static ssize_t hidma_show_values(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct hidma_dev *mdev = platform_get_drvdata(pdev);
+
+	buf[0] = 0;
+
+	if (strcmp(attr->attr.name, "chid") == 0)
+		sprintf(buf, "%d\n", mdev->chidx);
+
+	return strlen(buf);
+}
+
+static int hidma_create_sysfs_entry(struct hidma_dev *dev, char *name,
+				    int mode)
+{
+	struct device_attribute *attrs;
+	char *name_copy;
+
+	attrs = devm_kmalloc(dev->ddev.dev, sizeof(struct device_attribute),
+			     GFP_KERNEL);
+	if (!attrs)
+		return -ENOMEM;
+
+	name_copy = devm_kstrdup(dev->ddev.dev, name, GFP_KERNEL);
+	if (!name_copy)
+		return -ENOMEM;
+
+	attrs->attr.name = name_copy;
+	attrs->attr.mode = mode;
+	attrs->show = hidma_show_values;
+	sysfs_attr_init(&attrs->attr);
+
+	return device_create_file(dev->ddev.dev, attrs);
+}
+
 static int hidma_probe(struct platform_device *pdev)
 {
 	struct hidma_dev *dmadev;
@@ -682,6 +719,7 @@ static int hidma_probe(struct platform_device *pdev)
 	dmadev->irq = chirq;
 	tasklet_init(&dmadev->task, hidma_issue_task, (unsigned long)dmadev);
 	hidma_debug_init(dmadev);
+	hidma_create_sysfs_entry(dmadev, "chid", S_IRUGO);
 	dev_info(&pdev->dev, "HI-DMA engine driver registration complete\n");
 	platform_set_drvdata(pdev, dmadev);
 	pm_runtime_mark_last_busy(dmadev->ddev.dev);
@@ -730,7 +768,6 @@ static const struct of_device_id hidma_match[] = {
 	{.compatible = "qcom,hidma-1.0",},
 	{},
 };
-
 MODULE_DEVICE_TABLE(of, hidma_match);
 
 static struct platform_driver hidma_driver = {
drivers/dma/qcom/hidma_mgmt.c +108 -3

126 lines not on this page · raw message

Signature · 1 line
1.8.2.1
author
#4 lore raw

PATCH v15 4/4 dma: qcom_hidma: read the channel id from HW

In reply to Sinan Kaya

Removing the flexibility to choose the event channel as there is no real use case right now. We have been using the values in ACPI that match the HW defaults. OS is reading the event-channel from the HW register now.

---
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  3 --
 drivers/dma/qcom/hidma.c                           | 39 +---------------------
 2 files changed, 1 insertion(+), 41 deletions(-)
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +0 -3
index e3677a5..fd5618b 100644
@@ -51,7 +51,6 @@ Required properties:
 - reg: Addresses for the transfer and event channel
 - interrupts: Should contain the event interrupt
 - desc-count: Number of asynchronous requests this channel can handle
-- channel-index: The HW event channel completions will be delivered.
 - iommus: required a iommu node
 
 Example:
@@ -75,7 +74,6 @@ Hypervisor OS configuration:
 			interrupts = <0 389 0>;
 			desc-count = <10>;
 			iommus = <&system_mmu>;
-			channel-index = <4>;
 		};
 	};
 
@@ -87,6 +85,5 @@ Guest OS configuration:
 		      <0 0x5c0b0000 0x0 0x1000>;
 		interrupts = <0 389 0>;
 		desc-count = <10>;
-		channel-index = <4>;
 		iommus = <&system_mmu>;
 	};
drivers/dma/qcom/hidma.c +1 -38
index ac20bdb..7180367 100644
@@ -101,26 +101,6 @@ static unsigned int nr_desc_prm;
 module_param(nr_desc_prm, uint, 0644);
 MODULE_PARM_DESC(nr_desc_prm, "number of descriptors (default: 0)");
 
-#define HIDMA_MAX_CHANNELS	64
-static int channel_idx[HIDMA_MAX_CHANNELS] = {
-	[0 ... (HIDMA_MAX_CHANNELS - 1)] = -1
-};
-
-/*
- * 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 paraemeter such as
- * channel-index gets ignored by the QEMU.
- * We are using this command line parameter to pass the event channel index to
- * the guest machine.
- */
-static unsigned int num_channel_idx;
-module_param_array_named(channel_idx, channel_idx, int, &num_channel_idx,
-			 0644);
-MODULE_PARM_DESC(channel_idx, "channel index array for the notifications");
-static atomic_t channel_ref_count;
 
 /* process completed descriptors */
 static void hidma_process_completed(struct hidma_chan *mchan)
@@ -592,7 +572,6 @@ static int hidma_probe(struct platform_device *pdev)
 	struct resource *trca_resource;
 	struct resource *evca_resource;
 	int chirq;
-	int current_channel_index = atomic_read(&channel_ref_count);
 	void __iomem *evca;
 	void __iomem *trca;
 	int rc;
@@ -668,22 +647,7 @@ static int hidma_probe(struct platform_device *pdev)
 		goto dmafree;
 	}
 
-	if (current_channel_index > HIDMA_MAX_CHANNELS) {
-		rc = -EINVAL;
-		goto dmafree;
-	}
-
-	dmadev->chidx = -1;
-	device_property_read_u32(&pdev->dev, "channel-index", &dmadev->chidx);
-
-	/* kernel command line override for the guest machine */
-	if (channel_idx[current_channel_index] != -1)
-		dmadev->chidx = channel_idx[current_channel_index];
-
-	if (dmadev->chidx == -1) {
-		rc = -EINVAL;
-		goto dmafree;
-	}
+	dmadev->chidx = readl(dmadev->dev_trca + 0x28);
 
 	/* Set DMA mask to 64 bits. */
 	rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
@@ -724,7 +688,6 @@ static int hidma_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dmadev);
 	pm_runtime_mark_last_busy(dmadev->ddev.dev);
 	pm_runtime_put_autosuspend(dmadev->ddev.dev);
-	atomic_inc(&channel_ref_count);
 	return 0;
 
 uninit:
Signature · 1 line
1.8.2.1
maintainer Acked-by on v15 4/4
#5 lore raw

Re: [PATCH 4/4] dma: qcom_hidma: read the channel id from HW

Quoted 7 lines · Sinan Kaya

Removing the flexibility to choose the event channel as there is no real use case right now. We have been using the values in ACPI that match the HW defaults. OS is reading the event-channel from the HW register now.

---
 .../devicetree/bindings/dma/qcom_hidma_mgmt.txt    |  3 --
Quoted 2 lines
 drivers/dma/qcom/hidma.c                           | 39 +---------------------
 2 files changed, 1 insertion(+), 41 deletions(-)
#6 lore raw

v15 cover dma: add Qualcomm Technologies HIDMA driver

In reply to Sinan Kaya
Quoted 6 lines · Sinan Kaya

Sinan Kaya (4):
dma: qcom_hidma: implement lower level hardware interface
dma: qcom_hidma: add debugfs hooks
dma: qcom_hidma: add support for object hierarchy
dma: qcom_hidma: read the channel id from HW

Any reason why you insist on using subsystem name as dma even when asked to change..

Signature · 1 line
~Vinod
#7 lore raw

v15 cover dma: add Qualcomm Technologies HIDMA driver

Quoted 11 lines · Vinod Koul
Quoted 6 lines · Sinan Kaya

Sinan Kaya (4):
dma: qcom_hidma: implement lower level hardware interface
dma: qcom_hidma: add debugfs hooks
dma: qcom_hidma: add support for object hierarchy
dma: qcom_hidma: read the channel id from HW

Any reason why you insist on using subsystem name as dma even when asked to
change..

Forgotten. I can fix that.

#8 lore raw

v15 cover dma: add Qualcomm Technologies HIDMA driver

In reply to Vinod Koul
Quoted 11 lines · Vinod Koul
Quoted 6 lines · Sinan Kaya

Sinan Kaya (4):
dma: qcom_hidma: implement lower level hardware interface
dma: qcom_hidma: add debugfs hooks
dma: qcom_hidma: add support for object hierarchy
dma: qcom_hidma: read the channel id from HW

Any reason why you insist on using subsystem name as dma even when asked to
change..

Anything else, I should address?