dmaengine Archive on lore.kernel.org
 help / color / Atom feed
* [RFC 0/3] dmaengine: Support for DMA domain controllers
@ 2019-09-06 14:18 Peter Ujfalusi
  2019-09-06 14:18 ` [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains Peter Ujfalusi
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-06 14:18 UTC (permalink / raw)
  To: vkoul, robh+dt; +Cc: dmaengine, linux-kernel, dan.j.williams, devicetree

Hi,

More and more SoC have more than one DMA controller integrated.

If a device needs none slave DMA channel for operation (block copy from/to
memory mapped regions for example) at the moment when they request a channel it
is going to be taken from the first DMA controller which was registered, but
this might be not optimal for the device.

For example on AM654 we have two DMAs: main_udmap and mcu_udmap.
DDR to DDR memcpy is twice as fast on main_udmap compared to mcu_udmap, while
devices on MCU domain (OSPI for example) are more than twice as fast on
mcu_udmap than with main_udmap.

Because of probing order (mcu_udmap is probing first) modules would use
mcu_udmap instead of the better main_udmap. Currently the only solution is to
make a choice and disable the MEM_TO_MEM functionality on one of them which is
not a great solution.

With the introduction of DMA domain controllers we can utilize the best DMA
controller for the job around the SoC without the need to degrade performance.

If the dma-domain-controller is not present in DT or booted w/o DT the none
slave channel request will work as it does today.

The last patch introduces a new dma_domain_request_chan_by_mask() function and
I have a define for dma_request_chan_by_mask() to avoid breaking users of the
dma_request_chan_by_mask, but looking at the kernel we have small amount of
users:
drivers/gpu/drm/vc4/vc4_dsi.c
drivers/media/platform/omap/omap_vout_vrfb.c
drivers/media/platform/omap3isp/isphist.c
drivers/mtd/spi-nor/cadence-quadspi.c
drivers/spi/spi-ti-qspi.c

If it is acceptable we can modify the parameters of dma_request_chan_by_mask()
to include ther device pointer and at the same time change all of the clients
by giving NULL or in case of the last two their dev.

Regards,
Peter
---
Peter Ujfalusi (3):
  dt-bindings: dma: Add documentation for DMA domains
  dmaengine: of_dma: Function to look up the DMA domain of a client
  dmaengine: Support for requesting channels preferring DMA domain
    controller

 .../devicetree/bindings/dma/dma-domain.yaml   | 59 +++++++++++++++++++
 drivers/dma/dmaengine.c                       | 17 ++++--
 drivers/dma/of-dma.c                          | 42 +++++++++++++
 include/linux/dmaengine.h                     |  9 ++-
 include/linux/of_dma.h                        |  7 +++
 5 files changed, 126 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/dma/dma-domain.yaml

-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-06 14:18 [RFC 0/3] dmaengine: Support for DMA domain controllers Peter Ujfalusi
@ 2019-09-06 14:18 ` Peter Ujfalusi
  2019-09-08  7:47   ` Peter Ujfalusi
  2019-09-08 12:06   ` Vinod Koul
  2019-09-06 14:18 ` [RFC 2/3] dmaengine: of_dma: Function to look up the DMA domain of a client Peter Ujfalusi
  2019-09-06 14:18 ` [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller Peter Ujfalusi
  2 siblings, 2 replies; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-06 14:18 UTC (permalink / raw)
  To: vkoul, robh+dt; +Cc: dmaengine, linux-kernel, dan.j.williams, devicetree

On systems where multiple DMA controllers available, none Slave (for example
memcpy operation) users can not be described in DT as there is no device
involved from the DMA controller's point of view, DMA binding is not usable.
However in these systems still a peripheral might need to be serviced by or
it is better to serviced by specific DMA controller.
When a memcpy is used to/from a memory mapped region for example a DMA in the
same domain can perform better.
For generic software modules doing mem 2 mem operations it also matter that
they will get a channel from a controller which is faster in DDR to DDR mode
rather then from the first controller happen to be loaded.

This property is inherited, so it may be specified in a device node or in any
of its parent nodes.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 .../devicetree/bindings/dma/dma-domain.yaml   | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/dma-domain.yaml

diff --git a/Documentation/devicetree/bindings/dma/dma-domain.yaml b/Documentation/devicetree/bindings/dma/dma-domain.yaml
new file mode 100644
index 000000000000..c2f182f30081
--- /dev/null
+++ b/Documentation/devicetree/bindings/dma/dma-domain.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/dma-controller.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: DMA Domain Controller Definition
+
+maintainers:
+  - Vinod Koul <vkoul@kernel.org>
+
+allOf:
+  - $ref: "dma-controller.yaml#"
+
+description:
+  On systems where multiple DMA controllers available, none Slave (for example
+  memcpy operation) users can not be described in DT as there is no device
+  involved from the DMA controller's point of view, DMA binding is not usable.
+  However in these systems still a peripheral might need to be serviced by or
+  it is better to serviced by specific DMA controller.
+  When a memcpy is used to/from a memory mapped region for example a DMA in the
+  same domain can perform better.
+  For generic software modules doing mem 2 mem operations it also matter that
+  they will get a channel from a controller which is faster in DDR to DDR mode
+  rather then from the first controller happen to be loaded.
+
+  This property is inherited, so it may be specified in a device node or in any
+  of its parent nodes.
+
+properties:
+  $dma-domain-controller:
+    $ref: /schemas/types.yaml#definitions/phandle
+    description:
+      phande to the DMA controller node which should be used for the device or
+      domain.
+
+examples:
+  - |
+    / {
+        model = "Texas Instruments K3 AM654 SoC";
+        compatible = "ti,am654";
+        interrupt-parent = <&gic500>;
+        /* For modules without device, DDR to DDR is faster on main UDMAP */
+        dma-domain-controller = <&main_udmap>;
+        #address-cells = <2>;
+        #size-cells = <2>;
+        ...
+    };
+
+    &cbass_main {
+        /* For modules within MAIN domain, use main UDMAP */
+        dma-domain-controller = <&main_udmap>;
+    };
+
+    &cbass_mcu {
+        /* For modules within MCU domain, use mcu UDMAP */
+        dma-domain-controller = <&mcu_udmap>;
+    };
+...
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC 2/3] dmaengine: of_dma: Function to look up the DMA domain of a client
  2019-09-06 14:18 [RFC 0/3] dmaengine: Support for DMA domain controllers Peter Ujfalusi
  2019-09-06 14:18 ` [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains Peter Ujfalusi
@ 2019-09-06 14:18 ` Peter Ujfalusi
  2019-09-08 12:12   ` Vinod Koul
  2019-09-06 14:18 ` [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller Peter Ujfalusi
  2 siblings, 1 reply; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-06 14:18 UTC (permalink / raw)
  To: vkoul, robh+dt; +Cc: dmaengine, linux-kernel, dan.j.williams, devicetree

Find the DMA domain controller of the client device by iterating up in
device tree looking for the closest 'dma-domain-controller' property.

If the client's node is not provided then check the DT root for the
controller.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/dma/of-dma.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_dma.h |  7 +++++++
 2 files changed, 49 insertions(+)

diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
index c2d779daa4b5..04b5795cd76b 100644
--- a/drivers/dma/of-dma.c
+++ b/drivers/dma/of-dma.c
@@ -18,6 +18,48 @@
 static LIST_HEAD(of_dma_list);
 static DEFINE_MUTEX(of_dma_lock);
 
+/**
+ * of_find_dma_domain - Get the domain DMA controller
+ * @np:		device node of the client device
+ *
+ * Look up the DMA controller of the domain the client device is part of.
+ * Finds the dma-domain controller the client device belongs to. It is used when
+ * requesting non slave channels (like channel for memcpy) to make sure that the
+ * channel can be request from a DMA controller which can service the given
+ * domain best.
+ *
+ * Returns the device_node pointer of the DMA controller or succes or NULL on
+ * error.
+ */
+struct device_node *of_find_dma_domain(struct device_node *np)
+{
+	struct device_node *dma_domain = NULL;
+	phandle dma_phandle;
+
+	/*
+	 * If no device_node is provided look at the root level for system
+	 * default DMA controller for modules.
+	 */
+	if (!np)
+		np = of_root;
+
+	if (!np || !of_node_get(np))
+		return NULL;
+
+	do {
+		if (of_property_read_u32(np, "dma-domain-controller",
+					 &dma_phandle))
+			np = of_get_next_parent(np);
+		else {
+			dma_domain = of_find_node_by_phandle(dma_phandle);
+			of_node_put(np);
+		}
+	} while (!dma_domain && np);
+
+	return dma_domain;
+}
+EXPORT_SYMBOL_GPL(of_find_dma_domain);
+
 /**
  * of_dma_find_controller - Get a DMA controller in DT DMA helpers list
  * @dma_spec:	pointer to DMA specifier as found in the device tree
diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
index fd706cdf255c..6eab0a8d3335 100644
--- a/include/linux/of_dma.h
+++ b/include/linux/of_dma.h
@@ -32,6 +32,8 @@ struct of_dma_filter_info {
 };
 
 #ifdef CONFIG_DMA_OF
+extern struct device_node *of_find_dma_domain(struct device_node *np);
+
 extern int of_dma_controller_register(struct device_node *np,
 		struct dma_chan *(*of_dma_xlate)
 		(struct of_phandle_args *, struct of_dma *),
@@ -52,6 +54,11 @@ extern struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec
 		struct of_dma *ofdma);
 
 #else
+static inline struct device_node *of_find_dma_domain(struct device_node *np)
+{
+	return NULL;
+}
+
 static inline int of_dma_controller_register(struct device_node *np,
 		struct dma_chan *(*of_dma_xlate)
 		(struct of_phandle_args *, struct of_dma *),
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller
  2019-09-06 14:18 [RFC 0/3] dmaengine: Support for DMA domain controllers Peter Ujfalusi
  2019-09-06 14:18 ` [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains Peter Ujfalusi
  2019-09-06 14:18 ` [RFC 2/3] dmaengine: of_dma: Function to look up the DMA domain of a client Peter Ujfalusi
@ 2019-09-06 14:18 ` Peter Ujfalusi
  2019-09-08  7:46   ` Peter Ujfalusi
  2019-09-08 12:15   ` Vinod Koul
  2 siblings, 2 replies; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-06 14:18 UTC (permalink / raw)
  To: vkoul, robh+dt; +Cc: dmaengine, linux-kernel, dan.j.williams, devicetree

In case the channel is not requested via the slave API, use the
of_find_dma_domain() to see if a system default DMA controller is
specified.

Add new function which can be used by clients to request channels by mask
from their DMA domain controller if specified.

Client drivers can take advantage of the domain support by moving from
dma_request_chan_by_mask() to dma_domain_request_chan_by_mask()

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/dma/dmaengine.c   | 17 ++++++++++++-----
 include/linux/dmaengine.h |  9 ++++++---
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 6baddf7dcbfd..087450eed68c 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -640,6 +640,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 	struct dma_device *device, *_d;
 	struct dma_chan *chan = NULL;
 
+	/* If np is not specified, get the default DMA domain controller */
+	if (!np)
+		np = of_find_dma_domain(NULL);
+
 	/* Find a channel */
 	mutex_lock(&dma_list_mutex);
 	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
@@ -751,19 +755,22 @@ struct dma_chan *dma_request_slave_channel(struct device *dev,
 EXPORT_SYMBOL_GPL(dma_request_slave_channel);
 
 /**
- * dma_request_chan_by_mask - allocate a channel satisfying certain capabilities
- * @mask: capabilities that the channel must satisfy
+ * dma_domain_request_chan_by_mask - allocate a channel by mask from DMA domain
+ * @dev:	pointer to client device structure
+ * @mask:	capabilities that the channel must satisfy
  *
  * Returns pointer to appropriate DMA channel on success or an error pointer.
  */
-struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
+struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
+						 const dma_cap_mask_t *mask)
 {
 	struct dma_chan *chan;
 
 	if (!mask)
 		return ERR_PTR(-ENODEV);
 
-	chan = __dma_request_channel(mask, NULL, NULL, NULL);
+	chan = __dma_request_channel(mask, NULL, NULL,
+				     of_find_dma_domain(dev->of_node));
 	if (!chan) {
 		mutex_lock(&dma_list_mutex);
 		if (list_empty(&dma_device_list))
@@ -775,7 +782,7 @@ struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
 
 	return chan;
 }
-EXPORT_SYMBOL_GPL(dma_request_chan_by_mask);
+EXPORT_SYMBOL_GPL(dma_domain_request_chan_by_mask);
 
 void dma_release_channel(struct dma_chan *chan)
 {
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 3b2e8e302f6c..9f94df81e83f 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1438,7 +1438,8 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
 
 struct dma_chan *dma_request_chan(struct device *dev, const char *name);
-struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
+struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
+						 const dma_cap_mask_t *mask);
 
 void dma_release_channel(struct dma_chan *chan);
 int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
@@ -1475,8 +1476,8 @@ static inline struct dma_chan *dma_request_chan(struct device *dev,
 {
 	return ERR_PTR(-ENODEV);
 }
-static inline struct dma_chan *dma_request_chan_by_mask(
-						const dma_cap_mask_t *mask)
+static inline struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
+			const dma_cap_mask_t *mask)
 {
 	return ERR_PTR(-ENODEV);
 }
@@ -1537,6 +1538,8 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
 	__dma_request_channel(&(mask), x, y, NULL)
 #define dma_request_slave_channel_compat(mask, x, y, dev, name) \
 	__dma_request_slave_channel_compat(&(mask), x, y, dev, name)
+#define dma_request_chan_by_mask(mask) \
+	dma_domain_request_chan_by_mask(NULL, mask)
 
 static inline struct dma_chan
 *__dma_request_slave_channel_compat(const dma_cap_mask_t *mask,
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller
  2019-09-06 14:18 ` [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller Peter Ujfalusi
@ 2019-09-08  7:46   ` Peter Ujfalusi
  2019-09-08 12:15   ` Vinod Koul
  1 sibling, 0 replies; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-08  7:46 UTC (permalink / raw)
  To: vkoul, robh+dt; +Cc: dmaengine, linux-kernel, dan.j.williams, devicetree



On 06/09/2019 17.18, Peter Ujfalusi wrote:
> In case the channel is not requested via the slave API, use the
> of_find_dma_domain() to see if a system default DMA controller is
> specified.
> 
> Add new function which can be used by clients to request channels by mask
> from their DMA domain controller if specified.
> 
> Client drivers can take advantage of the domain support by moving from
> dma_request_chan_by_mask() to dma_domain_request_chan_by_mask()
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  drivers/dma/dmaengine.c   | 17 ++++++++++++-----
>  include/linux/dmaengine.h |  9 ++++++---
>  2 files changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 6baddf7dcbfd..087450eed68c 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -640,6 +640,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
>  	struct dma_device *device, *_d;
>  	struct dma_chan *chan = NULL;
>  
> +	/* If np is not specified, get the default DMA domain controller */
> +	if (!np)
> +		np = of_find_dma_domain(NULL);
> +
>  	/* Find a channel */
>  	mutex_lock(&dma_list_mutex);
>  	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
> @@ -751,19 +755,22 @@ struct dma_chan *dma_request_slave_channel(struct device *dev,
>  EXPORT_SYMBOL_GPL(dma_request_slave_channel);
>  
>  /**
> - * dma_request_chan_by_mask - allocate a channel satisfying certain capabilities
> - * @mask: capabilities that the channel must satisfy
> + * dma_domain_request_chan_by_mask - allocate a channel by mask from DMA domain
> + * @dev:	pointer to client device structure
> + * @mask:	capabilities that the channel must satisfy
>   *
>   * Returns pointer to appropriate DMA channel on success or an error pointer.
>   */
> -struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
> +struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
> +						 const dma_cap_mask_t *mask)
>  {
>  	struct dma_chan *chan;
>  
>  	if (!mask)
>  		return ERR_PTR(-ENODEV);
>  
> -	chan = __dma_request_channel(mask, NULL, NULL, NULL);

if (dev)
> +	chan = __dma_request_channel(mask, NULL, NULL,
> +				     of_find_dma_domain(dev->of_node));else
	chan = __dma_request_channel(mask, NULL, NULL, NULL);

>  	if (!chan) {
>  		mutex_lock(&dma_list_mutex);
>  		if (list_empty(&dma_device_list))
> @@ -775,7 +782,7 @@ struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
>  
>  	return chan;
>  }
> -EXPORT_SYMBOL_GPL(dma_request_chan_by_mask);
> +EXPORT_SYMBOL_GPL(dma_domain_request_chan_by_mask);
>  
>  void dma_release_channel(struct dma_chan *chan)
>  {
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index 3b2e8e302f6c..9f94df81e83f 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -1438,7 +1438,8 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
>  struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
>  
>  struct dma_chan *dma_request_chan(struct device *dev, const char *name);
> -struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
> +struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
> +						 const dma_cap_mask_t *mask);
>  
>  void dma_release_channel(struct dma_chan *chan);
>  int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
> @@ -1475,8 +1476,8 @@ static inline struct dma_chan *dma_request_chan(struct device *dev,
>  {
>  	return ERR_PTR(-ENODEV);
>  }
> -static inline struct dma_chan *dma_request_chan_by_mask(
> -						const dma_cap_mask_t *mask)
> +static inline struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
> +			const dma_cap_mask_t *mask)
>  {
>  	return ERR_PTR(-ENODEV);
>  }
> @@ -1537,6 +1538,8 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
>  	__dma_request_channel(&(mask), x, y, NULL)
>  #define dma_request_slave_channel_compat(mask, x, y, dev, name) \
>  	__dma_request_slave_channel_compat(&(mask), x, y, dev, name)
> +#define dma_request_chan_by_mask(mask) \
> +	dma_domain_request_chan_by_mask(NULL, mask)
>  
>  static inline struct dma_chan
>  *__dma_request_slave_channel_compat(const dma_cap_mask_t *mask,
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-06 14:18 ` [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains Peter Ujfalusi
@ 2019-09-08  7:47   ` Peter Ujfalusi
  2019-09-08 12:10     ` Vinod Koul
  2019-09-08 12:06   ` Vinod Koul
  1 sibling, 1 reply; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-08  7:47 UTC (permalink / raw)
  To: vkoul, robh+dt; +Cc: dmaengine, linux-kernel, dan.j.williams, devicetree



On 06/09/2019 17.18, Peter Ujfalusi wrote:
> On systems where multiple DMA controllers available, none Slave (for example
> memcpy operation) users can not be described in DT as there is no device
> involved from the DMA controller's point of view, DMA binding is not usable.
> However in these systems still a peripheral might need to be serviced by or
> it is better to serviced by specific DMA controller.
> When a memcpy is used to/from a memory mapped region for example a DMA in the
> same domain can perform better.
> For generic software modules doing mem 2 mem operations it also matter that
> they will get a channel from a controller which is faster in DDR to DDR mode
> rather then from the first controller happen to be loaded.
> 
> This property is inherited, so it may be specified in a device node or in any
> of its parent nodes.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  .../devicetree/bindings/dma/dma-domain.yaml   | 59 +++++++++++++++++++
>  1 file changed, 59 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/dma/dma-domain.yaml
> 
> diff --git a/Documentation/devicetree/bindings/dma/dma-domain.yaml b/Documentation/devicetree/bindings/dma/dma-domain.yaml
> new file mode 100644
> index 000000000000..c2f182f30081
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/dma/dma-domain.yaml
> @@ -0,0 +1,59 @@
> +# SPDX-License-Identifier: GPL-2.0
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/dma/dma-controller.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: DMA Domain Controller Definition
> +
> +maintainers:
> +  - Vinod Koul <vkoul@kernel.org>
> +
> +allOf:
> +  - $ref: "dma-controller.yaml#"
> +
> +description:
> +  On systems where multiple DMA controllers available, none Slave (for example
> +  memcpy operation) users can not be described in DT as there is no device
> +  involved from the DMA controller's point of view, DMA binding is not usable.
> +  However in these systems still a peripheral might need to be serviced by or
> +  it is better to serviced by specific DMA controller.
> +  When a memcpy is used to/from a memory mapped region for example a DMA in the
> +  same domain can perform better.
> +  For generic software modules doing mem 2 mem operations it also matter that
> +  they will get a channel from a controller which is faster in DDR to DDR mode
> +  rather then from the first controller happen to be loaded.
> +
> +  This property is inherited, so it may be specified in a device node or in any
> +  of its parent nodes.
> +
> +properties:
> +  $dma-domain-controller:

or domain-dma-controller?

> +    $ref: /schemas/types.yaml#definitions/phandle
> +    description:
> +      phande to the DMA controller node which should be used for the device or
> +      domain.
> +
> +examples:
> +  - |
> +    / {
> +        model = "Texas Instruments K3 AM654 SoC";
> +        compatible = "ti,am654";
> +        interrupt-parent = <&gic500>;
> +        /* For modules without device, DDR to DDR is faster on main UDMAP */
> +        dma-domain-controller = <&main_udmap>;
> +        #address-cells = <2>;
> +        #size-cells = <2>;
> +        ...
> +    };
> +
> +    &cbass_main {
> +        /* For modules within MAIN domain, use main UDMAP */
> +        dma-domain-controller = <&main_udmap>;
> +    };
> +
> +    &cbass_mcu {
> +        /* For modules within MCU domain, use mcu UDMAP */
> +        dma-domain-controller = <&mcu_udmap>;
> +    };
> +...
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-06 14:18 ` [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains Peter Ujfalusi
  2019-09-08  7:47   ` Peter Ujfalusi
@ 2019-09-08 12:06   ` Vinod Koul
  2019-09-09  6:00     ` Peter Ujfalusi
  1 sibling, 1 reply; 20+ messages in thread
From: Vinod Koul @ 2019-09-08 12:06 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

On 06-09-19, 17:18, Peter Ujfalusi wrote:
> On systems where multiple DMA controllers available, none Slave (for example

On systems with multiple DMA controllers, non Slave...

> memcpy operation) users can not be described in DT as there is no device
> involved from the DMA controller's point of view, DMA binding is not usable.
> However in these systems still a peripheral might need to be serviced by or
> it is better to serviced by specific DMA controller.
> When a memcpy is used to/from a memory mapped region for example a DMA in the
> same domain can perform better.
> For generic software modules doing mem 2 mem operations it also matter that
> they will get a channel from a controller which is faster in DDR to DDR mode
> rather then from the first controller happen to be loaded.
> 
> This property is inherited, so it may be specified in a device node or in any
> of its parent nodes.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  .../devicetree/bindings/dma/dma-domain.yaml   | 59 +++++++++++++++++++
>  1 file changed, 59 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/dma/dma-domain.yaml
> 
> diff --git a/Documentation/devicetree/bindings/dma/dma-domain.yaml b/Documentation/devicetree/bindings/dma/dma-domain.yaml
> new file mode 100644
> index 000000000000..c2f182f30081
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/dma/dma-domain.yaml
> @@ -0,0 +1,59 @@
> +# SPDX-License-Identifier: GPL-2.0
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/dma/dma-controller.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: DMA Domain Controller Definition
> +
> +maintainers:
> +  - Vinod Koul <vkoul@kernel.org>
> +
> +allOf:
> +  - $ref: "dma-controller.yaml#"
> +
> +description:
> +  On systems where multiple DMA controllers available, none Slave (for example
> +  memcpy operation) users can not be described in DT as there is no device
> +  involved from the DMA controller's point of view, DMA binding is not usable.
> +  However in these systems still a peripheral might need to be serviced by or
> +  it is better to serviced by specific DMA controller.
> +  When a memcpy is used to/from a memory mapped region for example a DMA in the
> +  same domain can perform better.
> +  For generic software modules doing mem 2 mem operations it also matter that
> +  they will get a channel from a controller which is faster in DDR to DDR mode
> +  rather then from the first controller happen to be loaded.
> +
> +  This property is inherited, so it may be specified in a device node or in any
> +  of its parent nodes.
> +
> +properties:
> +  $dma-domain-controller:
> +    $ref: /schemas/types.yaml#definitions/phandle
> +    description:
> +      phande to the DMA controller node which should be used for the device or
> +      domain.
> +
> +examples:
> +  - |
> +    / {
> +        model = "Texas Instruments K3 AM654 SoC";
> +        compatible = "ti,am654";
> +        interrupt-parent = <&gic500>;
> +        /* For modules without device, DDR to DDR is faster on main UDMAP */
> +        dma-domain-controller = <&main_udmap>;
> +        #address-cells = <2>;
> +        #size-cells = <2>;
> +        ...
> +    };
> +
> +    &cbass_main {
> +        /* For modules within MAIN domain, use main UDMAP */
> +        dma-domain-controller = <&main_udmap>;
> +    };
> +
> +    &cbass_mcu {
> +        /* For modules within MCU domain, use mcu UDMAP */
> +        dma-domain-controller = <&mcu_udmap>;

perhaps add the example of main_udmap and mcu_udmap as well

> +    };
> +...
> -- 
> Peter
> 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

-- 
~Vinod

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-08  7:47   ` Peter Ujfalusi
@ 2019-09-08 12:10     ` Vinod Koul
  2019-09-09  6:30       ` Peter Ujfalusi
  0 siblings, 1 reply; 20+ messages in thread
From: Vinod Koul @ 2019-09-08 12:10 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

On 08-09-19, 10:47, Peter Ujfalusi wrote:
> 
> 
> On 06/09/2019 17.18, Peter Ujfalusi wrote:
> > On systems where multiple DMA controllers available, none Slave (for example
> > memcpy operation) users can not be described in DT as there is no device
> > involved from the DMA controller's point of view, DMA binding is not usable.
> > However in these systems still a peripheral might need to be serviced by or
> > it is better to serviced by specific DMA controller.
> > When a memcpy is used to/from a memory mapped region for example a DMA in the
> > same domain can perform better.
> > For generic software modules doing mem 2 mem operations it also matter that
> > they will get a channel from a controller which is faster in DDR to DDR mode
> > rather then from the first controller happen to be loaded.
> > 
> > This property is inherited, so it may be specified in a device node or in any
> > of its parent nodes.
> > 
> > Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> > ---
> >  .../devicetree/bindings/dma/dma-domain.yaml   | 59 +++++++++++++++++++
> >  1 file changed, 59 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/dma/dma-domain.yaml
> > 
> > diff --git a/Documentation/devicetree/bindings/dma/dma-domain.yaml b/Documentation/devicetree/bindings/dma/dma-domain.yaml
> > new file mode 100644
> > index 000000000000..c2f182f30081
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/dma/dma-domain.yaml
> > @@ -0,0 +1,59 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/dma/dma-controller.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: DMA Domain Controller Definition
> > +
> > +maintainers:
> > +  - Vinod Koul <vkoul@kernel.org>
> > +
> > +allOf:
> > +  - $ref: "dma-controller.yaml#"
> > +
> > +description:
> > +  On systems where multiple DMA controllers available, none Slave (for example
> > +  memcpy operation) users can not be described in DT as there is no device
> > +  involved from the DMA controller's point of view, DMA binding is not usable.
> > +  However in these systems still a peripheral might need to be serviced by or
> > +  it is better to serviced by specific DMA controller.
> > +  When a memcpy is used to/from a memory mapped region for example a DMA in the
> > +  same domain can perform better.
> > +  For generic software modules doing mem 2 mem operations it also matter that
> > +  they will get a channel from a controller which is faster in DDR to DDR mode
> > +  rather then from the first controller happen to be loaded.
> > +
> > +  This property is inherited, so it may be specified in a device node or in any
> > +  of its parent nodes.
> > +
> > +properties:
> > +  $dma-domain-controller:
> 
> or domain-dma-controller?

I feel dma-domain-controller sounds fine as we are defining domains for
dmaengine. Another thought which comes here is that why not extend this to
slave as well and define dma-domain-controller for them as use that for
filtering, that is what we really need along with slave id in case a
specific channel is to be used by a peripheral

Thoughts..?

-- 
~Vinod

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 2/3] dmaengine: of_dma: Function to look up the DMA domain of a client
  2019-09-06 14:18 ` [RFC 2/3] dmaengine: of_dma: Function to look up the DMA domain of a client Peter Ujfalusi
@ 2019-09-08 12:12   ` Vinod Koul
  0 siblings, 0 replies; 20+ messages in thread
From: Vinod Koul @ 2019-09-08 12:12 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

On 06-09-19, 17:18, Peter Ujfalusi wrote:
> Find the DMA domain controller of the client device by iterating up in
> device tree looking for the closest 'dma-domain-controller' property.
> 
> If the client's node is not provided then check the DT root for the
> controller.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  drivers/dma/of-dma.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
>  include/linux/of_dma.h |  7 +++++++
>  2 files changed, 49 insertions(+)
> 
> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
> index c2d779daa4b5..04b5795cd76b 100644
> --- a/drivers/dma/of-dma.c
> +++ b/drivers/dma/of-dma.c
> @@ -18,6 +18,48 @@
>  static LIST_HEAD(of_dma_list);
>  static DEFINE_MUTEX(of_dma_lock);
>  
> +/**
> + * of_find_dma_domain - Get the domain DMA controller
> + * @np:		device node of the client device
> + *
> + * Look up the DMA controller of the domain the client device is part of.
> + * Finds the dma-domain controller the client device belongs to. It is used when
> + * requesting non slave channels (like channel for memcpy) to make sure that the
> + * channel can be request from a DMA controller which can service the given
> + * domain best.
> + *
> + * Returns the device_node pointer of the DMA controller or succes or NULL on
> + * error.
> + */
> +struct device_node *of_find_dma_domain(struct device_node *np)
> +{
> +	struct device_node *dma_domain = NULL;
> +	phandle dma_phandle;
> +
> +	/*
> +	 * If no device_node is provided look at the root level for system
> +	 * default DMA controller for modules.
> +	 */
> +	if (!np)
> +		np = of_root;
> +
> +	if (!np || !of_node_get(np))
> +		return NULL;
> +
> +	do {
> +		if (of_property_read_u32(np, "dma-domain-controller",
> +					 &dma_phandle))
> +			np = of_get_next_parent(np);

lets have braces around if as well please

> +		else {
> +			dma_domain = of_find_node_by_phandle(dma_phandle);
> +			of_node_put(np);
> +		}
> +	} while (!dma_domain && np);
> +
> +	return dma_domain;
> +}
> +EXPORT_SYMBOL_GPL(of_find_dma_domain);
> +
>  /**
>   * of_dma_find_controller - Get a DMA controller in DT DMA helpers list
>   * @dma_spec:	pointer to DMA specifier as found in the device tree
> diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
> index fd706cdf255c..6eab0a8d3335 100644
> --- a/include/linux/of_dma.h
> +++ b/include/linux/of_dma.h
> @@ -32,6 +32,8 @@ struct of_dma_filter_info {
>  };
>  
>  #ifdef CONFIG_DMA_OF
> +extern struct device_node *of_find_dma_domain(struct device_node *np);
> +
>  extern int of_dma_controller_register(struct device_node *np,
>  		struct dma_chan *(*of_dma_xlate)
>  		(struct of_phandle_args *, struct of_dma *),
> @@ -52,6 +54,11 @@ extern struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec
>  		struct of_dma *ofdma);
>  
>  #else
> +static inline struct device_node *of_find_dma_domain(struct device_node *np)
> +{
> +	return NULL;
> +}
> +
>  static inline int of_dma_controller_register(struct device_node *np,
>  		struct dma_chan *(*of_dma_xlate)
>  		(struct of_phandle_args *, struct of_dma *),
> -- 
> Peter
> 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

-- 
~Vinod

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller
  2019-09-06 14:18 ` [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller Peter Ujfalusi
  2019-09-08  7:46   ` Peter Ujfalusi
@ 2019-09-08 12:15   ` Vinod Koul
  2019-09-09  5:56     ` Peter Ujfalusi
  1 sibling, 1 reply; 20+ messages in thread
From: Vinod Koul @ 2019-09-08 12:15 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

On 06-09-19, 17:18, Peter Ujfalusi wrote:
> In case the channel is not requested via the slave API, use the
> of_find_dma_domain() to see if a system default DMA controller is
> specified.
> 
> Add new function which can be used by clients to request channels by mask
> from their DMA domain controller if specified.
> 
> Client drivers can take advantage of the domain support by moving from
> dma_request_chan_by_mask() to dma_domain_request_chan_by_mask()
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  drivers/dma/dmaengine.c   | 17 ++++++++++++-----
>  include/linux/dmaengine.h |  9 ++++++---
>  2 files changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 6baddf7dcbfd..087450eed68c 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -640,6 +640,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
>  	struct dma_device *device, *_d;
>  	struct dma_chan *chan = NULL;
>  
> +	/* If np is not specified, get the default DMA domain controller */
> +	if (!np)
> +		np = of_find_dma_domain(NULL);
> +
>  	/* Find a channel */
>  	mutex_lock(&dma_list_mutex);
>  	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
> @@ -751,19 +755,22 @@ struct dma_chan *dma_request_slave_channel(struct device *dev,
>  EXPORT_SYMBOL_GPL(dma_request_slave_channel);
>  
>  /**
> - * dma_request_chan_by_mask - allocate a channel satisfying certain capabilities
> - * @mask: capabilities that the channel must satisfy
> + * dma_domain_request_chan_by_mask - allocate a channel by mask from DMA domain
> + * @dev:	pointer to client device structure
> + * @mask:	capabilities that the channel must satisfy
>   *
>   * Returns pointer to appropriate DMA channel on success or an error pointer.
>   */
> -struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
> +struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
> +						 const dma_cap_mask_t *mask)

should we really use dma_request_chan_by_mask() why not create a new api
dma_request_chan_by_domain() and use that, it falls back to
dma_request_chan_by_mask() if it doesnt find a valid domain!

-- 
~Vinod

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller
  2019-09-08 12:15   ` Vinod Koul
@ 2019-09-09  5:56     ` Peter Ujfalusi
  2019-09-12 16:49       ` Vinod Koul
  0 siblings, 1 reply; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-09  5:56 UTC (permalink / raw)
  To: Vinod Koul; +Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree



On 08/09/2019 15.15, Vinod Koul wrote:
> On 06-09-19, 17:18, Peter Ujfalusi wrote:
>> In case the channel is not requested via the slave API, use the
>> of_find_dma_domain() to see if a system default DMA controller is
>> specified.
>>
>> Add new function which can be used by clients to request channels by mask
>> from their DMA domain controller if specified.
>>
>> Client drivers can take advantage of the domain support by moving from
>> dma_request_chan_by_mask() to dma_domain_request_chan_by_mask()
>>
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>> ---
>>  drivers/dma/dmaengine.c   | 17 ++++++++++++-----
>>  include/linux/dmaengine.h |  9 ++++++---
>>  2 files changed, 18 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
>> index 6baddf7dcbfd..087450eed68c 100644
>> --- a/drivers/dma/dmaengine.c
>> +++ b/drivers/dma/dmaengine.c
>> @@ -640,6 +640,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
>>  	struct dma_device *device, *_d;
>>  	struct dma_chan *chan = NULL;
>>  
>> +	/* If np is not specified, get the default DMA domain controller */
>> +	if (!np)
>> +		np = of_find_dma_domain(NULL);
>> +
>>  	/* Find a channel */
>>  	mutex_lock(&dma_list_mutex);
>>  	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
>> @@ -751,19 +755,22 @@ struct dma_chan *dma_request_slave_channel(struct device *dev,
>>  EXPORT_SYMBOL_GPL(dma_request_slave_channel);
>>  
>>  /**
>> - * dma_request_chan_by_mask - allocate a channel satisfying certain capabilities
>> - * @mask: capabilities that the channel must satisfy
>> + * dma_domain_request_chan_by_mask - allocate a channel by mask from DMA domain
>> + * @dev:	pointer to client device structure
>> + * @mask:	capabilities that the channel must satisfy
>>   *
>>   * Returns pointer to appropriate DMA channel on success or an error pointer.
>>   */
>> -struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
>> +struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
>> +						 const dma_cap_mask_t *mask)
> 
> should we really use dma_request_chan_by_mask() why not create a new api
> dma_request_chan_by_domain() and use that, it falls back to
> dma_request_chan_by_mask() if it doesnt find a valid domain!

So:
struct dma_chan *dma_request_chan_by_domain(struct device *dev,
					    const dma_cap_mask_t *mask);

?

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-08 12:06   ` Vinod Koul
@ 2019-09-09  6:00     ` Peter Ujfalusi
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-09  6:00 UTC (permalink / raw)
  To: Vinod Koul; +Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree



On 08/09/2019 15.06, Vinod Koul wrote:
> On 06-09-19, 17:18, Peter Ujfalusi wrote:
>> On systems where multiple DMA controllers available, none Slave (for example
> 
> On systems with multiple DMA controllers, non Slave...

Sure.

>> memcpy operation) users can not be described in DT as there is no device
>> involved from the DMA controller's point of view, DMA binding is not usable.
>> However in these systems still a peripheral might need to be serviced by or
>> it is better to serviced by specific DMA controller.
>> When a memcpy is used to/from a memory mapped region for example a DMA in the
>> same domain can perform better.
>> For generic software modules doing mem 2 mem operations it also matter that
>> they will get a channel from a controller which is faster in DDR to DDR mode
>> rather then from the first controller happen to be loaded.
>>
>> This property is inherited, so it may be specified in a device node or in any
>> of its parent nodes.
>>
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>> ---
>>  .../devicetree/bindings/dma/dma-domain.yaml   | 59 +++++++++++++++++++
>>  1 file changed, 59 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/dma/dma-domain.yaml
>>
>> diff --git a/Documentation/devicetree/bindings/dma/dma-domain.yaml b/Documentation/devicetree/bindings/dma/dma-domain.yaml
>> new file mode 100644
>> index 000000000000..c2f182f30081
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/dma/dma-domain.yaml
>> @@ -0,0 +1,59 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/dma/dma-controller.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: DMA Domain Controller Definition
>> +
>> +maintainers:
>> +  - Vinod Koul <vkoul@kernel.org>
>> +
>> +allOf:
>> +  - $ref: "dma-controller.yaml#"
>> +
>> +description:
>> +  On systems where multiple DMA controllers available, none Slave (for example
>> +  memcpy operation) users can not be described in DT as there is no device
>> +  involved from the DMA controller's point of view, DMA binding is not usable.
>> +  However in these systems still a peripheral might need to be serviced by or
>> +  it is better to serviced by specific DMA controller.
>> +  When a memcpy is used to/from a memory mapped region for example a DMA in the
>> +  same domain can perform better.
>> +  For generic software modules doing mem 2 mem operations it also matter that
>> +  they will get a channel from a controller which is faster in DDR to DDR mode
>> +  rather then from the first controller happen to be loaded.
>> +
>> +  This property is inherited, so it may be specified in a device node or in any
>> +  of its parent nodes.
>> +
>> +properties:
>> +  $dma-domain-controller:
>> +    $ref: /schemas/types.yaml#definitions/phandle
>> +    description:
>> +      phande to the DMA controller node which should be used for the device or
>> +      domain.
>> +
>> +examples:
>> +  - |
>> +    / {
>> +        model = "Texas Instruments K3 AM654 SoC";
>> +        compatible = "ti,am654";
>> +        interrupt-parent = <&gic500>;
>> +        /* For modules without device, DDR to DDR is faster on main UDMAP */
>> +        dma-domain-controller = <&main_udmap>;
>> +        #address-cells = <2>;
>> +        #size-cells = <2>;
>> +        ...
>> +    };
>> +
>> +    &cbass_main {
>> +        /* For modules within MAIN domain, use main UDMAP */
>> +        dma-domain-controller = <&main_udmap>;
>> +    };
>> +
>> +    &cbass_mcu {
>> +        /* For modules within MCU domain, use mcu UDMAP */
>> +        dma-domain-controller = <&mcu_udmap>;
> 
> perhaps add the example of main_udmap and mcu_udmap as well

I can populate the tree with the main/mcu_udmap and on MCU I can also
add the OSPI node.
The idea is to specify the dma controller to be used for non slave
channels on every device on MAIN/MCU domain.
UDMAPs do not need this property specified, it is needed for clients.

> 
>> +    };
>> +...
>> -- 
>> Peter
>>
>> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
>> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-08 12:10     ` Vinod Koul
@ 2019-09-09  6:30       ` Peter Ujfalusi
  2019-09-12 17:03         ` Vinod Koul
  0 siblings, 1 reply; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-09  6:30 UTC (permalink / raw)
  To: Vinod Koul; +Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree



On 08/09/2019 15.10, Vinod Koul wrote:
> On 08-09-19, 10:47, Peter Ujfalusi wrote:
>>
>>
>> On 06/09/2019 17.18, Peter Ujfalusi wrote:
>>> On systems where multiple DMA controllers available, none Slave (for example
>>> memcpy operation) users can not be described in DT as there is no device
>>> involved from the DMA controller's point of view, DMA binding is not usable.
>>> However in these systems still a peripheral might need to be serviced by or
>>> it is better to serviced by specific DMA controller.
>>> When a memcpy is used to/from a memory mapped region for example a DMA in the
>>> same domain can perform better.
>>> For generic software modules doing mem 2 mem operations it also matter that
>>> they will get a channel from a controller which is faster in DDR to DDR mode
>>> rather then from the first controller happen to be loaded.
>>>
>>> This property is inherited, so it may be specified in a device node or in any
>>> of its parent nodes.
>>>
>>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>>> ---
>>>  .../devicetree/bindings/dma/dma-domain.yaml   | 59 +++++++++++++++++++
>>>  1 file changed, 59 insertions(+)
>>>  create mode 100644 Documentation/devicetree/bindings/dma/dma-domain.yaml
>>>
>>> diff --git a/Documentation/devicetree/bindings/dma/dma-domain.yaml b/Documentation/devicetree/bindings/dma/dma-domain.yaml
>>> new file mode 100644
>>> index 000000000000..c2f182f30081
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/dma/dma-domain.yaml
>>> @@ -0,0 +1,59 @@
>>> +# SPDX-License-Identifier: GPL-2.0
>>> +%YAML 1.2
>>> +---
>>> +$id: http://devicetree.org/schemas/dma/dma-controller.yaml#
>>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>>> +
>>> +title: DMA Domain Controller Definition
>>> +
>>> +maintainers:
>>> +  - Vinod Koul <vkoul@kernel.org>
>>> +
>>> +allOf:
>>> +  - $ref: "dma-controller.yaml#"
>>> +
>>> +description:
>>> +  On systems where multiple DMA controllers available, none Slave (for example
>>> +  memcpy operation) users can not be described in DT as there is no device
>>> +  involved from the DMA controller's point of view, DMA binding is not usable.
>>> +  However in these systems still a peripheral might need to be serviced by or
>>> +  it is better to serviced by specific DMA controller.
>>> +  When a memcpy is used to/from a memory mapped region for example a DMA in the
>>> +  same domain can perform better.
>>> +  For generic software modules doing mem 2 mem operations it also matter that
>>> +  they will get a channel from a controller which is faster in DDR to DDR mode
>>> +  rather then from the first controller happen to be loaded.
>>> +
>>> +  This property is inherited, so it may be specified in a device node or in any
>>> +  of its parent nodes.
>>> +
>>> +properties:
>>> +  $dma-domain-controller:
>>
>> or domain-dma-controller?
> 
> I feel dma-domain-controller sounds fine as we are defining domains for
> dmaengine. Another thought which comes here is that why not extend this to
> slave as well and define dma-domain-controller for them as use that for
> filtering, that is what we really need along with slave id in case a
> specific channel is to be used by a peripheral
> 
> Thoughts..?

I have thought about this, we should be able to drop the phandle to the
dma controller from the slave binding just fine.

However we have the dma routers for the slave channels and there is no
clear way to handle them.
They are not needed for non slave channels as there is no trigger to
route. In DRA7 for example we have an event router for EDMA and another
one for sDMA. If a slave device is to be serviced by EDMA, the EDMA
event router needs to be specified, for sDMA clients should use the sDMA
event router.
In DRA7 case we don't really have DMA controllers for domains, but we
use the DMA which can service the peripheral better (sDMA is better to
be used for UART, but can not be used for McASP for example)

Then we have the other type of DMA router for daVinci/am33xx/am43xx
where the crossbar is not for the whole EDMA controller like in DRA7,
but we have small crossbars for some channels.

Other vendors have their own dma router topology..

Too many variables to handle the cases without gotchas, which would need
heavy churn in the core or in drivers.

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller
  2019-09-09  5:56     ` Peter Ujfalusi
@ 2019-09-12 16:49       ` Vinod Koul
  0 siblings, 0 replies; 20+ messages in thread
From: Vinod Koul @ 2019-09-12 16:49 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

On 09-09-19, 08:56, Peter Ujfalusi wrote:

> >> -struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
> >> +struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
> >> +						 const dma_cap_mask_t *mask)
> > 
> > should we really use dma_request_chan_by_mask() why not create a new api
> > dma_request_chan_by_domain() and use that, it falls back to
> > dma_request_chan_by_mask() if it doesnt find a valid domain!
> 
> So:
> struct dma_chan *dma_request_chan_by_domain(struct device *dev,
> 					    const dma_cap_mask_t *mask);

Yeah that looks better to me :)

-- 
~Vinod

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-09  6:30       ` Peter Ujfalusi
@ 2019-09-12 17:03         ` Vinod Koul
  2019-09-13  7:21           ` Peter Ujfalusi
  0 siblings, 1 reply; 20+ messages in thread
From: Vinod Koul @ 2019-09-12 17:03 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

On 09-09-19, 09:30, Peter Ujfalusi wrote:

> >> or domain-dma-controller?
> > 
> > I feel dma-domain-controller sounds fine as we are defining domains for
> > dmaengine. Another thought which comes here is that why not extend this to
> > slave as well and define dma-domain-controller for them as use that for
> > filtering, that is what we really need along with slave id in case a
> > specific channel is to be used by a peripheral
> > 
> > Thoughts..?
> 
> I have thought about this, we should be able to drop the phandle to the
> dma controller from the slave binding just fine.
> 
> However we have the dma routers for the slave channels and there is no
> clear way to handle them.
> They are not needed for non slave channels as there is no trigger to
> route. In DRA7 for example we have an event router for EDMA and another
> one for sDMA. If a slave device is to be serviced by EDMA, the EDMA
> event router needs to be specified, for sDMA clients should use the sDMA
> event router.

So you have dma, xbar and client? And you need to use a specfic xbar,
did i get that right?

> In DRA7 case we don't really have DMA controllers for domains, but we
> use the DMA which can service the peripheral better (sDMA is better to
> be used for UART, but can not be used for McASP for example)
> 
> Then we have the other type of DMA router for daVinci/am33xx/am43xx
> where the crossbar is not for the whole EDMA controller like in DRA7,
> but we have small crossbars for some channels.
> 
> Other vendors have their own dma router topology..
> 
> Too many variables to handle the cases without gotchas, which would need
> heavy churn in the core or in drivers.

-- 
~Vinod

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-12 17:03         ` Vinod Koul
@ 2019-09-13  7:21           ` Peter Ujfalusi
  2019-09-13 10:36             ` Vinod Koul
  0 siblings, 1 reply; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-13  7:21 UTC (permalink / raw)
  To: Vinod Koul; +Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree



On 12/09/2019 20.03, Vinod Koul wrote:
> On 09-09-19, 09:30, Peter Ujfalusi wrote:
> 
>>>> or domain-dma-controller?
>>>
>>> I feel dma-domain-controller sounds fine as we are defining domains for
>>> dmaengine. Another thought which comes here is that why not extend this to
>>> slave as well and define dma-domain-controller for them as use that for
>>> filtering, that is what we really need along with slave id in case a
>>> specific channel is to be used by a peripheral
>>>
>>> Thoughts..?
>>
>> I have thought about this, we should be able to drop the phandle to the
>> dma controller from the slave binding just fine.
>>
>> However we have the dma routers for the slave channels and there is no
>> clear way to handle them.
>> They are not needed for non slave channels as there is no trigger to
>> route. In DRA7 for example we have an event router for EDMA and another
>> one for sDMA. If a slave device is to be serviced by EDMA, the EDMA
>> event router needs to be specified, for sDMA clients should use the sDMA
>> event router.
> 
> So you have dma, xbar and client? And you need to use a specfic xbar,
> did i get that right?

At the end yes.
EDMA have dedicated crossbar
sDMA have dedicated crossbar

Slave devices must use the crossbar to request channel from the DMA
controllers. Non slave request are directed to the controllers directly
(no DT binding).

At minimum we would need a new property for DMA routers.
dma-domain-router perhaps which is pointing to the xbar.

A slave channel request would first look for dma-domain-router, if it is
there, the request goes via that.
If not then look for dma-domain-controller and use it for the request.
The DMA binding can drop the phandle to the xbar/dma.

Request for not slave channel would only look for dma-domain-controller.

But...

- If we have one dedicated memcpy DMA and one for slave usage.
In top we declare dma-domain-controller = <&m2m_dma>;

Then you have  a slave client somewhere
client1: peripheral@42 {
	dma-domain-controller = <&slave_dma>;
	dmas = <6>, <7>;
	dma-names = "tx", "rx";
};

This is fine I guess. But what would we do if the driver for client1
needs additional memcpy channel? By the definition of the binding the
non slave channel should be taken from the closest dma-domain-controller
which is not what we want. We want the channel from m2m_dma.

And no, we can not start looking for the dma-domain-controller starting
from the root as in most cases the dma-domain-controller closer to the
client is what we really want and not the globally best controller.

- How to handle the transition?
If neither dma-domain-controller/router is found, assume that the first
argument in the binding is a phandle to the dma/router?
We need to carry the support for what we have today for a long time. The
kernel must boot with old DT blob.

- Will it make things cleaner? Atm it is pretty easy to see which
controller/router is used for which device.

- Also to note that the EDMA and sDMA bindings are different, so we can
not just swap dma-domain-controller/router underneath, we also need to
modify the client's dmas line as well.

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-13  7:21           ` Peter Ujfalusi
@ 2019-09-13 10:36             ` Vinod Koul
  2019-09-13 12:19               ` Peter Ujfalusi
  0 siblings, 1 reply; 20+ messages in thread
From: Vinod Koul @ 2019-09-13 10:36 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

On 13-09-19, 10:21, Peter Ujfalusi wrote:
> 
> 
> On 12/09/2019 20.03, Vinod Koul wrote:
> > On 09-09-19, 09:30, Peter Ujfalusi wrote:
> > 
> >>>> or domain-dma-controller?
> >>>
> >>> I feel dma-domain-controller sounds fine as we are defining domains for
> >>> dmaengine. Another thought which comes here is that why not extend this to
> >>> slave as well and define dma-domain-controller for them as use that for
> >>> filtering, that is what we really need along with slave id in case a
> >>> specific channel is to be used by a peripheral
> >>>
> >>> Thoughts..?
> >>
> >> I have thought about this, we should be able to drop the phandle to the
> >> dma controller from the slave binding just fine.
> >>
> >> However we have the dma routers for the slave channels and there is no
> >> clear way to handle them.
> >> They are not needed for non slave channels as there is no trigger to
> >> route. In DRA7 for example we have an event router for EDMA and another
> >> one for sDMA. If a slave device is to be serviced by EDMA, the EDMA
> >> event router needs to be specified, for sDMA clients should use the sDMA
> >> event router.
> > 
> > So you have dma, xbar and client? And you need to use a specfic xbar,
> > did i get that right?
> 
> At the end yes.

:)

> EDMA have dedicated crossbar
> sDMA have dedicated crossbar

So the domain mapping should point to crossbar.

> Slave devices must use the crossbar to request channel from the DMA
> controllers. Non slave request are directed to the controllers directly
> (no DT binding).

The clients for these are different right, if so slave clients will
point to domain xbar and non slave will point to domain controller (to
make everyone use domains). Non domain get any channel ... (fallback as
well)


> At minimum we would need a new property for DMA routers.
> dma-domain-router perhaps which is pointing to the xbar.

Precisely!

> A slave channel request would first look for dma-domain-router, if it is
> there, the request goes via that.
> If not then look for dma-domain-controller and use it for the request.
> The DMA binding can drop the phandle to the xbar/dma.
> Request for not slave channel would only look for dma-domain-controller.
>
> 
> But...
> 
> - If we have one dedicated memcpy DMA and one for slave usage.
> In top we declare dma-domain-controller = <&m2m_dma>;
> 
> Then you have  a slave client somewhere
> client1: peripheral@42 {
> 	dma-domain-controller = <&slave_dma>;
> 	dmas = <6>, <7>;
> 	dma-names = "tx", "rx";
> };
> 
> This is fine I guess. But what would we do if the driver for client1
> needs additional memcpy channel? By the definition of the binding the
> non slave channel should be taken from the closest dma-domain-controller
> which is not what we want. We want the channel from m2m_dma.

I would not envision same controller needs both memcpy or slave
channels. If so, that should be represented as something like dma-names
and represent two sets of dmas one for domain1 and another for domain2.

I would generalize it and not call it memcpy/slave but just domains and
have a controller use multiple domains (if we have a super controller
which can do that :D)

client1: peripheral@42 {
        dma-domain-names = "memcpy", "slave";
        dma-domains = <&mem_dma>, <&slave_dma>;
        ...
};


> 
> And no, we can not start looking for the dma-domain-controller starting
> from the root as in most cases the dma-domain-controller closer to the
> client is what we really want and not the globally best controller.
> 
> - How to handle the transition?
>
> If neither dma-domain-controller/router is found, assume that the first
> argument in the binding is a phandle to the dma/router?
> We need to carry the support for what we have today for a long time. The
> kernel must boot with old DT blob.
> 
> - Will it make things cleaner? Atm it is pretty easy to see which
> controller/router is used for which device.
> 
> - Also to note that the EDMA and sDMA bindings are different, so we can
> not just swap dma-domain-controller/router underneath, we also need to
> modify the client's dmas line as well.
> 
> - Péter
> 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

-- 
~Vinod

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-13 10:36             ` Vinod Koul
@ 2019-09-13 12:19               ` Peter Ujfalusi
  2019-09-13 13:33                 ` Vinod Koul
  0 siblings, 1 reply; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-13 12:19 UTC (permalink / raw)
  To: Vinod Koul; +Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

Vinod,

On 13/09/2019 13.36, Vinod Koul wrote:
>>> So you have dma, xbar and client? And you need to use a specfic xbar,
>>> did i get that right?
>>
>> At the end yes.
> 
> :)
> 
>> EDMA have dedicated crossbar
>> sDMA have dedicated crossbar
> 
> So the domain mapping should point to crossbar.
> 
>> Slave devices must use the crossbar to request channel from the DMA
>> controllers. Non slave request are directed to the controllers directly
>> (no DT binding).
> 
> The clients for these are different right, if so slave clients will
> point to domain xbar and non slave will point to domain controller (to
> make everyone use domains). Non domain get any channel ... (fallback as
> well)
> 
> 
>> At minimum we would need a new property for DMA routers.
>> dma-domain-router perhaps which is pointing to the xbar.
> 
> Precisely!

After some thinking at the end we have two main type of DMA channels:
slave channels: Hw triggered channels
non-slave channels: SW triggered channels w/o DMA request lines

right?

Slave channels must be described in DT as we need to specify the DMA
request number/line/trigger, whatever it is called on different platforms.

non-slave channels on the other hand can be requested from any
controllers which can execute it. Or in the scope of this series, from
the controller which is best suited to service the device or module.

If we really want to move to similar binding structure as interrupts
opposed to what we have atm (gpio, pwm, leds, etc uses the same
principle), then

dma-slave-controller: can point to a dma controller or dma router which
should be used from the node it is presented inherited by it's child
nodes for slave channels.

dma-nonslave-controller: can point to a dma controller which should be
used from the node it is presented inherited by it's child nodes for non
slave channels.

DMA routers have the phandle for the dma controller they are attached
to, so this should be fine, I guess.

Based on the topology of the SoC, these can be added in higher level in
the tree to divert from the higher level controller selection.

>> A slave channel request would first look for dma-domain-router, if it is
>> there, the request goes via that.
>> If not then look for dma-domain-controller and use it for the request.
>> The DMA binding can drop the phandle to the xbar/dma.
>> Request for not slave channel would only look for dma-domain-controller.
>>
>>
>> But...
>>
>> - If we have one dedicated memcpy DMA and one for slave usage.
>> In top we declare dma-domain-controller = <&m2m_dma>;
>>
>> Then you have  a slave client somewhere
>> client1: peripheral@42 {
>> 	dma-domain-controller = <&slave_dma>;
>> 	dmas = <6>, <7>;
>> 	dma-names = "tx", "rx";
>> };
>>
>> This is fine I guess. But what would we do if the driver for client1
>> needs additional memcpy channel? By the definition of the binding the
>> non slave channel should be taken from the closest dma-domain-controller
>> which is not what we want. We want the channel from m2m_dma.
> 
> I would not envision same controller needs both memcpy or slave
> channels. If so, that should be represented as something like dma-names
> and represent two sets of dmas one for domain1 and another for domain2.
> 
> I would generalize it and not call it memcpy/slave but just domains and
> have a controller use multiple domains (if we have a super controller
> which can do that :D)
> 
> client1: peripheral@42 {
>         dma-domain-names = "memcpy", "slave";
>         dma-domains = <&mem_dma>, <&slave_dma>;
>         ...
> };

Right, similar thing should work, I guess.

/ {
	/* DDR to DDR is used in main_udmap */
	dma-domain-names = "memcpy";
	dma-domains = <&main_udmap>;

	cbass_main {
		/* memcpy is from main_udmap and slaves also */
		dma-domain-names = "slave";
		dma-domains = <&main_udmap>;

		cbass_mcu {
			/* memcpy is from mcu_udmap and slaves also */
			dma-domain-names = "memcpy", "slave";
			dma-domains = <&mcu_udmap>, <&mcu_udmap>;

		};
	};
};

or

/ {
	/* memcpy is from edma and slaves also */
	dma-domain-names = "memcpy", "slave";
	dma-domains = <&edma>, <&edma>;

	edma_xbar1 xbar@0 {
		/*
		 * DMA router on front of edma,
		 * optionally can be explicitly tell the DMA controller
		 * to be used with the router if needed.
		 */

		dma-domain-names = "slave";
		dma-domains = <&main_udmap>;
	};

	mcbsp muxed_dma@0 {
		/* memcpy is from edma and slaves from edma_xbar1 */
		dma-domain-names = "slave";
		dma-domains = <&edma_xbar1>;
	};

	voice muxed_dma@1 {
		/* memcpy is from edma and slaves from edma_xbar1 */
		dma-domain-names = "slave";
		dma-domains = <&edma_xbar1>;
	};

	something not_muxed@0 {
		/* memcpy is from edma and slaves also */
	};
};

Even the DMA router binding can be changed to look for the "slave"
domain it belongs to?

The the dmas can drop the phandle to the controller/router

Internal API wise, things could use
dmaengine_get_slave_domain(struct device *client_dev);
if we get a domain, we know the the binding does not include the phandle
for the controller.

and
dmaengine_get_nonslave_domain(struct device *client_dev);

The DMA routers and drivers might need to be changed, not sure if they
would notice the drop of the first phandle from the binding...

>>
>> And no, we can not start looking for the dma-domain-controller starting
>> from the root as in most cases the dma-domain-controller closer to the
>> client is what we really want and not the globally best controller.
>>
>> - How to handle the transition?
>>
>> If neither dma-domain-controller/router is found, assume that the first
>> argument in the binding is a phandle to the dma/router?
>> We need to carry the support for what we have today for a long time. The
>> kernel must boot with old DT blob.
>>
>> - Will it make things cleaner? Atm it is pretty easy to see which
>> controller/router is used for which device.

Is this big change worth to push for?


>> - Also to note that the EDMA and sDMA bindings are different, so we can
>> not just swap dma-domain-controller/router underneath, we also need to
>> modify the client's dmas line as well.
>>
>> - Péter
>>
>> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
>> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains
  2019-09-13 12:19               ` Peter Ujfalusi
@ 2019-09-13 13:33                 ` Vinod Koul
  0 siblings, 0 replies; 20+ messages in thread
From: Vinod Koul @ 2019-09-13 13:33 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: robh+dt, dmaengine, linux-kernel, dan.j.williams, devicetree

On 13-09-19, 15:19, Peter Ujfalusi wrote:
> Vinod,
> 
> On 13/09/2019 13.36, Vinod Koul wrote:
> >>> So you have dma, xbar and client? And you need to use a specfic xbar,
> >>> did i get that right?
> >>
> >> At the end yes.
> > 
> > :)
> > 
> >> EDMA have dedicated crossbar
> >> sDMA have dedicated crossbar
> > 
> > So the domain mapping should point to crossbar.
> > 
> >> Slave devices must use the crossbar to request channel from the DMA
> >> controllers. Non slave request are directed to the controllers directly
> >> (no DT binding).
> > 
> > The clients for these are different right, if so slave clients will
> > point to domain xbar and non slave will point to domain controller (to
> > make everyone use domains). Non domain get any channel ... (fallback as
> > well)
> > 
> > 
> >> At minimum we would need a new property for DMA routers.
> >> dma-domain-router perhaps which is pointing to the xbar.
> > 
> > Precisely!
> 
> After some thinking at the end we have two main type of DMA channels:
> slave channels: Hw triggered channels
> non-slave channels: SW triggered channels w/o DMA request lines
> 
> right?

yes and no

You are correct in saying this but I would like to move away from the
two concepts and generalize them a bit, it is long overdue.

So from domain point of view, we have channels (memcpy/slave) specifying
one or more domains to use or no domain (memcpy, any channel)

> Slave channels must be described in DT as we need to specify the DMA
> request number/line/trigger, whatever it is called on different platforms.

So in the cases where a specific channel/request/trigger is required, we
would be required to specify that in DT as we do currently, but more
modern controllers which uses muxes wont need this to be specified,
pointing to domain (which can be controller/xbar) would do the trick!


> non-slave channels on the other hand can be requested from any
> controllers which can execute it. Or in the scope of this series, from
> the controller which is best suited to service the device or module.

Right which takes care of your new requirement as well as older ones

> If we really want to move to similar binding structure as interrupts
> opposed to what we have atm (gpio, pwm, leds, etc uses the same
> principle), then
> 
> dma-slave-controller: can point to a dma controller or dma router which
> should be used from the node it is presented inherited by it's child
> nodes for slave channels.
> 
> dma-nonslave-controller: can point to a dma controller which should be
> used from the node it is presented inherited by it's child nodes for non
> slave channels.
> 
> DMA routers have the phandle for the dma controller they are attached
> to, so this should be fine, I guess.
> 
> Based on the topology of the SoC, these can be added in higher level in
> the tree to divert from the higher level controller selection.

Looks interesting to me and doable. But as I said earlier, lets do a bit
more generalization in concepts please

> >> A slave channel request would first look for dma-domain-router, if it is
> >> there, the request goes via that.
> >> If not then look for dma-domain-controller and use it for the request.
> >> The DMA binding can drop the phandle to the xbar/dma.
> >> Request for not slave channel would only look for dma-domain-controller.
> >>
> >>
> >> But...
> >>
> >> - If we have one dedicated memcpy DMA and one for slave usage.
> >> In top we declare dma-domain-controller = <&m2m_dma>;
> >>
> >> Then you have  a slave client somewhere
> >> client1: peripheral@42 {
> >> 	dma-domain-controller = <&slave_dma>;
> >> 	dmas = <6>, <7>;
> >> 	dma-names = "tx", "rx";
> >> };
> >>
> >> This is fine I guess. But what would we do if the driver for client1
> >> needs additional memcpy channel? By the definition of the binding the
> >> non slave channel should be taken from the closest dma-domain-controller
> >> which is not what we want. We want the channel from m2m_dma.
> > 
> > I would not envision same controller needs both memcpy or slave
> > channels. If so, that should be represented as something like dma-names
> > and represent two sets of dmas one for domain1 and another for domain2.
> > 
> > I would generalize it and not call it memcpy/slave but just domains and
> > have a controller use multiple domains (if we have a super controller
> > which can do that :D)
> > 
> > client1: peripheral@42 {
> >         dma-domain-names = "memcpy", "slave";
> >         dma-domains = <&mem_dma>, <&slave_dma>;
> >         ...
> > };
> 
> Right, similar thing should work, I guess.
> 
> / {
> 	/* DDR to DDR is used in main_udmap */
> 	dma-domain-names = "memcpy";
> 	dma-domains = <&main_udmap>;
> 
> 	cbass_main {
> 		/* memcpy is from main_udmap and slaves also */
> 		dma-domain-names = "slave";
> 		dma-domains = <&main_udmap>;
> 
> 		cbass_mcu {
> 			/* memcpy is from mcu_udmap and slaves also */
> 			dma-domain-names = "memcpy", "slave";
> 			dma-domains = <&mcu_udmap>, <&mcu_udmap>;
> 
> 		};
> 	};
> };
> 
> or
> 
> / {
> 	/* memcpy is from edma and slaves also */
> 	dma-domain-names = "memcpy", "slave";
> 	dma-domains = <&edma>, <&edma>;
> 
> 	edma_xbar1 xbar@0 {
> 		/*
> 		 * DMA router on front of edma,
> 		 * optionally can be explicitly tell the DMA controller
> 		 * to be used with the router if needed.
> 		 */
> 
> 		dma-domain-names = "slave";
> 		dma-domains = <&main_udmap>;
> 	};
> 
> 	mcbsp muxed_dma@0 {
> 		/* memcpy is from edma and slaves from edma_xbar1 */
> 		dma-domain-names = "slave";
> 		dma-domains = <&edma_xbar1>;
> 	};
> 
> 	voice muxed_dma@1 {
> 		/* memcpy is from edma and slaves from edma_xbar1 */
> 		dma-domain-names = "slave";
> 		dma-domains = <&edma_xbar1>;
> 	};
> 
> 	something not_muxed@0 {
> 		/* memcpy is from edma and slaves also */
> 	};
> };
> 
> Even the DMA router binding can be changed to look for the "slave"
> domain it belongs to?
> 
> The the dmas can drop the phandle to the controller/router
> 
> Internal API wise, things could use
> dmaengine_get_slave_domain(struct device *client_dev);
> if we get a domain, we know the the binding does not include the phandle
> for the controller.
> 
> and
> dmaengine_get_nonslave_domain(struct device *client_dev);
> 
> The DMA routers and drivers might need to be changed, not sure if they
> would notice the drop of the first phandle from the binding...
> 
> >>
> >> And no, we can not start looking for the dma-domain-controller starting
> >> from the root as in most cases the dma-domain-controller closer to the
> >> client is what we really want and not the globally best controller.
> >>
> >> - How to handle the transition?
> >>
> >> If neither dma-domain-controller/router is found, assume that the first
> >> argument in the binding is a phandle to the dma/router?
> >> We need to carry the support for what we have today for a long time. The
> >> kernel must boot with old DT blob.
> >>
> >> - Will it make things cleaner? Atm it is pretty easy to see which
> >> controller/router is used for which device.
> 
> Is this big change worth to push for?
> 
> 
> >> - Also to note that the EDMA and sDMA bindings are different, so we can
> >> not just swap dma-domain-controller/router underneath, we also need to
> >> modify the client's dmas line as well.
> >>
> >> - Péter
> >>
> >> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> >> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
> > 
> 
> - Péter
> 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

-- 
~Vinod

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller
  2019-09-06 14:17 [RFC 0/3] dmaengine: Support for DMA domain controllers Peter Ujfalusi
@ 2019-09-06 14:17 ` Peter Ujfalusi
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Ujfalusi @ 2019-09-06 14:17 UTC (permalink / raw)
  To: vinod.koul, robh+dt; +Cc: dmaengine, linux-kernel, dan.j.williams, devicetree

In case the channel is not requested via the slave API, use the
of_find_dma_domain() to see if a system default DMA controller is
specified.

Add new function which can be used by clients to request channels by mask
from their DMA domain controller if specified.

Client drivers can take advantage of the domain support by moving from
dma_request_chan_by_mask() to dma_domain_request_chan_by_mask()

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/dma/dmaengine.c   | 17 ++++++++++++-----
 include/linux/dmaengine.h |  9 ++++++---
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 6baddf7dcbfd..087450eed68c 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -640,6 +640,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 	struct dma_device *device, *_d;
 	struct dma_chan *chan = NULL;
 
+	/* If np is not specified, get the default DMA domain controller */
+	if (!np)
+		np = of_find_dma_domain(NULL);
+
 	/* Find a channel */
 	mutex_lock(&dma_list_mutex);
 	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
@@ -751,19 +755,22 @@ struct dma_chan *dma_request_slave_channel(struct device *dev,
 EXPORT_SYMBOL_GPL(dma_request_slave_channel);
 
 /**
- * dma_request_chan_by_mask - allocate a channel satisfying certain capabilities
- * @mask: capabilities that the channel must satisfy
+ * dma_domain_request_chan_by_mask - allocate a channel by mask from DMA domain
+ * @dev:	pointer to client device structure
+ * @mask:	capabilities that the channel must satisfy
  *
  * Returns pointer to appropriate DMA channel on success or an error pointer.
  */
-struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
+struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
+						 const dma_cap_mask_t *mask)
 {
 	struct dma_chan *chan;
 
 	if (!mask)
 		return ERR_PTR(-ENODEV);
 
-	chan = __dma_request_channel(mask, NULL, NULL, NULL);
+	chan = __dma_request_channel(mask, NULL, NULL,
+				     of_find_dma_domain(dev->of_node));
 	if (!chan) {
 		mutex_lock(&dma_list_mutex);
 		if (list_empty(&dma_device_list))
@@ -775,7 +782,7 @@ struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
 
 	return chan;
 }
-EXPORT_SYMBOL_GPL(dma_request_chan_by_mask);
+EXPORT_SYMBOL_GPL(dma_domain_request_chan_by_mask);
 
 void dma_release_channel(struct dma_chan *chan)
 {
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 3b2e8e302f6c..9f94df81e83f 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1438,7 +1438,8 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
 
 struct dma_chan *dma_request_chan(struct device *dev, const char *name);
-struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
+struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
+						 const dma_cap_mask_t *mask);
 
 void dma_release_channel(struct dma_chan *chan);
 int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
@@ -1475,8 +1476,8 @@ static inline struct dma_chan *dma_request_chan(struct device *dev,
 {
 	return ERR_PTR(-ENODEV);
 }
-static inline struct dma_chan *dma_request_chan_by_mask(
-						const dma_cap_mask_t *mask)
+static inline struct dma_chan *dma_domain_request_chan_by_mask(struct device *dev,
+			const dma_cap_mask_t *mask)
 {
 	return ERR_PTR(-ENODEV);
 }
@@ -1537,6 +1538,8 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
 	__dma_request_channel(&(mask), x, y, NULL)
 #define dma_request_slave_channel_compat(mask, x, y, dev, name) \
 	__dma_request_slave_channel_compat(&(mask), x, y, dev, name)
+#define dma_request_chan_by_mask(mask) \
+	dma_domain_request_chan_by_mask(NULL, mask)
 
 static inline struct dma_chan
 *__dma_request_slave_channel_compat(const dma_cap_mask_t *mask,
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, back to index

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 14:18 [RFC 0/3] dmaengine: Support for DMA domain controllers Peter Ujfalusi
2019-09-06 14:18 ` [RFC 1/3] dt-bindings: dma: Add documentation for DMA domains Peter Ujfalusi
2019-09-08  7:47   ` Peter Ujfalusi
2019-09-08 12:10     ` Vinod Koul
2019-09-09  6:30       ` Peter Ujfalusi
2019-09-12 17:03         ` Vinod Koul
2019-09-13  7:21           ` Peter Ujfalusi
2019-09-13 10:36             ` Vinod Koul
2019-09-13 12:19               ` Peter Ujfalusi
2019-09-13 13:33                 ` Vinod Koul
2019-09-08 12:06   ` Vinod Koul
2019-09-09  6:00     ` Peter Ujfalusi
2019-09-06 14:18 ` [RFC 2/3] dmaengine: of_dma: Function to look up the DMA domain of a client Peter Ujfalusi
2019-09-08 12:12   ` Vinod Koul
2019-09-06 14:18 ` [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller Peter Ujfalusi
2019-09-08  7:46   ` Peter Ujfalusi
2019-09-08 12:15   ` Vinod Koul
2019-09-09  5:56     ` Peter Ujfalusi
2019-09-12 16:49       ` Vinod Koul
  -- strict thread matches above, loose matches on Subject: below --
2019-09-06 14:17 [RFC 0/3] dmaengine: Support for DMA domain controllers Peter Ujfalusi
2019-09-06 14:17 ` [RFC 3/3] dmaengine: Support for requesting channels preferring DMA domain controller Peter Ujfalusi

dmaengine Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dmaengine/0 dmaengine/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dmaengine dmaengine/ https://lore.kernel.org/dmaengine \
		dmaengine@vger.kernel.org dmaengine@archiver.kernel.org
	public-inbox-index dmaengine

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.dmaengine


AGPL code for this site: git clone https://public-inbox.org/ public-inbox