[PATCH v11 33/35] remoteproc: k3: Refactor mem_release() functions into common driver

Beleswar Padhi
2025-04-25T10:43:53Z

The mem_release() implementations in the TI K3 R5, DSP and M4 remoteproc
drivers release the reserved memory of the device, which get auto
triggered upon device removal.

Refactor these functions into ti_k3_common.c driver as k3_mem_release()
and use this common function in R5, DSP and M4 drivers.

Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
Tested-by: Judith Mendez <jm@ti.com>
---
v11: Changelog:
1. Carried T/B tag.

Link to v10:
https://lore.kernel.org/all/20250417182001.3903905-32-b-padhi@ti.com/

v10: Changelog:
1. Update commit message to call out changes in a better way.

Link to v9:
https://lore.kernel.org/all/20250317120622.1746415-25-b-padhi@ti.com/

drivers/remoteproc/ti_k3_common.c | 8 ++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 9 +--------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 9 +--------
drivers/remoteproc/ti_k3_r5_remoteproc.c | 9 +--------
5 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 3f39a828d26c0..c58e68e1764ea 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -457,5 +457,13 @@ int k3_rproc_of_get_memories(struct platform_device *pdev,
}
EXPORT_SYMBOL_GPL(k3_rproc_of_get_memories);

+void k3_mem_release(void *data)
+{
+ struct device *dev = data;
+
+ of_reserved_mem_device_release(dev);
+}
+EXPORT_SYMBOL_GPL(k3_mem_release);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("TI K3 common Remoteproc code");
diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h
index a811c4951e6b0..70656215c4d72 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -107,4 +107,5 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len,
bool *is_iomem);
int k3_rproc_of_get_memories(struct platform_device *pdev,
struct k3_rproc *kproc);
+void k3_mem_release(void *data);
#endif /* REMOTEPROC_TI_K3_COMMON_H */
diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
index 5ba82944a537f..6c79b347a610a 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -66,13 +66,6 @@ static const struct rproc_ops k3_dsp_rproc_ops = {
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
};

-static void k3_dsp_mem_release(void *data)
-{
- struct device *dev = data;
-
- of_reserved_mem_device_release(dev);
-}
-
static int k3_dsp_reserved_mem_init(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
@@ -102,7 +95,7 @@ static int k3_dsp_reserved_mem_init(struct k3_rproc *kproc)
ERR_PTR(ret));
return ret;
}
- ret = devm_add_action_or_reset(dev, k3_dsp_mem_release, dev);
+ ret = devm_add_action_or_reset(dev, k3_mem_release, dev);
if (ret)
return ret;

diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 771769e3dd66b..67b92cbf7c2bd 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,13 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"

-static void k3_m4_rproc_dev_mem_release(void *data)
-{
- struct device *dev = data;
-
- of_reserved_mem_device_release(dev);
-}
-
static int k3_m4_reserved_mem_init(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
@@ -56,7 +49,7 @@ static int k3_m4_reserved_mem_init(struct k3_rproc *kproc)
dev_err(dev, "device cannot initialize DMA pool (%d)\n", ret);
return ret;
}
- ret = devm_add_action_or_reset(dev, k3_m4_rproc_dev_mem_release, dev);
+ ret = devm_add_action_or_reset(dev, k3_mem_release, dev);
if (ret)
return ret;

diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c
index 94e9506a8e6e2..59bd610f2a8c7 100644
--- a/drivers/remoteproc/ti_k3_r5_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c
@@ -761,13 +761,6 @@ static int k3_r5_rproc_configure(struct k3_rproc *kproc)
return ret;
}

-static void k3_r5_mem_release(void *data)
-{
- struct device *dev = data;
-
- of_reserved_mem_device_release(dev);
-}
-
static int k3_r5_reserved_mem_init(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
@@ -798,7 +791,7 @@ static int k3_r5_reserved_mem_init(struct k3_rproc *kproc)
return ret;
}

- ret = devm_add_action_or_reset(dev, k3_r5_mem_release, dev);
+ ret = devm_add_action_or_reset(dev, k3_mem_release, dev);
if (ret)
return ret;

--
2.34.1