Skip to contentSkip to conversation

remoteproc: xlnx: add shutdown callback

PATCH In review Tanmay Shah 2 participants 2 messages Jun 20, 2025 – Jul 2, 2025 Remote processor (remoteproc)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remoteproc: xlnx: add shutdown callback

In case of kexec call, each driver's shutdown callback is called. Handle this call for rproc driver and shutdown/detach each core that was powered on before. This is needed for proper Life Cycle Management of remote processor. Otherwise on next linux boot, remote processor can't be started due to bad refcount of power-domain managed by platform management controller.

---
 drivers/remoteproc/xlnx_r5_remoteproc.c | 40 +++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/remoteproc/xlnx_r5_remoteproc.c +40 -0
index 1af89782e116..30294e7fbc79 100644
@@ -1463,6 +1463,45 @@ static void zynqmp_r5_cluster_exit(void *data)
 	platform_set_drvdata(pdev, NULL);
 }
 
+/*
+ * zynqmp_r5_remoteproc_shutdown()
+ * Follow shutdown sequence in case of kexec call.
+ *
+ * @pdev: domain platform device for cluster
+ *
+ * Return: None.
+ */
+static void zynqmp_r5_remoteproc_shutdown(struct platform_device *pdev)
+{
+	const char *rproc_state_str = NULL;
+	struct zynqmp_r5_cluster *cluster;
+	struct zynqmp_r5_core *r5_core;
+	struct rproc *rproc;
+	int i, ret = 0;
+
+	cluster = platform_get_drvdata(pdev);
+
+	for (i = 0; i < cluster->core_count; i++) {
+		r5_core = cluster->r5_cores[i];
+		rproc = r5_core->rproc;
+
+		if (rproc->state == RPROC_RUNNING) {
+			ret = rproc_shutdown(rproc);
+			rproc_state_str = "shutdown";
+		} else if (rproc->state == RPROC_ATTACHED) {
+			ret = rproc_detach(rproc);
+			rproc_state_str = "detach";
+		} else {
+			ret = 0;
+		}
+
+		if (ret) {
+			dev_err(cluster->dev, "failed to %s rproc %d\n",
+				rproc_state_str, rproc->index);
+		}
+	}
+}
+
 /*
  * zynqmp_r5_remoteproc_probe()
  * parse device-tree, initialize hardware and allocate required resources
@@ -1524,6 +1563,7 @@ static struct platform_driver zynqmp_r5_remoteproc_driver = {
 		.name = "zynqmp_r5_remoteproc",
 		.of_match_table = zynqmp_r5_remoteproc_match,
 	},
+	.shutdown = zynqmp_r5_remoteproc_shutdown,
 };
 module_platform_driver(zynqmp_r5_remoteproc_driver);
 

base-commit: d293da1e4dbebb40560e4c6a417b29ce3393659a

Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 7 lines · Tanmay Shah

In case of kexec call, each driver's shutdown callback is called. Handle this call for rproc driver and shutdown/detach each core that was powered on before. This is needed for proper Life Cycle Management of remote processor. Otherwise on next linux boot, remote processor can't be started due to bad refcount of power-domain managed by platform management controller.

Quoted 5 lines
---
 drivers/remoteproc/xlnx_r5_remoteproc.c | 40 +++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

I have applied your patch.

Thanks,
Mathieu

Quoted 63 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +40 -0
index 1af89782e116..30294e7fbc79 100644
@@ -1463,6 +1463,45 @@ static void zynqmp_r5_cluster_exit(void *data)
 	platform_set_drvdata(pdev, NULL);
 }
 
+/*
+ * zynqmp_r5_remoteproc_shutdown()
+ * Follow shutdown sequence in case of kexec call.
+ *
+ * @pdev: domain platform device for cluster
+ *
+ * Return: None.
+ */
+static void zynqmp_r5_remoteproc_shutdown(struct platform_device *pdev)
+{
+	const char *rproc_state_str = NULL;
+	struct zynqmp_r5_cluster *cluster;
+	struct zynqmp_r5_core *r5_core;
+	struct rproc *rproc;
+	int i, ret = 0;
+
+	cluster = platform_get_drvdata(pdev);
+
+	for (i = 0; i < cluster->core_count; i++) {
+		r5_core = cluster->r5_cores[i];
+		rproc = r5_core->rproc;
+
+		if (rproc->state == RPROC_RUNNING) {
+			ret = rproc_shutdown(rproc);
+			rproc_state_str = "shutdown";
+		} else if (rproc->state == RPROC_ATTACHED) {
+			ret = rproc_detach(rproc);
+			rproc_state_str = "detach";
+		} else {
+			ret = 0;
+		}
+
+		if (ret) {
+			dev_err(cluster->dev, "failed to %s rproc %d\n",
+				rproc_state_str, rproc->index);
+		}
+	}
+}
+
 /*
  * zynqmp_r5_remoteproc_probe()
  * parse device-tree, initialize hardware and allocate required resources
@@ -1524,6 +1563,7 @@ static struct platform_driver zynqmp_r5_remoteproc_driver = {
 		.name = "zynqmp_r5_remoteproc",
 		.of_match_table = zynqmp_r5_remoteproc_match,
 	},
+	.shutdown = zynqmp_r5_remoteproc_shutdown,
 };
 module_platform_driver(zynqmp_r5_remoteproc_driver);
 

base-commit: d293da1e4dbebb40560e4c6a417b29ce3393659a

Signature · 1 line
2.34.1