]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
remoteproc: xlnx: Add shutdown callback
authorTanmay Shah <tanmay.shah@amd.com>
Fri, 20 Jun 2025 19:57:28 +0000 (12:57 -0700)
committerMathieu Poirier <mathieu.poirier@linaro.org>
Thu, 3 Jul 2025 16:34:19 +0000 (10:34 -0600)
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.

Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
Link: https://lore.kernel.org/r/20250620195728.3216935-1-tanmay.shah@amd.com
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
drivers/remoteproc/xlnx_r5_remoteproc.c

index 5aa3fd1b0530114726b5f71f24eba143b8eee478..a51523456c6ed74d81c0381e27d328c16bae20c5 100644 (file)
@@ -1467,6 +1467,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
@@ -1528,6 +1567,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);