All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] remoteproc: xlnx: add shutdown callback
@ 2025-06-20 19:57 Tanmay Shah
  2025-07-02 14:25 ` Mathieu Poirier
  0 siblings, 1 reply; 2+ messages in thread
From: Tanmay Shah @ 2025-06-20 19:57 UTC (permalink / raw)
  To: andersson, mathieu.poirier; +Cc: linux-remoteproc, linux-kernel, 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.

Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
---
 drivers/remoteproc/xlnx_r5_remoteproc.c | 40 +++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/remoteproc/xlnx_r5_remoteproc.c b/drivers/remoteproc/xlnx_r5_remoteproc.c
index 1af89782e116..30294e7fbc79 100644
--- a/drivers/remoteproc/xlnx_r5_remoteproc.c
+++ b/drivers/remoteproc/xlnx_r5_remoteproc.c
@@ -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
-- 
2.34.1


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

* Re: [PATCH] remoteproc: xlnx: add shutdown callback
  2025-06-20 19:57 [PATCH] remoteproc: xlnx: add shutdown callback Tanmay Shah
@ 2025-07-02 14:25 ` Mathieu Poirier
  0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Poirier @ 2025-07-02 14:25 UTC (permalink / raw)
  To: Tanmay Shah; +Cc: andersson, linux-remoteproc, linux-kernel

On Fri, Jun 20, 2025 at 12:57:28PM -0700, Tanmay Shah wrote:
> 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>
> ---
>  drivers/remoteproc/xlnx_r5_remoteproc.c | 40 +++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
>

I have applied your patch.  

Thanks,
Mathieu
 
> diff --git a/drivers/remoteproc/xlnx_r5_remoteproc.c b/drivers/remoteproc/xlnx_r5_remoteproc.c
> index 1af89782e116..30294e7fbc79 100644
> --- a/drivers/remoteproc/xlnx_r5_remoteproc.c
> +++ b/drivers/remoteproc/xlnx_r5_remoteproc.c
> @@ -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
> -- 
> 2.34.1
> 

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

end of thread, other threads:[~2025-07-02 14:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 19:57 [PATCH] remoteproc: xlnx: add shutdown callback Tanmay Shah
2025-07-02 14:25 ` Mathieu Poirier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.