Skip to contentSkip to conversation

remoteproc: get rproc devices for clusters

PATCH RESEND Superseded Tanmay Shah 3 participants 7 messages Oct 14, 2023 – Jan 2, 2024 Remote processor (remoteproc)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover remoteproc: get rproc devices for clusters

This series extends original patch and makes rproc_put() work for clusters along with rprog_get_by_phandle().

Changes in v3:
- remove module_put call that was introduced in the patch by mistake
- remove redundant check in rproc_put
- Add inline comments in rproc_put that explains functionality

Changes in v2:
- Introduce patch to fix rproc_put as per modified rproc_get_by_phandle

v1 is here: https://lore.kernel.org/all/[email protected]/

Mathieu Poirier (1):
remoteproc: Make rproc_get_by_phandle() work for clusters

Tanmay Shah (1):
remoteproc: enhance rproc_put() for clusters

 drivers/remoteproc/remoteproc_core.c | 45 ++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

base-commit: a7d272979d3a89b117ca2c547dc8a465c4f28635

Signature · 1 line
2.25.1
#1 lore raw

PATCH RESEND v3 1/2 remoteproc: Make rproc_get_by_phandle() work for clusters

From: Mathieu Poirier <[email protected]>

Multi-cluster remoteproc designs typically have the following DT declaration:

	remoteproc_cluster {
		compatible = "soc,remoteproc-cluster";

                core0: core0 {
			compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                };

                core1: core1 {
			compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                }
        };

A driver exists for the cluster rather than the individual cores themselves so that operation mode and HW specific configurations applicable to the cluster can be made.

Because the driver exists at the cluster level and not the individual core level, function rproc_get_by_phandle() fails to return the remoteproc associated with the phandled it is called for.

This patch enhances rproc_get_by_phandle() by looking for the cluster's driver when the driver for the immediate remoteproc's parent is not found.

---
 drivers/remoteproc/remoteproc_core.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +27 -1
index 695cce218e8c..3a8191803885 100644
@@ -33,6 +33,7 @@
 #include <linux/idr.h>
 #include <linux/elf.h>
 #include <linux/crc32.h>
+#include <linux/of_platform.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/virtio_ids.h>
 #include <linux/virtio_ring.h>
@@ -2111,7 +2112,9 @@ EXPORT_SYMBOL(rproc_detach);
 #ifdef CONFIG_OF
 struct rproc *rproc_get_by_phandle(phandle phandle)
 {
+	struct platform_device *cluster_pdev;
 	struct rproc *rproc = NULL, *r;
+	struct device_driver *driver;
 	struct device_node *np;
 
 	np = of_find_node_by_phandle(phandle);
@@ -2122,7 +2125,30 @@ struct rproc *rproc_get_by_phandle(phandle phandle)
 	list_for_each_entry_rcu(r, &rproc_list, node) {
 		if (r->dev.parent && device_match_of_node(r->dev.parent, np)) {
 			/* prevent underlying implementation from being removed */
-			if (!try_module_get(r->dev.parent->driver->owner)) {
+
+			/*
+			 * If the remoteproc's parent has a driver, the
+			 * remoteproc is not part of a cluster and we can use
+			 * that driver.
+			 */
+			driver = r->dev.parent->driver;
+
+			/*
+			 * If the remoteproc's parent does not have a driver,
+			 * look for the driver associated with the cluster.
+			 */
+			if (!driver) {
+				cluster_pdev = of_find_device_by_node(np->parent);
+				if (!cluster_pdev) {
+					dev_err(&r->dev, "can't get parent\n");
+					break;
+				}
+
+				driver = cluster_pdev->dev.driver;
+				put_device(&cluster_pdev->dev);
+			}
+
+			if (!try_module_get(driver->owner)) {
 				dev_err(&r->dev, "can't get owner\n");
 				break;
 			}
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [RESEND PATCH v3 1/2] remoteproc: Make rproc_get_by_phandle() work for clusters

Quoted 71 lines · Tanmay Shah

From: Mathieu Poirier <[email protected]>

Multi-cluster remoteproc designs typically have the following DT declaration:

	remoteproc_cluster {
		compatible = "soc,remoteproc-cluster";

                core0: core0 {
			compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                };

                core1: core1 {
			compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                }
        };

A driver exists for the cluster rather than the individual cores themselves so that operation mode and HW specific configurations applicable to the cluster can be made.

Because the driver exists at the cluster level and not the individual core level, function rproc_get_by_phandle() fails to return the remoteproc associated with the phandled it is called for.

This patch enhances rproc_get_by_phandle() by looking for the cluster's driver when the driver for the immediate remoteproc's parent is not found.

---
 drivers/remoteproc/remoteproc_core.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +7 -1
index 695cce218e8c..3a8191803885 100644
@@ -33,6 +33,7 @@
 #include <linux/idr.h>
 #include <linux/elf.h>
 #include <linux/crc32.h>
+#include <linux/of_platform.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/virtio_ids.h>
 #include <linux/virtio_ring.h>
@@ -2111,7 +2112,9 @@ EXPORT_SYMBOL(rproc_detach);
 #ifdef CONFIG_OF
 struct rproc *rproc_get_by_phandle(phandle phandle)
 {
+	struct platform_device *cluster_pdev;
 	struct rproc *rproc = NULL, *r;
+	struct device_driver *driver;
 	struct device_node *np;
 
 	np = of_find_node_by_phandle(phandle);
@@ -2122,7 +2125,30 @@ struct rproc *rproc_get_by_phandle(phandle phandle)
 	list_for_each_entry_rcu(r, &rproc_list, node) {
 		if (r->dev.parent && device_match_of_node(r->dev.parent, np)) {
 			/* prevent underlying implementation from being removed */
-			if (!try_module_get(r->dev.parent->driver->owner)) {
+
+			/*
+			 * If the remoteproc's parent has a driver, the
+			 * remoteproc is not part of a cluster and we can use

drivers/remoteproc/remoteproc_core.c struct rproc *rproc_get_by_phandle(phandle phandle) · line 2141

Quoted 10 lines
drivers/remoteproc/remoteproc_core.c +10 -0
+			 * that driver.
+			 */
+			driver = r->dev.parent->driver;
+
+			/*
+			 * If the remoteproc's parent does not have a driver,
+			 * look for the driver associated with the cluster.
+			 */
+			if (!driver) {
+				cluster_pdev = of_find_device_by_node(np->parent);

Both the Ti and Xilinx drivers are using of_platform_populate(), so their r->dev.parent should have a parent reference to the cluster device.

Unless I'm reading the code wrong, I think we should follow that pointer, rather than taking the detour in the DeviceTree data.

Regards,
Bjorn

Quoted 16 lines
drivers/remoteproc/remoteproc_core.c +10 -0
+				if (!cluster_pdev) {
+					dev_err(&r->dev, "can't get parent\n");
+					break;
+				}
+
+				driver = cluster_pdev->dev.driver;
+				put_device(&cluster_pdev->dev);
+			}
+
+			if (!try_module_get(driver->owner)) {
 				dev_err(&r->dev, "can't get owner\n");
 				break;
 			}
Signature · 1 line
2.25.1
maintainer
#3 lore raw

Re: [RESEND PATCH v3 1/2] remoteproc: Make rproc_get_by_phandle() work for clusters

Quoted 79 lines · Bjorn Andersson
Quoted 77 lines · Tanmay Shah

From: Mathieu Poirier <[email protected]>

Multi-cluster remoteproc designs typically have the following DT declaration:

      remoteproc_cluster {
              compatible = "soc,remoteproc-cluster";

                core0: core0 {
                      compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                };

                core1: core1 {
                      compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                }
        };

A driver exists for the cluster rather than the individual cores themselves so that operation mode and HW specific configurations applicable to the cluster can be made.

Because the driver exists at the cluster level and not the individual core level, function rproc_get_by_phandle() fails to return the remoteproc associated with the phandled it is called for.

This patch enhances rproc_get_by_phandle() by looking for the cluster's driver when the driver for the immediate remoteproc's parent is not found.

---
 drivers/remoteproc/remoteproc_core.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +13 -1
index 695cce218e8c..3a8191803885 100644
@@ -33,6 +33,7 @@
 #include <linux/idr.h>
 #include <linux/elf.h>
 #include <linux/crc32.h>
+#include <linux/of_platform.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/virtio_ids.h>
 #include <linux/virtio_ring.h>
@@ -2111,7 +2112,9 @@ EXPORT_SYMBOL(rproc_detach);
 #ifdef CONFIG_OF
 struct rproc *rproc_get_by_phandle(phandle phandle)
 {
+     struct platform_device *cluster_pdev;
      struct rproc *rproc = NULL, *r;
+     struct device_driver *driver;
      struct device_node *np;
 
      np = of_find_node_by_phandle(phandle);
@@ -2122,7 +2125,30 @@ struct rproc *rproc_get_by_phandle(phandle phandle)
      list_for_each_entry_rcu(r, &rproc_list, node) {
              if (r->dev.parent && device_match_of_node(r->dev.parent, np)) {
                      /* prevent underlying implementation from being removed */
-                     if (!try_module_get(r->dev.parent->driver->owner)) {
+
+                     /*
+                      * If the remoteproc's parent has a driver, the
+                      * remoteproc is not part of a cluster and we can use
+                      * that driver.
+                      */
+                     driver = r->dev.parent->driver;
+
+                     /*
+                      * If the remoteproc's parent does not have a driver,
Quoted 9 lines

drivers/remoteproc/remoteproc_core.c struct rproc *rproc_get_by_phandle(phandle phandle) · line 2141

Quoted 4 lines
drivers/remoteproc/remoteproc_core.c +4 -0
+                      * look for the driver associated with the cluster.
+                      */
+                     if (!driver) {
+                             cluster_pdev = of_find_device_by_node(np->parent);

Both the Ti and Xilinx drivers are using of_platform_populate(), so their r->dev.parent should have a parent reference to the cluster device.

So you are proposing to get the cluster's driver using something like r->dev.parent->parent->driver?

I will have to verify the parent/child relationship is set up properly through the of_platform_populate(). If it is, following the pointer trail is an equally valid approach and I will respin this set.

Quoted 22 lines

Unless I'm reading the code wrong, I think we should follow that pointer, rather than taking the detour in the DeviceTree data.

Regards,
Bjorn

Quoted 16 lines
drivers/remoteproc/remoteproc_core.c +10 -1
+                             if (!cluster_pdev) {
+                                     dev_err(&r->dev, "can't get parent\n");
+                                     break;
+                             }
+
+                             driver = cluster_pdev->dev.driver;
+                             put_device(&cluster_pdev->dev);
+                     }
+
+                     if (!try_module_get(driver->owner)) {
                              dev_err(&r->dev, "can't get owner\n");
                              break;
                      }
--

2.25.1

#4 lore raw

Re: [RESEND PATCH v3 1/2] remoteproc: Make rproc_get_by_phandle() work for clusters

Quoted 90 lines · Mathieu Poirier
Quoted 79 lines · Bjorn Andersson
Quoted 77 lines · Tanmay Shah

From: Mathieu Poirier <[email protected]>

Multi-cluster remoteproc designs typically have the following DT declaration:

      remoteproc_cluster {
              compatible = "soc,remoteproc-cluster";

                core0: core0 {
                      compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                };

                core1: core1 {
                      compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                }
        };

A driver exists for the cluster rather than the individual cores themselves so that operation mode and HW specific configurations applicable to the cluster can be made.

Because the driver exists at the cluster level and not the individual core level, function rproc_get_by_phandle() fails to return the remoteproc associated with the phandled it is called for.

This patch enhances rproc_get_by_phandle() by looking for the cluster's driver when the driver for the immediate remoteproc's parent is not found.

---
 drivers/remoteproc/remoteproc_core.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +13 -1
index 695cce218e8c..3a8191803885 100644
@@ -33,6 +33,7 @@
 #include <linux/idr.h>
 #include <linux/elf.h>
 #include <linux/crc32.h>
+#include <linux/of_platform.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/virtio_ids.h>
 #include <linux/virtio_ring.h>
@@ -2111,7 +2112,9 @@ EXPORT_SYMBOL(rproc_detach);
 #ifdef CONFIG_OF
 struct rproc *rproc_get_by_phandle(phandle phandle)
 {
+     struct platform_device *cluster_pdev;
      struct rproc *rproc = NULL, *r;
+     struct device_driver *driver;
      struct device_node *np;
 
      np = of_find_node_by_phandle(phandle);
@@ -2122,7 +2125,30 @@ struct rproc *rproc_get_by_phandle(phandle phandle)
      list_for_each_entry_rcu(r, &rproc_list, node) {
              if (r->dev.parent && device_match_of_node(r->dev.parent, np)) {
                      /* prevent underlying implementation from being removed */
-                     if (!try_module_get(r->dev.parent->driver->owner)) {
+
+                     /*
+                      * If the remoteproc's parent has a driver, the
+                      * remoteproc is not part of a cluster and we can use
+                      * that driver.
+                      */
+                     driver = r->dev.parent->driver;
+
+                     /*
+                      * If the remoteproc's parent does not have a driver,
Quoted 9 lines

drivers/remoteproc/remoteproc_core.c struct rproc *rproc_get_by_phandle(phandle phandle) · line 2141

Quoted 4 lines
drivers/remoteproc/remoteproc_core.c +4 -0
+                      * look for the driver associated with the cluster.
+                      */
+                     if (!driver) {
+                             cluster_pdev = of_find_device_by_node(np->parent);

Both the Ti and Xilinx drivers are using of_platform_populate(), so their r->dev.parent should have a parent reference to the cluster device.

Quoted 6 lines

So you are proposing to get the cluster's driver using something like r->dev.parent->parent->driver?

I will have to verify the parent/child relationship is set up properly through the of_platform_populate(). If it is, following the pointer trail is an equally valid approach and I will respin this set.

Hi Mathieu,

I addressed Bjorn's comments and verified on ZynqMP hardware that it's working.

Let me know if you would like to see v4 with suggested changes.

Thanks,

Tanmay

Quoted 22 lines
Quoted 22 lines

Unless I'm reading the code wrong, I think we should follow that pointer, rather than taking the detour in the DeviceTree data.

Regards,
Bjorn

Quoted 16 lines
drivers/remoteproc/remoteproc_core.c +10 -1
+                             if (!cluster_pdev) {
+                                     dev_err(&r->dev, "can't get parent\n");
+                                     break;
+                             }
+
+                             driver = cluster_pdev->dev.driver;
+                             put_device(&cluster_pdev->dev);
+                     }
+
+                     if (!try_module_get(driver->owner)) {
                              dev_err(&r->dev, "can't get owner\n");
                              break;
                      }
--

2.25.1

maintainer
#5 lore raw

Re: [RESEND PATCH v3 1/2] remoteproc: Make rproc_get_by_phandle() work for clusters

Quoted 100 lines · Tanmay Shah
Quoted 90 lines · Mathieu Poirier
Quoted 79 lines · Bjorn Andersson
Quoted 77 lines · Tanmay Shah

From: Mathieu Poirier <[email protected]>

Multi-cluster remoteproc designs typically have the following DT declaration:

      remoteproc_cluster {
              compatible = "soc,remoteproc-cluster";

                core0: core0 {
                      compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                };

                core1: core1 {
                      compatible = "soc,remoteproc-core"
                        memory-region;
                        sram;
                }
        };

A driver exists for the cluster rather than the individual cores themselves so that operation mode and HW specific configurations applicable to the cluster can be made.

Because the driver exists at the cluster level and not the individual core level, function rproc_get_by_phandle() fails to return the remoteproc associated with the phandled it is called for.

This patch enhances rproc_get_by_phandle() by looking for the cluster's driver when the driver for the immediate remoteproc's parent is not found.

---
 drivers/remoteproc/remoteproc_core.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +13 -1
index 695cce218e8c..3a8191803885 100644
@@ -33,6 +33,7 @@
 #include <linux/idr.h>
 #include <linux/elf.h>
 #include <linux/crc32.h>
+#include <linux/of_platform.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/virtio_ids.h>
 #include <linux/virtio_ring.h>
@@ -2111,7 +2112,9 @@ EXPORT_SYMBOL(rproc_detach);
 #ifdef CONFIG_OF
 struct rproc *rproc_get_by_phandle(phandle phandle)
 {
+     struct platform_device *cluster_pdev;
      struct rproc *rproc = NULL, *r;
+     struct device_driver *driver;
      struct device_node *np;
 
      np = of_find_node_by_phandle(phandle);
@@ -2122,7 +2125,30 @@ struct rproc *rproc_get_by_phandle(phandle phandle)
      list_for_each_entry_rcu(r, &rproc_list, node) {
              if (r->dev.parent && device_match_of_node(r->dev.parent, np)) {
                      /* prevent underlying implementation from being removed */
-                     if (!try_module_get(r->dev.parent->driver->owner)) {
+
+                     /*
+                      * If the remoteproc's parent has a driver, the
+                      * remoteproc is not part of a cluster and we can use
+                      * that driver.
+                      */
+                     driver = r->dev.parent->driver;
+
+                     /*
+                      * If the remoteproc's parent does not have a driver,
Quoted 9 lines

drivers/remoteproc/remoteproc_core.c struct rproc *rproc_get_by_phandle(phandle phandle) · line 2141

Quoted 4 lines
drivers/remoteproc/remoteproc_core.c +4 -0
+                      * look for the driver associated with the cluster.
+                      */
+                     if (!driver) {
+                             cluster_pdev = of_find_device_by_node(np->parent);

Both the Ti and Xilinx drivers are using of_platform_populate(), so their r->dev.parent should have a parent reference to the cluster device.

Quoted 6 lines

So you are proposing to get the cluster's driver using something like r->dev.parent->parent->driver?

I will have to verify the parent/child relationship is set up properly through the of_platform_populate(). If it is, following the pointer trail is an equally valid approach and I will respin this set.

Quoted 6 lines

Hi Mathieu,

I addressed Bjorn's comments and verified on ZynqMP hardware that it's working.

Let me know if you would like to see v4 with suggested changes.

Yes, please send a V4 with the proposed changes.

Quoted 27 lines

Thanks,

Tanmay

Quoted 22 lines
Quoted 22 lines

Unless I'm reading the code wrong, I think we should follow that pointer, rather than taking the detour in the DeviceTree data.

Regards,
Bjorn

Quoted 16 lines
drivers/remoteproc/remoteproc_core.c +10 -1
+                             if (!cluster_pdev) {
+                                     dev_err(&r->dev, "can't get parent\n");
+                                     break;
+                             }
+
+                             driver = cluster_pdev->dev.driver;
+                             put_device(&cluster_pdev->dev);
+                     }
+
+                     if (!try_module_get(driver->owner)) {
                              dev_err(&r->dev, "can't get owner\n");
                              break;
                      }
--

2.25.1

#6 lore raw

PATCH RESEND v3 2/2 remoteproc: enhance rproc_put() for clusters

In reply to Tanmay Shah

This patch enhances rproc_put() to support remoteproc clusters with multiple child nodes as in rproc_get_by_phandle().

---
 drivers/remoteproc/remoteproc_core.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +16 -1
index 3a8191803885..3d95543971b5 100644
@@ -2559,7 +2559,22 @@ EXPORT_SYMBOL(rproc_free);
  */
 void rproc_put(struct rproc *rproc)
 {
-	module_put(rproc->dev.parent->driver->owner);
+	struct platform_device *cluster_pdev;
+
+	if (rproc->dev.parent->driver) {
+		module_put(rproc->dev.parent->driver->owner);
+	} else {
+		/*
+		 * If the remoteproc's parent does not have a driver,
+		 * driver is associated with the cluster.
+		 */
+		cluster_pdev = of_find_device_by_node(rproc->dev.parent->of_node->parent);
+		if (cluster_pdev) {
+			module_put(cluster_pdev->dev.driver->owner);
+			put_device(&cluster_pdev->dev);
+		}
+	}
+
 	put_device(&rproc->dev);
 }
 EXPORT_SYMBOL(rproc_put);
Signature · 1 line
2.25.1