* [PATCH v8 01/20] remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-08 8:49 ` Beleswar Prasad Padhi
2025-01-03 10:12 ` [PATCH v8 02/20] remoteproc: k3: Refactor shared data structures Beleswar Padhi
` (20 subsequent siblings)
21 siblings, 1 reply; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
Inter-Processor Communication is facilitated through mailbox payloads,
which typically contains the index of the triggered virtqueue having the
actual data to be consumed, but the payload can also be used for trivial
communication, like sending an echo message or notifying a crash etc.
When the core is detached, the virtqueues are freed, and thus the Virtio
level IPC is not functional. However, Mailbox IPC is still possible with
trivial payloads.
Therefore, introduce checks in k3_m4_rproc_kick() and
k3_m4_rproc_mbox_callback() functions to return early without parsing
the payload when core is detached, and is not undergoing an attach
operation in IPC-only mode.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_m4_remoteproc.c | 41 ++++++++++++++++++++----
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index a16fb165fced..3201c3684a86 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -50,6 +50,7 @@ struct k3_m4_rproc_mem_data {
/**
* struct k3_m4_rproc - k3 remote processor driver structure
* @dev: cached device pointer
+ * @rproc: remoteproc device handle
* @mem: internal memory regions data
* @num_mems: number of internal memory regions
* @rmem: reserved memory regions data
@@ -60,9 +61,11 @@ struct k3_m4_rproc_mem_data {
* @ti_sci_id: TI-SCI device identifier
* @mbox: mailbox channel handle
* @client: mailbox client to request the mailbox channel
+ * @is_attach_ongoing: flag to indicate if IPC-only "attach()" is in progress
*/
struct k3_m4_rproc {
struct device *dev;
+ struct rproc *rproc;
struct k3_m4_rproc_mem *mem;
int num_mems;
struct k3_m4_rproc_mem *rmem;
@@ -73,6 +76,7 @@ struct k3_m4_rproc {
u32 ti_sci_id;
struct mbox_chan *mbox;
struct mbox_client client;
+ bool is_attach_ongoing;
};
/**
@@ -93,8 +97,16 @@ static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data)
{
struct device *dev = client->dev;
struct rproc *rproc = dev_get_drvdata(dev);
+ struct k3_m4_rproc *kproc = rproc->priv;
u32 msg = (u32)(uintptr_t)(data);
+ /*
+ * Do not forward messages from a detached core, except when the core
+ * is in the process of being attached in IPC-only mode.
+ */
+ if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
+ return;
+
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
switch (msg) {
@@ -135,6 +147,12 @@ static void k3_m4_rproc_kick(struct rproc *rproc, int vqid)
u32 msg = (u32)vqid;
int ret;
+ /*
+ * Do not forward messages to a detached core, except when the core
+ * is in the process of being attached in IPC-only mode.
+ */
+ if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
+ return;
/*
* Send the index of the triggered virtqueue in the mailbox payload.
* NOTE: msg is cast to uintptr_t to prevent compiler warnings when
@@ -515,15 +533,19 @@ static int k3_m4_rproc_stop(struct rproc *rproc)
/*
* Attach to a running M4 remote processor (IPC-only mode)
*
- * The remote processor is already booted, so there is no need to issue any
- * TI-SCI commands to boot the M4 core. This callback is used only in IPC-only
- * mode.
+ * This rproc attach callback only needs to set the "is_attach_ongoing" flag to
+ * notify k3_m4_rproc_{kick/mbox_callback} functions that the core is in the
+ * process of getting attached in IPC-only mode. The remote processor is already
+ * booted, so there is no need to issue any TI-SCI commands to boot the M4 core.
+ * This callback is used only in IPC-only mode.
*/
static int k3_m4_rproc_attach(struct rproc *rproc)
{
struct k3_m4_rproc *kproc = rproc->priv;
int ret;
+ kproc->is_attach_ongoing = true;
+
ret = k3_m4_rproc_ping_mbox(kproc);
if (ret)
return ret;
@@ -534,12 +556,18 @@ static int k3_m4_rproc_attach(struct rproc *rproc)
/*
* Detach from a running M4 remote processor (IPC-only mode)
*
- * This rproc detach callback performs the opposite operation to attach
- * callback, the M4 core is not stopped and will be left to continue to
- * run its booted firmware. This callback is invoked only in IPC-only mode.
+ * This rproc detach callback performs the opposite operation to attach callback
+ * and only needs to clear the "is_attach_ongoing" flag to ensure no mailbox
+ * messages are sent to or received from a detached core. The M4 core is not
+ * stopped and will be left to continue to run its booted firmware. This
+ * callback is invoked only in IPC-only mode.
*/
static int k3_m4_rproc_detach(struct rproc *rproc)
{
+ struct k3_m4_rproc *kproc = rproc->priv;
+
+ kproc->is_attach_ongoing = false;
+
return 0;
}
@@ -577,6 +605,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
rproc->has_iommu = false;
rproc->recovery_disabled = true;
kproc = rproc->priv;
+ kproc->rproc = rproc;
kproc->dev = dev;
platform_set_drvdata(pdev, rproc);
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH v8 01/20] remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
2025-01-03 10:12 ` [PATCH v8 01/20] remoteproc: k3-m4: Prevent Mailbox level IPC with detached core Beleswar Padhi
@ 2025-01-08 8:49 ` Beleswar Prasad Padhi
0 siblings, 0 replies; 25+ messages in thread
From: Beleswar Prasad Padhi @ 2025-01-08 8:49 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, linux-remoteproc, linux-kernel
On 03/01/25 15:42, Beleswar Padhi wrote:
> Inter-Processor Communication is facilitated through mailbox payloads,
> which typically contains the index of the triggered virtqueue having the
> actual data to be consumed, but the payload can also be used for trivial
> communication, like sending an echo message or notifying a crash etc.
> When the core is detached, the virtqueues are freed, and thus the Virtio
> level IPC is not functional. However, Mailbox IPC is still possible with
> trivial payloads.
>
> Therefore, introduce checks in k3_m4_rproc_kick() and
> k3_m4_rproc_mbox_callback() functions to return early without parsing
> the payload when core is detached, and is not undergoing an attach
> operation in IPC-only mode.
>
> Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
> ---
> drivers/remoteproc/ti_k3_m4_remoteproc.c | 41 ++++++++++++++++++++----
> 1 file changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
> index a16fb165fced..3201c3684a86 100644
> --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
> +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
> @@ -50,6 +50,7 @@ struct k3_m4_rproc_mem_data {
> /**
> * struct k3_m4_rproc - k3 remote processor driver structure
> * @dev: cached device pointer
> + * @rproc: remoteproc device handle
> * @mem: internal memory regions data
> * @num_mems: number of internal memory regions
> * @rmem: reserved memory regions data
> @@ -60,9 +61,11 @@ struct k3_m4_rproc_mem_data {
> * @ti_sci_id: TI-SCI device identifier
> * @mbox: mailbox channel handle
> * @client: mailbox client to request the mailbox channel
> + * @is_attach_ongoing: flag to indicate if IPC-only "attach()" is in progress
Note: This variable naming will be changed to 'is_attached' (for better
clarity) in the next revision. I wish to take more feedback for the
whole series before posting next revision.
Thanks,
Beleswar
> */
> struct k3_m4_rproc {
> struct device *dev;
> + struct rproc *rproc;
> struct k3_m4_rproc_mem *mem;
> int num_mems;
> struct k3_m4_rproc_mem *rmem;
> @@ -73,6 +76,7 @@ struct k3_m4_rproc {
> u32 ti_sci_id;
> struct mbox_chan *mbox;
> struct mbox_client client;
> + bool is_attach_ongoing;
> };
>
> /**
> @@ -93,8 +97,16 @@ static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data)
> {
> struct device *dev = client->dev;
> struct rproc *rproc = dev_get_drvdata(dev);
> + struct k3_m4_rproc *kproc = rproc->priv;
> u32 msg = (u32)(uintptr_t)(data);
>
> + /*
> + * Do not forward messages from a detached core, except when the core
> + * is in the process of being attached in IPC-only mode.
> + */
> + if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
> + return;
> +
> dev_dbg(dev, "mbox msg: 0x%x\n", msg);
>
> switch (msg) {
> @@ -135,6 +147,12 @@ static void k3_m4_rproc_kick(struct rproc *rproc, int vqid)
> u32 msg = (u32)vqid;
> int ret;
>
> + /*
> + * Do not forward messages to a detached core, except when the core
> + * is in the process of being attached in IPC-only mode.
> + */
> + if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
> + return;
> /*
> * Send the index of the triggered virtqueue in the mailbox payload.
> * NOTE: msg is cast to uintptr_t to prevent compiler warnings when
> @@ -515,15 +533,19 @@ static int k3_m4_rproc_stop(struct rproc *rproc)
> /*
> * Attach to a running M4 remote processor (IPC-only mode)
> *
> - * The remote processor is already booted, so there is no need to issue any
> - * TI-SCI commands to boot the M4 core. This callback is used only in IPC-only
> - * mode.
> + * This rproc attach callback only needs to set the "is_attach_ongoing" flag to
> + * notify k3_m4_rproc_{kick/mbox_callback} functions that the core is in the
> + * process of getting attached in IPC-only mode. The remote processor is already
> + * booted, so there is no need to issue any TI-SCI commands to boot the M4 core.
> + * This callback is used only in IPC-only mode.
> */
> static int k3_m4_rproc_attach(struct rproc *rproc)
> {
> struct k3_m4_rproc *kproc = rproc->priv;
> int ret;
>
> + kproc->is_attach_ongoing = true;
> +
> ret = k3_m4_rproc_ping_mbox(kproc);
> if (ret)
> return ret;
> @@ -534,12 +556,18 @@ static int k3_m4_rproc_attach(struct rproc *rproc)
> /*
> * Detach from a running M4 remote processor (IPC-only mode)
> *
> - * This rproc detach callback performs the opposite operation to attach
> - * callback, the M4 core is not stopped and will be left to continue to
> - * run its booted firmware. This callback is invoked only in IPC-only mode.
> + * This rproc detach callback performs the opposite operation to attach callback
> + * and only needs to clear the "is_attach_ongoing" flag to ensure no mailbox
> + * messages are sent to or received from a detached core. The M4 core is not
> + * stopped and will be left to continue to run its booted firmware. This
> + * callback is invoked only in IPC-only mode.
> */
> static int k3_m4_rproc_detach(struct rproc *rproc)
> {
> + struct k3_m4_rproc *kproc = rproc->priv;
> +
> + kproc->is_attach_ongoing = false;
> +
> return 0;
> }
>
> @@ -577,6 +605,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
> rproc->has_iommu = false;
> rproc->recovery_disabled = true;
> kproc = rproc->priv;
> + kproc->rproc = rproc;
> kproc->dev = dev;
> platform_set_drvdata(pdev, rproc);
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v8 02/20] remoteproc: k3: Refactor shared data structures
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 01/20] remoteproc: k3-m4: Prevent Mailbox level IPC with detached core Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 03/20] remoteproc: k3: Refactor mailbox rx_callback functions into common driver Beleswar Padhi
` (19 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c drivers share the
same data structure definitions. Refactor the shared data structures
into a new common header file, 'ti_k3_common.h', and update both drivers
to use the unified data structures.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.h | 91 ++++++++++++++++
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 124 +++++-----------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 85 +++------------
3 files changed, 132 insertions(+), 168 deletions(-)
create mode 100644 drivers/remoteproc/ti_k3_common.h
diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h
new file mode 100644
index 000000000000..9d7ce70bcbf5
--- /dev/null
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * TI K3 Remote Processor(s) driver common code
+ *
+ * Refactored out of ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c.
+ *
+ * ti_k3_dsp_remoteproc.c:
+ * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
+ * Suman Anna <s-anna@ti.com>
+ *
+ * ti_k3_m4_remoteproc.c:
+ * Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/
+ * Hari Nagalla <hnagalla@ti.com>
+ */
+
+#ifndef REMOTEPROC_TI_K3_COMMON_H
+#define REMOTEPROC_TI_K3_COMMON_H
+
+/**
+ * struct k3_rproc_mem - internal memory structure
+ * @cpu_addr: MPU virtual address of the memory region
+ * @bus_addr: Bus address used to access the memory region
+ * @dev_addr: Device address of the memory region from remote processor view
+ * @size: Size of the memory region
+ */
+struct k3_rproc_mem {
+ void __iomem *cpu_addr;
+ phys_addr_t bus_addr;
+ u32 dev_addr;
+ size_t size;
+};
+
+/**
+ * struct k3_rproc_mem_data - memory definitions for a remote processor
+ * @name: name for this memory entry
+ * @dev_addr: device address for the memory entry
+ */
+struct k3_rproc_mem_data {
+ const char *name;
+ const u32 dev_addr;
+};
+
+/**
+ * struct k3_rproc_dev_data - device data structure for a remote processor
+ * @mems: pointer to memory definitions for a remote processor
+ * @num_mems: number of memory regions in @mems
+ * @boot_align_addr: boot vector address alignment granularity
+ * @uses_lreset: flag to denote the need for local reset management
+ */
+struct k3_rproc_dev_data {
+ const struct k3_rproc_mem_data *mems;
+ u32 num_mems;
+ u32 boot_align_addr;
+ bool uses_lreset;
+};
+
+/**
+ * struct k3_rproc - k3 remote processor driver structure
+ * @dev: cached device pointer
+ * @rproc: remoteproc device handle
+ * @mem: internal memory regions data
+ * @num_mems: number of internal memory regions
+ * @rmem: reserved memory regions data
+ * @num_rmems: number of reserved memory regions
+ * @reset: reset control handle
+ * @data: pointer to DSP-specific device data
+ * @tsp: TI-SCI processor control handle
+ * @ti_sci: TI-SCI handle
+ * @ti_sci_id: TI-SCI device identifier
+ * @mbox: mailbox channel handle
+ * @client: mailbox client to request the mailbox channel
+ * @is_attach_ongoing: flag to indicate if IPC-only "attach()" is in progress
+ */
+struct k3_rproc {
+ struct device *dev;
+ struct rproc *rproc;
+ struct k3_rproc_mem *mem;
+ int num_mems;
+ struct k3_rproc_mem *rmem;
+ int num_rmems;
+ struct reset_control *reset;
+ const struct k3_rproc_dev_data *data;
+ struct ti_sci_proc *tsp;
+ const struct ti_sci_handle *ti_sci;
+ u32 ti_sci_id;
+ struct mbox_chan *mbox;
+ struct mbox_client client;
+ bool is_attach_ongoing;
+};
+
+#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 f20fc2db077b..41b32af15260 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -20,81 +20,10 @@
#include "omap_remoteproc.h"
#include "remoteproc_internal.h"
#include "ti_sci_proc.h"
+#include "ti_k3_common.h"
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-/**
- * struct k3_dsp_mem - internal memory structure
- * @cpu_addr: MPU virtual address of the memory region
- * @bus_addr: Bus address used to access the memory region
- * @dev_addr: Device address of the memory region from DSP view
- * @size: Size of the memory region
- */
-struct k3_dsp_mem {
- void __iomem *cpu_addr;
- phys_addr_t bus_addr;
- u32 dev_addr;
- size_t size;
-};
-
-/**
- * struct k3_dsp_mem_data - memory definitions for a DSP
- * @name: name for this memory entry
- * @dev_addr: device address for the memory entry
- */
-struct k3_dsp_mem_data {
- const char *name;
- const u32 dev_addr;
-};
-
-/**
- * struct k3_dsp_dev_data - device data structure for a DSP
- * @mems: pointer to memory definitions for a DSP
- * @num_mems: number of memory regions in @mems
- * @boot_align_addr: boot vector address alignment granularity
- * @uses_lreset: flag to denote the need for local reset management
- */
-struct k3_dsp_dev_data {
- const struct k3_dsp_mem_data *mems;
- u32 num_mems;
- u32 boot_align_addr;
- bool uses_lreset;
-};
-
-/**
- * struct k3_dsp_rproc - k3 DSP remote processor driver structure
- * @dev: cached device pointer
- * @rproc: remoteproc device handle
- * @mem: internal memory regions data
- * @num_mems: number of internal memory regions
- * @rmem: reserved memory regions data
- * @num_rmems: number of reserved memory regions
- * @reset: reset control handle
- * @data: pointer to DSP-specific device data
- * @tsp: TI-SCI processor control handle
- * @ti_sci: TI-SCI handle
- * @ti_sci_id: TI-SCI device identifier
- * @mbox: mailbox channel handle
- * @client: mailbox client to request the mailbox channel
- * @is_attach_ongoing: flag to indicate if IPC-only "attach()" is in progress
- */
-struct k3_dsp_rproc {
- struct device *dev;
- struct rproc *rproc;
- struct k3_dsp_mem *mem;
- int num_mems;
- struct k3_dsp_mem *rmem;
- int num_rmems;
- struct reset_control *reset;
- const struct k3_dsp_dev_data *data;
- struct ti_sci_proc *tsp;
- const struct ti_sci_handle *ti_sci;
- u32 ti_sci_id;
- struct mbox_chan *mbox;
- struct mbox_client client;
- bool is_attach_ongoing;
-};
-
/**
* k3_dsp_rproc_mbox_callback() - inbound mailbox message handler
* @client: mailbox client pointer used for requesting the mailbox channel
@@ -111,8 +40,7 @@ struct k3_dsp_rproc {
*/
static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data)
{
- struct k3_dsp_rproc *kproc = container_of(client, struct k3_dsp_rproc,
- client);
+ struct k3_rproc *kproc = container_of(client, struct k3_rproc, client);
struct device *dev = kproc->rproc->dev.parent;
const char *name = kproc->rproc->name;
u32 msg = omap_mbox_message(data);
@@ -159,7 +87,7 @@ static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data)
*/
static void k3_dsp_rproc_kick(struct rproc *rproc, int vqid)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = rproc->dev.parent;
mbox_msg_t msg = (mbox_msg_t)vqid;
int ret;
@@ -179,7 +107,7 @@ static void k3_dsp_rproc_kick(struct rproc *rproc, int vqid)
}
/* Put the DSP processor into reset */
-static int k3_dsp_rproc_reset(struct k3_dsp_rproc *kproc)
+static int k3_dsp_rproc_reset(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
int ret;
@@ -205,7 +133,7 @@ static int k3_dsp_rproc_reset(struct k3_dsp_rproc *kproc)
}
/* Release the DSP processor from reset */
-static int k3_dsp_rproc_release(struct k3_dsp_rproc *kproc)
+static int k3_dsp_rproc_release(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
int ret;
@@ -234,7 +162,7 @@ static int k3_dsp_rproc_release(struct k3_dsp_rproc *kproc)
static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct mbox_client *client = &kproc->client;
struct device *dev = kproc->dev;
int ret;
@@ -278,7 +206,7 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
*/
static int k3_dsp_rproc_prepare(struct rproc *rproc)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
@@ -302,7 +230,7 @@ static int k3_dsp_rproc_prepare(struct rproc *rproc)
*/
static int k3_dsp_rproc_unprepare(struct rproc *rproc)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
@@ -323,7 +251,7 @@ static int k3_dsp_rproc_unprepare(struct rproc *rproc)
*/
static int k3_dsp_rproc_start(struct rproc *rproc)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
u32 boot_addr;
int ret;
@@ -355,7 +283,7 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
*/
static int k3_dsp_rproc_stop(struct rproc *rproc)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
k3_dsp_rproc_reset(kproc);
@@ -374,7 +302,7 @@ static int k3_dsp_rproc_stop(struct rproc *rproc)
*/
static int k3_dsp_rproc_attach(struct rproc *rproc)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
kproc->is_attach_ongoing = true;
@@ -392,7 +320,7 @@ static int k3_dsp_rproc_attach(struct rproc *rproc)
*/
static int k3_dsp_rproc_detach(struct rproc *rproc)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
kproc->is_attach_ongoing = false;
@@ -412,7 +340,7 @@ static int k3_dsp_rproc_detach(struct rproc *rproc)
static struct resource_table *k3_dsp_get_loaded_rsc_table(struct rproc *rproc,
size_t *rsc_table_sz)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
if (!kproc->rmem[0].cpu_addr) {
@@ -441,7 +369,7 @@ static struct resource_table *k3_dsp_get_loaded_rsc_table(struct rproc *rproc,
*/
static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
{
- struct k3_dsp_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
void __iomem *va = NULL;
phys_addr_t bus_addr;
u32 dev_addr, offset;
@@ -498,9 +426,9 @@ static const struct rproc_ops k3_dsp_rproc_ops = {
};
static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev,
- struct k3_dsp_rproc *kproc)
+ struct k3_rproc *kproc)
{
- const struct k3_dsp_dev_data *data = kproc->data;
+ const struct k3_rproc_dev_data *data = kproc->data;
struct device *dev = &pdev->dev;
struct resource *res;
int num_mems = 0;
@@ -556,7 +484,7 @@ static void k3_dsp_mem_release(void *data)
of_reserved_mem_device_release(dev);
}
-static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc)
+static int k3_dsp_reserved_mem_init(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
struct device_node *np = dev->of_node;
@@ -637,8 +565,8 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
- const struct k3_dsp_dev_data *data;
- struct k3_dsp_rproc *kproc;
+ const struct k3_rproc_dev_data *data;
+ struct k3_rproc *kproc;
struct rproc *rproc;
const char *fw_name;
bool p_state = false;
@@ -754,7 +682,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
static void k3_dsp_rproc_remove(struct platform_device *pdev)
{
- struct k3_dsp_rproc *kproc = platform_get_drvdata(pdev);
+ struct k3_rproc *kproc = platform_get_drvdata(pdev);
struct rproc *rproc = kproc->rproc;
struct device *dev = &pdev->dev;
int ret;
@@ -768,37 +696,37 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev)
mbox_free_channel(kproc->mbox);
}
-static const struct k3_dsp_mem_data c66_mems[] = {
+static const struct k3_rproc_mem_data c66_mems[] = {
{ .name = "l2sram", .dev_addr = 0x800000 },
{ .name = "l1pram", .dev_addr = 0xe00000 },
{ .name = "l1dram", .dev_addr = 0xf00000 },
};
/* C71x cores only have a L1P Cache, there are no L1P SRAMs */
-static const struct k3_dsp_mem_data c71_mems[] = {
+static const struct k3_rproc_mem_data c71_mems[] = {
{ .name = "l2sram", .dev_addr = 0x800000 },
{ .name = "l1dram", .dev_addr = 0xe00000 },
};
-static const struct k3_dsp_mem_data c7xv_mems[] = {
+static const struct k3_rproc_mem_data c7xv_mems[] = {
{ .name = "l2sram", .dev_addr = 0x800000 },
};
-static const struct k3_dsp_dev_data c66_data = {
+static const struct k3_rproc_dev_data c66_data = {
.mems = c66_mems,
.num_mems = ARRAY_SIZE(c66_mems),
.boot_align_addr = SZ_1K,
.uses_lreset = true,
};
-static const struct k3_dsp_dev_data c71_data = {
+static const struct k3_rproc_dev_data c71_data = {
.mems = c71_mems,
.num_mems = ARRAY_SIZE(c71_mems),
.boot_align_addr = SZ_2M,
.uses_lreset = false,
};
-static const struct k3_dsp_dev_data c7xv_data = {
+static const struct k3_rproc_dev_data c7xv_data = {
.mems = c7xv_mems,
.num_mems = ARRAY_SIZE(c7xv_mems),
.boot_align_addr = SZ_2M,
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 3201c3684a86..feca53978c62 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -19,66 +19,11 @@
#include "omap_remoteproc.h"
#include "remoteproc_internal.h"
#include "ti_sci_proc.h"
+#include "ti_k3_common.h"
#define K3_M4_IRAM_DEV_ADDR 0x00000
#define K3_M4_DRAM_DEV_ADDR 0x30000
-/**
- * struct k3_m4_rproc_mem - internal memory structure
- * @cpu_addr: MPU virtual address of the memory region
- * @bus_addr: Bus address used to access the memory region
- * @dev_addr: Device address of the memory region from remote processor view
- * @size: Size of the memory region
- */
-struct k3_m4_rproc_mem {
- void __iomem *cpu_addr;
- phys_addr_t bus_addr;
- u32 dev_addr;
- size_t size;
-};
-
-/**
- * struct k3_m4_rproc_mem_data - memory definitions for a remote processor
- * @name: name for this memory entry
- * @dev_addr: device address for the memory entry
- */
-struct k3_m4_rproc_mem_data {
- const char *name;
- const u32 dev_addr;
-};
-
-/**
- * struct k3_m4_rproc - k3 remote processor driver structure
- * @dev: cached device pointer
- * @rproc: remoteproc device handle
- * @mem: internal memory regions data
- * @num_mems: number of internal memory regions
- * @rmem: reserved memory regions data
- * @num_rmems: number of reserved memory regions
- * @reset: reset control handle
- * @tsp: TI-SCI processor control handle
- * @ti_sci: TI-SCI handle
- * @ti_sci_id: TI-SCI device identifier
- * @mbox: mailbox channel handle
- * @client: mailbox client to request the mailbox channel
- * @is_attach_ongoing: flag to indicate if IPC-only "attach()" is in progress
- */
-struct k3_m4_rproc {
- struct device *dev;
- struct rproc *rproc;
- struct k3_m4_rproc_mem *mem;
- int num_mems;
- struct k3_m4_rproc_mem *rmem;
- int num_rmems;
- struct reset_control *reset;
- struct ti_sci_proc *tsp;
- const struct ti_sci_handle *ti_sci;
- u32 ti_sci_id;
- struct mbox_chan *mbox;
- struct mbox_client client;
- bool is_attach_ongoing;
-};
-
/**
* k3_m4_rproc_mbox_callback() - inbound mailbox message handler
* @client: mailbox client pointer used for requesting the mailbox channel
@@ -97,7 +42,7 @@ static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data)
{
struct device *dev = client->dev;
struct rproc *rproc = dev_get_drvdata(dev);
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
u32 msg = (u32)(uintptr_t)(data);
/*
@@ -142,7 +87,7 @@ static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data)
*/
static void k3_m4_rproc_kick(struct rproc *rproc, int vqid)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
u32 msg = (u32)vqid;
int ret;
@@ -164,7 +109,7 @@ static void k3_m4_rproc_kick(struct rproc *rproc, int vqid)
ret);
}
-static int k3_m4_rproc_ping_mbox(struct k3_m4_rproc *kproc)
+static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
int ret;
@@ -196,7 +141,7 @@ static int k3_m4_rproc_ping_mbox(struct k3_m4_rproc *kproc)
*/
static int k3_m4_rproc_prepare(struct rproc *rproc)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
@@ -241,7 +186,7 @@ static int k3_m4_rproc_prepare(struct rproc *rproc)
*/
static int k3_m4_rproc_unprepare(struct rproc *rproc)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
@@ -272,7 +217,7 @@ static int k3_m4_rproc_unprepare(struct rproc *rproc)
static struct resource_table *k3_m4_get_loaded_rsc_table(struct rproc *rproc,
size_t *rsc_table_sz)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
if (!kproc->rmem[0].cpu_addr) {
@@ -302,7 +247,7 @@ static struct resource_table *k3_m4_get_loaded_rsc_table(struct rproc *rproc,
*/
static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
void __iomem *va = NULL;
phys_addr_t bus_addr;
u32 dev_addr, offset;
@@ -348,7 +293,7 @@ static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool
}
static int k3_m4_rproc_of_get_memories(struct platform_device *pdev,
- struct k3_m4_rproc *kproc)
+ struct k3_rproc *kproc)
{
static const char * const mem_names[] = { "iram", "dram" };
static const u32 mem_addrs[] = { K3_M4_IRAM_DEV_ADDR, K3_M4_DRAM_DEV_ADDR };
@@ -407,7 +352,7 @@ static void k3_m4_rproc_dev_mem_release(void *data)
of_reserved_mem_device_release(dev);
}
-static int k3_m4_reserved_mem_init(struct k3_m4_rproc *kproc)
+static int k3_m4_reserved_mem_init(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
struct device_node *np = dev->of_node;
@@ -492,7 +437,7 @@ static void k3_m4_release_tsp(void *data)
*/
static int k3_m4_rproc_start(struct rproc *rproc)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
@@ -517,7 +462,7 @@ static int k3_m4_rproc_start(struct rproc *rproc)
*/
static int k3_m4_rproc_stop(struct rproc *rproc)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
@@ -541,7 +486,7 @@ static int k3_m4_rproc_stop(struct rproc *rproc)
*/
static int k3_m4_rproc_attach(struct rproc *rproc)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
int ret;
kproc->is_attach_ongoing = true;
@@ -564,7 +509,7 @@ static int k3_m4_rproc_attach(struct rproc *rproc)
*/
static int k3_m4_rproc_detach(struct rproc *rproc)
{
- struct k3_m4_rproc *kproc = rproc->priv;
+ struct k3_rproc *kproc = rproc->priv;
kproc->is_attach_ongoing = false;
@@ -586,7 +531,7 @@ static const struct rproc_ops k3_m4_rproc_ops = {
static int k3_m4_rproc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct k3_m4_rproc *kproc;
+ struct k3_rproc *kproc;
struct rproc *rproc;
const char *fw_name;
bool r_state = false;
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 03/20] remoteproc: k3: Refactor mailbox rx_callback functions into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 01/20] remoteproc: k3-m4: Prevent Mailbox level IPC with detached core Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 02/20] remoteproc: k3: Refactor shared data structures Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 04/20] remoteproc: k3: Refactor .kick rproc ops " Beleswar Padhi
` (18 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The mailbox .rx_callback implementations in ti_k3_dsp_remoteproc.c and
ti_k3_m4_remoteproc.c drivers handle inbound mailbox messages in the
same way. Introduce a common driver 'ti_k3_common.c' and refactor the
implementations into a common function 'k3_rproc_mbox_callback'() in it.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/Makefile | 4 +-
drivers/remoteproc/ti_k3_common.c | 90 +++++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 57 +-------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 57 +-------------
5 files changed, 95 insertions(+), 114 deletions(-)
create mode 100644 drivers/remoteproc/ti_k3_common.c
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 5ff4e2fee4ab..e30908ca4bfc 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -36,7 +36,7 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o
obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o
obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o
obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o
-obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o
-obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o
+obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o
+obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o ti_k3_common.o
obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o
obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.o
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
new file mode 100644
index 000000000000..a87a06744f71
--- /dev/null
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * TI K3 Remote Processor(s) driver common code
+ *
+ * Refactored out of ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c.
+ *
+ * ti_k3_dsp_remoteproc.c:
+ * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
+ * Suman Anna <s-anna@ti.com>
+ *
+ * ti_k3_m4_remoteproc.c:
+ * Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/
+ * Hari Nagalla <hnagalla@ti.com>
+ */
+
+#include <linux/io.h>
+#include <linux/mailbox_client.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/omap-mailbox.h>
+#include <linux/platform_device.h>
+#include <linux/remoteproc.h>
+#include <linux/reset.h>
+#include <linux/slab.h>
+
+#include "omap_remoteproc.h"
+#include "remoteproc_internal.h"
+#include "ti_sci_proc.h"
+#include "ti_k3_common.h"
+
+/**
+ * k3_rproc_mbox_callback() - inbound mailbox message handler
+ * @client: mailbox client pointer used for requesting the mailbox channel
+ * @data: mailbox payload
+ *
+ * This handler is invoked by the K3 mailbox driver whenever a mailbox
+ * message is received. Usually, the mailbox payload simply contains
+ * the index of the virtqueue that is kicked by the remote processor,
+ * and we let remoteproc core handle it.
+ *
+ * In addition to virtqueue indices, we also have some out-of-band values
+ * that indicate different events. Those values are deliberately very
+ * large so they don't coincide with virtqueue indices.
+ */
+void k3_rproc_mbox_callback(struct mbox_client *client, void *data)
+{
+ struct k3_rproc *kproc = container_of(client, struct k3_rproc, client);
+ struct device *dev = kproc->rproc->dev.parent;
+ struct rproc *rproc = kproc->rproc;
+ u32 msg = (u32)(uintptr_t)(data);
+
+ /*
+ * Do not forward messages from a detached core, except when the core
+ * is in the process of being attached in IPC-only mode.
+ */
+ if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
+ return;
+
+ dev_dbg(dev, "mbox msg: 0x%x\n", msg);
+
+ switch (msg) {
+ case RP_MBOX_CRASH:
+ /*
+ * remoteproc detected an exception, but error recovery is not
+ * supported. So, just log this for now
+ */
+ dev_err(dev, "K3 rproc %s crashed\n", rproc->name);
+ break;
+ case RP_MBOX_ECHO_REPLY:
+ dev_info(dev, "received echo reply from %s\n", rproc->name);
+ break;
+ default:
+ /* silently handle all other valid messages */
+ if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
+ return;
+ if (msg > rproc->max_notifyid) {
+ dev_dbg(dev, "dropping unknown message 0x%x", msg);
+ return;
+ }
+ /* msg contains the index of the triggered vring */
+ if (rproc_vq_interrupt(rproc, msg) == IRQ_NONE)
+ dev_dbg(dev, "no message was found in vqid %d\n", msg);
+ }
+}
+EXPORT_SYMBOL_GPL(k3_rproc_mbox_callback);
+
+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 9d7ce70bcbf5..251ecc2df1dd 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -88,4 +88,5 @@ struct k3_rproc {
bool is_attach_ongoing;
};
+void k3_rproc_mbox_callback(struct mbox_client *client, 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 41b32af15260..70fbceccbac2 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,61 +24,6 @@
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-/**
- * k3_dsp_rproc_mbox_callback() - inbound mailbox message handler
- * @client: mailbox client pointer used for requesting the mailbox channel
- * @data: mailbox payload
- *
- * This handler is invoked by the OMAP mailbox driver whenever a mailbox
- * message is received. Usually, the mailbox payload simply contains
- * the index of the virtqueue that is kicked by the remote processor,
- * and we let remoteproc core handle it.
- *
- * In addition to virtqueue indices, we also have some out-of-band values
- * that indicate different events. Those values are deliberately very
- * large so they don't coincide with virtqueue indices.
- */
-static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data)
-{
- struct k3_rproc *kproc = container_of(client, struct k3_rproc, client);
- struct device *dev = kproc->rproc->dev.parent;
- const char *name = kproc->rproc->name;
- u32 msg = omap_mbox_message(data);
-
- /*
- * Do not forward messages from a detached core, except when the core
- * is in the process of being attached in IPC-only mode.
- */
- if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
- return;
-
- dev_dbg(dev, "mbox msg: 0x%x\n", msg);
-
- switch (msg) {
- case RP_MBOX_CRASH:
- /*
- * remoteproc detected an exception, but error recovery is not
- * supported. So, just log this for now
- */
- dev_err(dev, "K3 DSP rproc %s crashed\n", name);
- break;
- case RP_MBOX_ECHO_REPLY:
- dev_info(dev, "received echo reply from %s\n", name);
- break;
- default:
- /* silently handle all other valid messages */
- if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
- return;
- if (msg > kproc->rproc->max_notifyid) {
- dev_dbg(dev, "dropping unknown message 0x%x", msg);
- return;
- }
- /* msg contains the index of the triggered vring */
- if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE)
- dev_dbg(dev, "no message was found in vqid %d\n", msg);
- }
-}
-
/*
* Kick the remote processor to notify about pending unprocessed messages.
* The vqid usage is not used and is inconsequential, as the kick is performed
@@ -169,7 +114,7 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
client->dev = dev;
client->tx_done = NULL;
- client->rx_callback = k3_dsp_rproc_mbox_callback;
+ client->rx_callback = k3_rproc_mbox_callback;
client->tx_block = false;
client->knows_txdone = false;
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index feca53978c62..f1fe7d462d2a 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -24,61 +24,6 @@
#define K3_M4_IRAM_DEV_ADDR 0x00000
#define K3_M4_DRAM_DEV_ADDR 0x30000
-/**
- * k3_m4_rproc_mbox_callback() - inbound mailbox message handler
- * @client: mailbox client pointer used for requesting the mailbox channel
- * @data: mailbox payload
- *
- * This handler is invoked by the K3 mailbox driver whenever a mailbox
- * message is received. Usually, the mailbox payload simply contains
- * the index of the virtqueue that is kicked by the remote processor,
- * and we let remoteproc core handle it.
- *
- * In addition to virtqueue indices, we also have some out-of-band values
- * that indicate different events. Those values are deliberately very
- * large so they don't coincide with virtqueue indices.
- */
-static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data)
-{
- struct device *dev = client->dev;
- struct rproc *rproc = dev_get_drvdata(dev);
- struct k3_rproc *kproc = rproc->priv;
- u32 msg = (u32)(uintptr_t)(data);
-
- /*
- * Do not forward messages from a detached core, except when the core
- * is in the process of being attached in IPC-only mode.
- */
- if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
- return;
-
- dev_dbg(dev, "mbox msg: 0x%x\n", msg);
-
- switch (msg) {
- case RP_MBOX_CRASH:
- /*
- * remoteproc detected an exception, but error recovery is not
- * supported. So, just log this for now
- */
- dev_err(dev, "K3 rproc %s crashed\n", rproc->name);
- break;
- case RP_MBOX_ECHO_REPLY:
- dev_info(dev, "received echo reply from %s\n", rproc->name);
- break;
- default:
- /* silently handle all other valid messages */
- if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
- return;
- if (msg > rproc->max_notifyid) {
- dev_dbg(dev, "dropping unknown message 0x%x", msg);
- return;
- }
- /* msg contains the index of the triggered vring */
- if (rproc_vq_interrupt(rproc, msg) == IRQ_NONE)
- dev_dbg(dev, "no message was found in vqid %d\n", msg);
- }
-}
-
/*
* Kick the remote processor to notify about pending unprocessed messages.
* The vqid usage is not used and is inconsequential, as the kick is performed
@@ -603,7 +548,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
kproc->client.dev = dev;
kproc->client.tx_done = NULL;
- kproc->client.rx_callback = k3_m4_rproc_mbox_callback;
+ kproc->client.rx_callback = k3_rproc_mbox_callback;
kproc->client.tx_block = false;
kproc->client.knows_txdone = false;
kproc->mbox = mbox_request_channel(&kproc->client, 0);
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 04/20] remoteproc: k3: Refactor .kick rproc ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (2 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 03/20] remoteproc: k3: Refactor mailbox rx_callback functions into common driver Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 05/20] remoteproc: k3-m4: Use k3_rproc_mem_data structure for memory info Beleswar Padhi
` (17 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The .kick rproc ops implementations in ti_k3_dsp_remoteproc.c and
ti_k3_m4_remoteproc.c drivers sends a mailbox message to the remote
processor in the same way. Refactor the implementations into a common
function 'k3_rproc_kick()' in the ti_k3_common.c driver.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 31 +++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 31 ++-------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 34 ++---------------------
4 files changed, 36 insertions(+), 61 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index a87a06744f71..bd6353283078 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -86,5 +86,36 @@ void k3_rproc_mbox_callback(struct mbox_client *client, void *data)
}
EXPORT_SYMBOL_GPL(k3_rproc_mbox_callback);
+/*
+ * Kick the remote processor to notify about pending unprocessed messages.
+ * The vqid usage is not used and is inconsequential, as the kick is performed
+ * through a simulated GPIO (a bit in an IPC interrupt-triggering register),
+ * the remote processor is expected to process both its Tx and Rx virtqueues.
+ */
+void k3_rproc_kick(struct rproc *rproc, int vqid)
+{
+ struct k3_rproc *kproc = rproc->priv;
+ struct device *dev = kproc->dev;
+ u32 msg = (u32)vqid;
+ int ret;
+
+ /*
+ * Do not forward messages to a detached core, except when the core
+ * is in the process of being attached in IPC-only mode.
+ */
+ if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
+ return;
+ /*
+ * Send the index of the triggered virtqueue in the mailbox payload.
+ * NOTE: msg is cast to uintptr_t to prevent compiler warnings when
+ * void* is 64bit. It is safely cast back to u32 in the mailbox driver.
+ */
+ ret = mbox_send_message(kproc->mbox, (void *)(uintptr_t)msg);
+ if (ret < 0)
+ dev_err(dev, "failed to send mailbox message, status = %d\n",
+ ret);
+}
+EXPORT_SYMBOL_GPL(k3_rproc_kick);
+
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 251ecc2df1dd..57792d68b7ef 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -89,4 +89,5 @@ struct k3_rproc {
};
void k3_rproc_mbox_callback(struct mbox_client *client, void *data);
+void k3_rproc_kick(struct rproc *rproc, int vqid);
#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 70fbceccbac2..b2551b5171a9 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,33 +24,6 @@
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-/*
- * Kick the remote processor to notify about pending unprocessed messages.
- * The vqid usage is not used and is inconsequential, as the kick is performed
- * through a simulated GPIO (a bit in an IPC interrupt-triggering register),
- * the remote processor is expected to process both its Tx and Rx virtqueues.
- */
-static void k3_dsp_rproc_kick(struct rproc *rproc, int vqid)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = rproc->dev.parent;
- mbox_msg_t msg = (mbox_msg_t)vqid;
- int ret;
-
- /*
- * Do not forward messages to a detached core, except when the core is
- * in the process of being attached in IPC-only mode.
- */
- if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
- return;
-
- /* send the index of the triggered virtqueue in the mailbox payload */
- ret = mbox_send_message(kproc->mbox, (void *)msg);
- if (ret < 0)
- dev_err(dev, "failed to send mailbox message (%pe)\n",
- ERR_PTR(ret));
-}
-
/* Put the DSP processor into reset */
static int k3_dsp_rproc_reset(struct k3_rproc *kproc)
{
@@ -239,7 +212,7 @@ static int k3_dsp_rproc_stop(struct rproc *rproc)
* Attach to a running DSP remote processor (IPC-only mode)
*
* This rproc attach callback only needs to set the "is_attach_ongoing" flag to
- * notify k3_dsp_rproc_{kick/mbox_callback} functions that the core is in the
+ * notify k3_rproc_{kick/mbox_callback} functions that the core is in the
* process of getting attached in IPC-only mode. The remote processor is already
* booted, and all required resources have been acquired during probe routine,
* so there is no need to issue any TI-SCI commands to boot the DSP core. This
@@ -366,7 +339,7 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool
static const struct rproc_ops k3_dsp_rproc_ops = {
.start = k3_dsp_rproc_start,
.stop = k3_dsp_rproc_stop,
- .kick = k3_dsp_rproc_kick,
+ .kick = k3_rproc_kick,
.da_to_va = k3_dsp_rproc_da_to_va,
};
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index f1fe7d462d2a..953c3999019f 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -24,36 +24,6 @@
#define K3_M4_IRAM_DEV_ADDR 0x00000
#define K3_M4_DRAM_DEV_ADDR 0x30000
-/*
- * Kick the remote processor to notify about pending unprocessed messages.
- * The vqid usage is not used and is inconsequential, as the kick is performed
- * through a simulated GPIO (a bit in an IPC interrupt-triggering register),
- * the remote processor is expected to process both its Tx and Rx virtqueues.
- */
-static void k3_m4_rproc_kick(struct rproc *rproc, int vqid)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
- u32 msg = (u32)vqid;
- int ret;
-
- /*
- * Do not forward messages to a detached core, except when the core
- * is in the process of being attached in IPC-only mode.
- */
- if (!kproc->is_attach_ongoing && kproc->rproc->state == RPROC_DETACHED)
- return;
- /*
- * Send the index of the triggered virtqueue in the mailbox payload.
- * NOTE: msg is cast to uintptr_t to prevent compiler warnings when
- * void* is 64bit. It is safely cast back to u32 in the mailbox driver.
- */
- ret = mbox_send_message(kproc->mbox, (void *)(uintptr_t)msg);
- if (ret < 0)
- dev_err(dev, "failed to send mailbox message, status = %d\n",
- ret);
-}
-
static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
@@ -424,7 +394,7 @@ static int k3_m4_rproc_stop(struct rproc *rproc)
* Attach to a running M4 remote processor (IPC-only mode)
*
* This rproc attach callback only needs to set the "is_attach_ongoing" flag to
- * notify k3_m4_rproc_{kick/mbox_callback} functions that the core is in the
+ * notify k3_rproc_{kick/mbox_callback} functions that the core is in the
* process of getting attached in IPC-only mode. The remote processor is already
* booted, so there is no need to issue any TI-SCI commands to boot the M4 core.
* This callback is used only in IPC-only mode.
@@ -468,7 +438,7 @@ static const struct rproc_ops k3_m4_rproc_ops = {
.stop = k3_m4_rproc_stop,
.attach = k3_m4_rproc_attach,
.detach = k3_m4_rproc_detach,
- .kick = k3_m4_rproc_kick,
+ .kick = k3_rproc_kick,
.da_to_va = k3_m4_rproc_da_to_va,
.get_loaded_rsc_table = k3_m4_get_loaded_rsc_table,
};
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 05/20] remoteproc: k3-m4: Use k3_rproc_mem_data structure for memory info
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (3 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 04/20] remoteproc: k3: Refactor .kick rproc ops " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 06/20] remoteproc: k3: Refactor rproc_reset() implementation into common driver Beleswar Padhi
` (16 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The ti_k3_m4_remoteproc.c driver previously hardcoded device memory
region addresses and names. Change this to use the k3_rproc_mem_data
structure to store memory information. This aligns with
ti_k3_dsp_remoteproc.c driver, and can be refactored out later.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_m4_remoteproc.c | 40 ++++++++++++++++--------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 953c3999019f..fc688b124a54 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,9 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-#define K3_M4_IRAM_DEV_ADDR 0x00000
-#define K3_M4_DRAM_DEV_ADDR 0x30000
-
static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
@@ -210,14 +207,13 @@ static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool
static int k3_m4_rproc_of_get_memories(struct platform_device *pdev,
struct k3_rproc *kproc)
{
- static const char * const mem_names[] = { "iram", "dram" };
- static const u32 mem_addrs[] = { K3_M4_IRAM_DEV_ADDR, K3_M4_DRAM_DEV_ADDR };
+ const struct k3_rproc_dev_data *data = kproc->data;
struct device *dev = &pdev->dev;
struct resource *res;
int num_mems;
int i;
- num_mems = ARRAY_SIZE(mem_names);
+ num_mems = kproc->data->num_mems;
kproc->mem = devm_kcalloc(kproc->dev, num_mems,
sizeof(*kproc->mem), GFP_KERNEL);
if (!kproc->mem)
@@ -225,17 +221,17 @@ static int k3_m4_rproc_of_get_memories(struct platform_device *pdev,
for (i = 0; i < num_mems; i++) {
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
- mem_names[i]);
+ data->mems[i].name);
if (!res) {
dev_err(dev, "found no memory resource for %s\n",
- mem_names[i]);
+ data->mems[i].name);
return -EINVAL;
}
if (!devm_request_mem_region(dev, res->start,
resource_size(res),
dev_name(dev))) {
dev_err(dev, "could not request %s region for resource\n",
- mem_names[i]);
+ data->mems[i].name);
return -EBUSY;
}
@@ -243,15 +239,15 @@ static int k3_m4_rproc_of_get_memories(struct platform_device *pdev,
resource_size(res));
if (!kproc->mem[i].cpu_addr) {
dev_err(dev, "failed to map %s memory\n",
- mem_names[i]);
+ data->mems[i].name);
return -ENOMEM;
}
kproc->mem[i].bus_addr = res->start;
- kproc->mem[i].dev_addr = mem_addrs[i];
+ kproc->mem[i].dev_addr = data->mems[i].dev_addr;
kproc->mem[i].size = resource_size(res);
dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
- mem_names[i], &kproc->mem[i].bus_addr,
+ data->mems[i].name, &kproc->mem[i].bus_addr,
kproc->mem[i].size, kproc->mem[i].cpu_addr,
kproc->mem[i].dev_addr);
}
@@ -446,6 +442,7 @@ static const struct rproc_ops k3_m4_rproc_ops = {
static int k3_m4_rproc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
+ const struct k3_rproc_dev_data *data;
struct k3_rproc *kproc;
struct rproc *rproc;
const char *fw_name;
@@ -453,6 +450,10 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
bool p_state = false;
int ret;
+ data = of_device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
+
ret = rproc_of_parse_firmware(dev, 0, &fw_name);
if (ret)
return dev_err_probe(dev, ret, "failed to parse firmware-name property\n");
@@ -467,6 +468,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
kproc = rproc->priv;
kproc->rproc = rproc;
kproc->dev = dev;
+ kproc->data = data;
platform_set_drvdata(pdev, rproc);
kproc->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci");
@@ -534,8 +536,20 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
return 0;
}
+static const struct k3_rproc_mem_data am64_m4_mems[] = {
+ { .name = "iram", .dev_addr = 0x0 },
+ { .name = "dram", .dev_addr = 0x30000 },
+};
+
+static const struct k3_rproc_dev_data am64_m4_data = {
+ .mems = am64_m4_mems,
+ .num_mems = ARRAY_SIZE(am64_m4_mems),
+ .boot_align_addr = SZ_1K,
+ .uses_lreset = true,
+};
+
static const struct of_device_id k3_m4_of_match[] = {
- { .compatible = "ti,am64-m4fss", },
+ { .compatible = "ti,am64-m4fss", .data = &am64_m4_data, },
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, k3_m4_of_match);
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 06/20] remoteproc: k3: Refactor rproc_reset() implementation into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (4 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 05/20] remoteproc: k3-m4: Use k3_rproc_mem_data structure for memory info Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 07/20] remoteproc: k3: Refactor rproc_release() " Beleswar Padhi
` (15 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The k3_dsp_rproc_reset() function erroneously asserts the local reset
even for devices which do not support it. Even though it results in a
no-operation, Update the logic to explicitly assert the local reset for
devices that support it and only the global reset for those that do not.
Further, refactor the above function into the ti_k3_common.c driver as
k3_rproc_reset() and use it throughout DSP and M4 drivers for resetting
the remote processor.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 25 +++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 30 ++---------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 16 +++---------
4 files changed, 31 insertions(+), 41 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index bd6353283078..8f4cc52c1332 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -117,5 +117,30 @@ void k3_rproc_kick(struct rproc *rproc, int vqid)
}
EXPORT_SYMBOL_GPL(k3_rproc_kick);
+/* Put the remote processor into reset */
+int k3_rproc_reset(struct k3_rproc *kproc)
+{
+ struct device *dev = kproc->dev;
+ int ret;
+
+ if (kproc->data->uses_lreset) {
+ ret = reset_control_assert(kproc->reset);
+ if (ret)
+ dev_err(dev, "local-reset assert failed (%pe)\n", ERR_PTR(ret));
+ return ret;
+ }
+
+ ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
+ kproc->ti_sci_id);
+ if (ret) {
+ dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret));
+ if (reset_control_deassert(kproc->reset))
+ dev_warn(dev, "local-reset deassert back failed\n");
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_reset);
+
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 57792d68b7ef..52f784ada496 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -90,4 +90,5 @@ struct k3_rproc {
void k3_rproc_mbox_callback(struct mbox_client *client, void *data);
void k3_rproc_kick(struct rproc *rproc, int vqid);
+int k3_rproc_reset(struct k3_rproc *kproc);
#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 b2551b5171a9..045b1e81d06c 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,32 +24,6 @@
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-/* Put the DSP processor into reset */
-static int k3_dsp_rproc_reset(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- int ret;
-
- ret = reset_control_assert(kproc->reset);
- if (ret) {
- dev_err(dev, "local-reset assert failed (%pe)\n", ERR_PTR(ret));
- return ret;
- }
-
- if (kproc->data->uses_lreset)
- return ret;
-
- ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret) {
- dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret));
- if (reset_control_deassert(kproc->reset))
- dev_warn(dev, "local-reset deassert back failed\n");
- }
-
- return ret;
-}
-
/* Release the DSP processor from reset */
static int k3_dsp_rproc_release(struct k3_rproc *kproc)
{
@@ -203,7 +177,7 @@ static int k3_dsp_rproc_stop(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
- k3_dsp_rproc_reset(kproc);
+ k3_rproc_reset(kproc);
return 0;
}
@@ -584,7 +558,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret, "failed to get reset status\n");
} else if (ret == 0) {
dev_warn(dev, "local reset is deasserted for device\n");
- k3_dsp_rproc_reset(kproc);
+ k3_rproc_reset(kproc);
}
}
}
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index fc688b124a54..d31cf9babf1d 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -65,11 +65,9 @@ static int k3_m4_rproc_prepare(struct rproc *rproc)
* Ensure the local reset is asserted so the core doesn't
* execute bogus code when the module reset is released.
*/
- ret = reset_control_assert(kproc->reset);
- if (ret) {
- dev_err(dev, "could not assert local reset\n");
+ ret = k3_rproc_reset(kproc);
+ if (ret)
return ret;
- }
ret = reset_control_status(kproc->reset);
if (ret <= 0) {
@@ -374,16 +372,8 @@ static int k3_m4_rproc_start(struct rproc *rproc)
static int k3_m4_rproc_stop(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
- int ret;
- ret = reset_control_assert(kproc->reset);
- if (ret) {
- dev_err(dev, "local-reset assert failed, ret = %d\n", ret);
- return ret;
- }
-
- return 0;
+ return k3_rproc_reset(kproc);
}
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 07/20] remoteproc: k3: Refactor rproc_release() implementation into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (5 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 06/20] remoteproc: k3: Refactor rproc_reset() implementation into common driver Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 08/20] remoteproc: k3: Refactor rproc_request_mbox() implementations " Beleswar Padhi
` (14 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The k3_dsp_rproc_release() function erroneously deasserts the local
reset even for devices which do not support it. Even though it results
in a no-operation, Update the logic to explicitly deassert the local
reset for devices that support it and only the global reset for those
that do not.
Further, refactor the above function into the ti_k3_common.c driver as
k3_rproc_release() and use it throughout DSP and M4 drivers for
releasing the reset from the remote processor.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 27 ++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 30 +----------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 8 +++---
4 files changed, 32 insertions(+), 34 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 8f4cc52c1332..cec664819a1d 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -142,5 +142,32 @@ int k3_rproc_reset(struct k3_rproc *kproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_reset);
+/* Release the remote processor from reset */
+int k3_rproc_release(struct k3_rproc *kproc)
+{
+ struct device *dev = kproc->dev;
+ int ret;
+
+ if (kproc->data->uses_lreset) {
+ ret = reset_control_deassert(kproc->reset);
+ if (ret) {
+ dev_err(dev, "local-reset deassert failed, (%pe)\n", ERR_PTR(ret));
+ if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
+ kproc->ti_sci_id))
+ dev_warn(dev, "module-reset assert back failed\n");
+ }
+
+ return ret;
+ }
+
+ ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
+ kproc->ti_sci_id);
+ if (ret)
+ dev_err(dev, "module-reset deassert failed (%pe)\n", ERR_PTR(ret));
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_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 52f784ada496..37516765e505 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -91,4 +91,5 @@ struct k3_rproc {
void k3_rproc_mbox_callback(struct mbox_client *client, void *data);
void k3_rproc_kick(struct rproc *rproc, int vqid);
int k3_rproc_reset(struct k3_rproc *kproc);
+int k3_rproc_release(struct k3_rproc *kproc);
#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 045b1e81d06c..64affbe0ba29 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,34 +24,6 @@
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-/* Release the DSP processor from reset */
-static int k3_dsp_rproc_release(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- int ret;
-
- if (kproc->data->uses_lreset)
- goto lreset;
-
- ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret) {
- dev_err(dev, "module-reset deassert failed (%pe)\n", ERR_PTR(ret));
- return ret;
- }
-
-lreset:
- ret = reset_control_deassert(kproc->reset);
- if (ret) {
- dev_err(dev, "local-reset deassert failed, (%pe)\n", ERR_PTR(ret));
- if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
- kproc->ti_sci_id))
- dev_warn(dev, "module-reset assert back failed\n");
- }
-
- return ret;
-}
-
static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
@@ -160,7 +132,7 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
if (ret)
return ret;
- ret = k3_dsp_rproc_release(kproc);
+ ret = k3_rproc_release(kproc);
if (ret)
return ret;
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index d31cf9babf1d..c24085411e1c 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -354,13 +354,11 @@ static int k3_m4_rproc_start(struct rproc *rproc)
if (ret)
return ret;
- ret = reset_control_deassert(kproc->reset);
- if (ret) {
+ ret = k3_rproc_release(kproc);
+ if (ret)
dev_err(dev, "local-reset deassert failed, ret = %d\n", ret);
- return ret;
- }
- return 0;
+ return ret;
}
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 08/20] remoteproc: k3: Refactor rproc_request_mbox() implementations into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (6 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 07/20] remoteproc: k3: Refactor rproc_release() " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 09/20] remoteproc: k3: Refactor .prepare rproc ops " Beleswar Padhi
` (13 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The k3_dsp_rproc_request_mbox() function acquires the mailbox channel
and sends a message through the acquired channel. The
ti_k3_m4_remoteproc.c driver acquires the mailbox channel in probe and
sends the message later in .attach()/.start() callbacks. Refactor the
k3_dsp_rproc_request_mbox() function into ti_k3_common.c as
k3_rproc_request_mbox() and align DSP and M4 drivers to use this common
function during probe routine.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 36 +++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 36 +------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 42 ++---------------------
4 files changed, 41 insertions(+), 74 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index cec664819a1d..a78abecf2756 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -169,5 +169,41 @@ int k3_rproc_release(struct k3_rproc *kproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_release);
+int k3_rproc_request_mbox(struct rproc *rproc)
+{
+ struct k3_rproc *kproc = rproc->priv;
+ struct mbox_client *client = &kproc->client;
+ struct device *dev = kproc->dev;
+ int ret;
+
+ client->dev = dev;
+ client->tx_done = NULL;
+ client->rx_callback = k3_rproc_mbox_callback;
+ client->tx_block = false;
+ client->knows_txdone = false;
+
+ kproc->mbox = mbox_request_channel(client, 0);
+ if (IS_ERR(kproc->mbox))
+ return dev_err_probe(dev, PTR_ERR(kproc->mbox),
+ "mbox_request_channel failed\n");
+
+ /*
+ * Ping the remote processor, this is only for sanity-sake for now;
+ * there is no functional effect whatsoever.
+ *
+ * Note that the reply will _not_ arrive immediately: this message
+ * will wait in the mailbox fifo until the remote processor is booted.
+ */
+ ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
+ if (ret < 0) {
+ dev_err(dev, "mbox_send_message failed (%pe)\n", ERR_PTR(ret));
+ mbox_free_channel(kproc->mbox);
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_request_mbox);
+
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 37516765e505..8e44c0455c39 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -92,4 +92,5 @@ void k3_rproc_mbox_callback(struct mbox_client *client, void *data);
void k3_rproc_kick(struct rproc *rproc, int vqid);
int k3_rproc_reset(struct k3_rproc *kproc);
int k3_rproc_release(struct k3_rproc *kproc);
+int k3_rproc_request_mbox(struct rproc *rproc);
#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 64affbe0ba29..c8bab63a4f4d 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,40 +24,6 @@
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct mbox_client *client = &kproc->client;
- struct device *dev = kproc->dev;
- int ret;
-
- client->dev = dev;
- client->tx_done = NULL;
- client->rx_callback = k3_rproc_mbox_callback;
- client->tx_block = false;
- client->knows_txdone = false;
-
- kproc->mbox = mbox_request_channel(client, 0);
- if (IS_ERR(kproc->mbox))
- return dev_err_probe(dev, PTR_ERR(kproc->mbox),
- "mbox_request_channel failed\n");
-
- /*
- * Ping the remote processor, this is only for sanity-sake for now;
- * there is no functional effect whatsoever.
- *
- * Note that the reply will _not_ arrive immediately: this message
- * will wait in the mailbox fifo until the remote processor is booted.
- */
- ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
- if (ret < 0) {
- dev_err(dev, "mbox_send_message failed (%pe)\n", ERR_PTR(ret));
- mbox_free_channel(kproc->mbox);
- return ret;
- }
-
- return 0;
-}
/*
* The C66x DSP cores have a local reset that affects only the CPU, and a
* generic module reset that powers on the device and allows the DSP internal
@@ -460,7 +426,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
kproc->dev = dev;
kproc->data = data;
- ret = k3_dsp_rproc_request_mbox(rproc);
+ ret = k3_rproc_request_mbox(rproc);
if (ret)
return ret;
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index c24085411e1c..6dd93c8d0553 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,27 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- int ret;
-
- /*
- * Ping the remote processor, this is only for sanity-sake for now;
- * there is no functional effect whatsoever.
- *
- * Note that the reply will _not_ arrive immediately: this message
- * will wait in the mailbox fifo until the remote processor is booted.
- */
- ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
- if (ret < 0) {
- dev_err(dev, "mbox_send_message failed: %d\n", ret);
- return ret;
- }
-
- return 0;
-}
-
/*
* The M4 cores have a local reset that affects only the CPU, and a
* generic module reset that powers on the device and allows the internal
@@ -350,10 +329,6 @@ static int k3_m4_rproc_start(struct rproc *rproc)
struct device *dev = kproc->dev;
int ret;
- ret = k3_m4_rproc_ping_mbox(kproc);
- if (ret)
- return ret;
-
ret = k3_rproc_release(kproc);
if (ret)
dev_err(dev, "local-reset deassert failed, ret = %d\n", ret);
@@ -386,14 +361,9 @@ static int k3_m4_rproc_stop(struct rproc *rproc)
static int k3_m4_rproc_attach(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
- int ret;
kproc->is_attach_ongoing = true;
- ret = k3_m4_rproc_ping_mbox(kproc);
- if (ret)
- return ret;
-
return 0;
}
@@ -506,15 +476,9 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
dev_info(dev, "configured M4F for remoteproc mode\n");
}
- kproc->client.dev = dev;
- kproc->client.tx_done = NULL;
- kproc->client.rx_callback = k3_rproc_mbox_callback;
- kproc->client.tx_block = false;
- kproc->client.knows_txdone = false;
- kproc->mbox = mbox_request_channel(&kproc->client, 0);
- if (IS_ERR(kproc->mbox))
- return dev_err_probe(dev, PTR_ERR(kproc->mbox),
- "mbox_request_channel failed\n");
+ ret = k3_rproc_request_mbox(rproc);
+ if (ret)
+ return ret;
ret = devm_rproc_add(dev, rproc);
if (ret)
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 09/20] remoteproc: k3: Refactor .prepare rproc ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (7 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 08/20] remoteproc: k3: Refactor rproc_request_mbox() implementations " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 10/20] remoteproc: k3: Refactor .unprepare " Beleswar Padhi
` (12 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The ti_k3_dsp_remoteproc.c driver asserts the local reset in probe and
releases the global reset in .prepare callback. Whereas, the
ti_k3_m4_remoteproc.c driver does both operations in .prepare callback,
which is more suitable as it ensures lreset is asserted for subsequent
core start operations from sysfs. Refactor the k3_m4_rproc_prepare()
function into the ti_k3_common.c driver as k3_rproc_prepare() and align
DSP and M4 drivers to register this common function as .prepare ops.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 46 +++++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 42 +--------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 45 +---------------------
4 files changed, 49 insertions(+), 85 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index a78abecf2756..699528e4a369 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -205,5 +205,51 @@ int k3_rproc_request_mbox(struct rproc *rproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_request_mbox);
+/*
+ * The K3 DSP and M4 cores have a local reset that affects only the CPU, and a
+ * generic module reset that powers on the device and allows the internal
+ * memories to be accessed while the local reset is asserted. This function is
+ * used to release the global reset on remote cores to allow loading into the
+ * internal RAMs. The .prepare() ops is invoked by remoteproc core before any
+ * firmware loading, and is followed by the .start() ops after loading to
+ * actually let the remote cores to run.
+ */
+int k3_rproc_prepare(struct rproc *rproc)
+{
+ struct k3_rproc *kproc = rproc->priv;
+ struct device *dev = kproc->dev;
+ int ret;
+
+ /* If the core is running already no need to deassert the module reset */
+ if (rproc->state == RPROC_DETACHED)
+ return 0;
+
+ /*
+ * Ensure the local reset is asserted so the core doesn't
+ * execute bogus code when the module reset is released.
+ */
+ if (kproc->data->uses_lreset) {
+ ret = k3_rproc_reset(kproc);
+ if (ret)
+ return ret;
+
+ ret = reset_control_status(kproc->reset);
+ if (ret <= 0) {
+ dev_err(dev, "local reset still not asserted\n");
+ return ret;
+ }
+ }
+
+ ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
+ kproc->ti_sci_id);
+ if (ret) {
+ dev_err(dev, "could not deassert module-reset for internal RAM loading\n");
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_prepare);
+
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 8e44c0455c39..22dd6e13f47a 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -93,4 +93,5 @@ void k3_rproc_kick(struct rproc *rproc, int vqid);
int k3_rproc_reset(struct k3_rproc *kproc);
int k3_rproc_release(struct k3_rproc *kproc);
int k3_rproc_request_mbox(struct rproc *rproc);
+int k3_rproc_prepare(struct rproc *rproc);
#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 c8bab63a4f4d..078bfb9aa233 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,31 +24,6 @@
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-/*
- * The C66x DSP cores have a local reset that affects only the CPU, and a
- * generic module reset that powers on the device and allows the DSP internal
- * memories to be accessed while the local reset is asserted. This function is
- * used to release the global reset on C66x DSPs to allow loading into the DSP
- * internal RAMs. The .prepare() ops is invoked by remoteproc core before any
- * firmware loading, and is followed by the .start() ops after loading to
- * actually let the C66x DSP cores run. This callback is invoked only in
- * remoteproc mode.
- */
-static int k3_dsp_rproc_prepare(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
- int ret;
-
- ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret)
- dev_err(dev, "module-reset deassert failed, cannot enable internal RAM loading (%pe)\n",
- ERR_PTR(ret));
-
- return ret;
-}
-
/*
* This function implements the .unprepare() ops and performs the complimentary
* operations to that of the .prepare() ops. The function is used to assert the
@@ -418,7 +393,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
rproc->has_iommu = false;
rproc->recovery_disabled = true;
if (data->uses_lreset) {
- rproc->ops->prepare = k3_dsp_rproc_prepare;
+ rproc->ops->prepare = k3_rproc_prepare;
rproc->ops->unprepare = k3_dsp_rproc_unprepare;
}
kproc = rproc->priv;
@@ -476,7 +451,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_info(dev, "configured DSP for IPC-only mode\n");
rproc->state = RPROC_DETACHED;
/* override rproc ops with only required IPC-only mode ops */
- rproc->ops->prepare = NULL;
rproc->ops->unprepare = NULL;
rproc->ops->start = NULL;
rproc->ops->stop = NULL;
@@ -485,20 +459,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
rproc->ops->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table;
} else {
dev_info(dev, "configured DSP for remoteproc mode\n");
- /*
- * ensure the DSP local reset is asserted to ensure the DSP
- * doesn't execute bogus code in .prepare() when the module
- * reset is released.
- */
- if (data->uses_lreset) {
- ret = reset_control_status(kproc->reset);
- if (ret < 0) {
- return dev_err_probe(dev, ret, "failed to get reset status\n");
- } else if (ret == 0) {
- dev_warn(dev, "local reset is deasserted for device\n");
- k3_rproc_reset(kproc);
- }
- }
}
ret = devm_rproc_add(dev, rproc);
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 6dd93c8d0553..218d4bf941a1 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,49 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-/*
- * The M4 cores have a local reset that affects only the CPU, and a
- * generic module reset that powers on the device and allows the internal
- * memories to be accessed while the local reset is asserted. This function is
- * used to release the global reset on remote cores to allow loading into the
- * internal RAMs. The .prepare() ops is invoked by remoteproc core before any
- * firmware loading, and is followed by the .start() ops after loading to
- * actually let the remote cores to run.
- */
-static int k3_m4_rproc_prepare(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
- int ret;
-
- /* If the core is running already no need to deassert the module reset */
- if (rproc->state == RPROC_DETACHED)
- return 0;
-
- /*
- * Ensure the local reset is asserted so the core doesn't
- * execute bogus code when the module reset is released.
- */
- ret = k3_rproc_reset(kproc);
- if (ret)
- return ret;
-
- ret = reset_control_status(kproc->reset);
- if (ret <= 0) {
- dev_err(dev, "local reset still not asserted\n");
- return ret;
- }
-
- ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret) {
- dev_err(dev, "could not deassert module-reset for internal RAM loading\n");
- return ret;
- }
-
- return 0;
-}
-
/*
* This function implements the .unprepare() ops and performs the complimentary
* operations to that of the .prepare() ops. The function is used to assert the
@@ -386,7 +343,7 @@ static int k3_m4_rproc_detach(struct rproc *rproc)
}
static const struct rproc_ops k3_m4_rproc_ops = {
- .prepare = k3_m4_rproc_prepare,
+ .prepare = k3_rproc_prepare,
.unprepare = k3_m4_rproc_unprepare,
.start = k3_m4_rproc_start,
.stop = k3_m4_rproc_stop,
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 10/20] remoteproc: k3: Refactor .unprepare rproc ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (8 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 09/20] remoteproc: k3: Refactor .prepare rproc ops " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 11/20] remoteproc: k3: Refactor .start " Beleswar Padhi
` (11 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The .unprepare rproc ops implementations in ti_k3_dsp_remoteproc.c and
ti_k3_m4_remoteproc.c drivers assert the global reset on the remote
processor. Refactor the implementations into ti_k3_common.c driver as
k3_rproc_unprepare() and align DSP and M4 drivers to register this
common function as .unprepare ops.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 30 ++++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 26 +------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 31 +----------------------
4 files changed, 33 insertions(+), 55 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 699528e4a369..7fd8c8394d95 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -251,5 +251,35 @@ int k3_rproc_prepare(struct rproc *rproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_prepare);
+/*
+ * This function implements the .unprepare() ops and performs the complimentary
+ * operations to that of the .prepare() ops. The function is used to assert the
+ * global reset on applicable K3 DSP and M4 cores. This completes the second
+ * portion of powering down the remote core. The cores themselves are only
+ * halted in the .stop() callback through the local reset, and the .unprepare()
+ * ops is invoked by the remoteproc core after the remoteproc is stopped to
+ * balance the global reset.
+ */
+int k3_rproc_unprepare(struct rproc *rproc)
+{
+ struct k3_rproc *kproc = rproc->priv;
+ struct device *dev = kproc->dev;
+ int ret;
+
+ /* If the core is going to be detached do not assert the module reset */
+ if (rproc->state == RPROC_ATTACHED)
+ return 0;
+
+ ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
+ kproc->ti_sci_id);
+ if (ret) {
+ dev_err(dev, "module-reset assert failed\n");
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_unprepare);
+
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 22dd6e13f47a..b6b977e16af6 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -94,4 +94,5 @@ int k3_rproc_reset(struct k3_rproc *kproc);
int k3_rproc_release(struct k3_rproc *kproc);
int k3_rproc_request_mbox(struct rproc *rproc);
int k3_rproc_prepare(struct rproc *rproc);
+int k3_rproc_unprepare(struct rproc *rproc);
#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 078bfb9aa233..7e7aca192d0a 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,29 +24,6 @@
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-/*
- * This function implements the .unprepare() ops and performs the complimentary
- * operations to that of the .prepare() ops. The function is used to assert the
- * global reset on applicable C66x cores. This completes the second portion of
- * powering down the C66x DSP cores. The cores themselves are only halted in the
- * .stop() callback through the local reset, and the .unprepare() ops is invoked
- * by the remoteproc core after the remoteproc is stopped to balance the global
- * reset. This callback is invoked only in remoteproc mode.
- */
-static int k3_dsp_rproc_unprepare(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
- int ret;
-
- ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret)
- dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret));
-
- return ret;
-}
-
/*
* Power up the DSP remote processor.
*
@@ -394,7 +371,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
rproc->recovery_disabled = true;
if (data->uses_lreset) {
rproc->ops->prepare = k3_rproc_prepare;
- rproc->ops->unprepare = k3_dsp_rproc_unprepare;
+ rproc->ops->unprepare = k3_rproc_unprepare;
}
kproc = rproc->priv;
kproc->rproc = rproc;
@@ -451,7 +428,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_info(dev, "configured DSP for IPC-only mode\n");
rproc->state = RPROC_DETACHED;
/* override rproc ops with only required IPC-only mode ops */
- rproc->ops->unprepare = NULL;
rproc->ops->start = NULL;
rproc->ops->stop = NULL;
rproc->ops->attach = k3_dsp_rproc_attach;
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 218d4bf941a1..25f013fa7511 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,35 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-/*
- * This function implements the .unprepare() ops and performs the complimentary
- * operations to that of the .prepare() ops. The function is used to assert the
- * global reset on applicable cores. This completes the second portion of
- * powering down the remote core. The cores themselves are only halted in the
- * .stop() callback through the local reset, and the .unprepare() ops is invoked
- * by the remoteproc core after the remoteproc is stopped to balance the global
- * reset.
- */
-static int k3_m4_rproc_unprepare(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
- int ret;
-
- /* If the core is going to be detached do not assert the module reset */
- if (rproc->state == RPROC_ATTACHED)
- return 0;
-
- ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret) {
- dev_err(dev, "module-reset assert failed\n");
- return ret;
- }
-
- return 0;
-}
-
/*
* This function implements the .get_loaded_rsc_table() callback and is used
* to provide the resource table for a booted remote processor in IPC-only
@@ -344,7 +315,7 @@ static int k3_m4_rproc_detach(struct rproc *rproc)
static const struct rproc_ops k3_m4_rproc_ops = {
.prepare = k3_rproc_prepare,
- .unprepare = k3_m4_rproc_unprepare,
+ .unprepare = k3_rproc_unprepare,
.start = k3_m4_rproc_start,
.stop = k3_m4_rproc_stop,
.attach = k3_m4_rproc_attach,
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 11/20] remoteproc: k3: Refactor .start rproc ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (9 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 10/20] remoteproc: k3: Refactor .unprepare " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 12/20] remoteproc: k3: Refactor .stop " Beleswar Padhi
` (10 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The k3_dsp_rproc_start() function sets the boot address and releases the
reset on the remote processor. Whereas, the k3_m4_rproc_start() function
only needs to release the reset. Refactor the k3_m4_rproc_start() into
ti_k3_common.c as k3_rproc_start() and align the DSP and M4 drivers to
invoke this common function when releasing the reset on the remote
processor.
Further, do not override the .start ops with NULL when operating in
IPC-only mode in ti_k3_dsp_remoteproc.c, as .start is never invoked in
rproc_attach routine.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 15 +++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 4 ++--
drivers/remoteproc/ti_k3_m4_remoteproc.c | 22 +---------------------
4 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 7fd8c8394d95..b1d828dbb334 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -281,5 +281,20 @@ int k3_rproc_unprepare(struct rproc *rproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_unprepare);
+/*
+ * Power up the remote processor.
+ *
+ * This function will be invoked only after the firmware for this rproc
+ * was loaded, parsed successfully, and all of its resource requirements
+ * were met. This callback is invoked only in remoteproc mode.
+ */
+int k3_rproc_start(struct rproc *rproc)
+{
+ struct k3_rproc *kproc = rproc->priv;
+
+ return k3_rproc_release(kproc);
+}
+EXPORT_SYMBOL_GPL(k3_rproc_start);
+
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 b6b977e16af6..2eb1539b3bb9 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -95,4 +95,5 @@ int k3_rproc_release(struct k3_rproc *kproc);
int k3_rproc_request_mbox(struct rproc *rproc);
int k3_rproc_prepare(struct rproc *rproc);
int k3_rproc_unprepare(struct rproc *rproc);
+int k3_rproc_start(struct rproc *rproc);
#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 7e7aca192d0a..75ab86b4e82a 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -50,7 +50,8 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
if (ret)
return ret;
- ret = k3_rproc_release(kproc);
+ /* Call the K3 common start function after doing DSP specific stuff */
+ ret = k3_rproc_start(rproc);
if (ret)
return ret;
@@ -428,7 +429,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_info(dev, "configured DSP for IPC-only mode\n");
rproc->state = RPROC_DETACHED;
/* override rproc ops with only required IPC-only mode ops */
- rproc->ops->start = NULL;
rproc->ops->stop = NULL;
rproc->ops->attach = k3_dsp_rproc_attach;
rproc->ops->detach = k3_dsp_rproc_detach;
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 25f013fa7511..0f1237172233 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -244,26 +244,6 @@ static void k3_m4_release_tsp(void *data)
ti_sci_proc_release(tsp);
}
-/*
- * Power up the M4 remote processor.
- *
- * This function will be invoked only after the firmware for this rproc
- * was loaded, parsed successfully, and all of its resource requirements
- * were met. This callback is invoked only in remoteproc mode.
- */
-static int k3_m4_rproc_start(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
- int ret;
-
- ret = k3_rproc_release(kproc);
- if (ret)
- dev_err(dev, "local-reset deassert failed, ret = %d\n", ret);
-
- return ret;
-}
-
/*
* Stop the M4 remote processor.
*
@@ -316,7 +296,7 @@ static int k3_m4_rproc_detach(struct rproc *rproc)
static const struct rproc_ops k3_m4_rproc_ops = {
.prepare = k3_rproc_prepare,
.unprepare = k3_rproc_unprepare,
- .start = k3_m4_rproc_start,
+ .start = k3_rproc_start,
.stop = k3_m4_rproc_stop,
.attach = k3_m4_rproc_attach,
.detach = k3_m4_rproc_detach,
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 12/20] remoteproc: k3: Refactor .stop rproc ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (10 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 11/20] remoteproc: k3: Refactor .start " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 13/20] remoteproc: k3: Refactor .attach " Beleswar Padhi
` (9 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The .stop rproc ops implementations in ti_k3_dsp_remoteproc.c and
ti_k3_m4_remoteproc.c drivers put the remote processor into reset.
Refactor the implementations into ti_k3_common.c driver as
k3_rproc_stop() and align DSP and M4 drivers to register this common
function as .stop ops.
Further, do not override the .stop ops with NULL when operating in
IPC-only mode in ti_k3_dsp_remoteproc.c, as .stop is never invoked in
rproc_detach routine.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 14 ++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 18 +-----------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 15 +--------------
4 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index b1d828dbb334..799152d1a736 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -296,5 +296,19 @@ int k3_rproc_start(struct rproc *rproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_start);
+/*
+ * Stop the remote processor.
+ *
+ * This function puts the remote processor into reset, and finishes processing
+ * of any pending messages. This callback is invoked only in remoteproc mode.
+ */
+int k3_rproc_stop(struct rproc *rproc)
+{
+ struct k3_rproc *kproc = rproc->priv;
+
+ return k3_rproc_reset(kproc);
+}
+EXPORT_SYMBOL_GPL(k3_rproc_stop);
+
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 2eb1539b3bb9..bfcb5d086cff 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -96,4 +96,5 @@ int k3_rproc_request_mbox(struct rproc *rproc);
int k3_rproc_prepare(struct rproc *rproc);
int k3_rproc_unprepare(struct rproc *rproc);
int k3_rproc_start(struct rproc *rproc);
+int k3_rproc_stop(struct rproc *rproc);
#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 75ab86b4e82a..a9896ba51399 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -58,21 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
return 0;
}
-/*
- * Stop the DSP remote processor.
- *
- * This function puts the DSP processor into reset, and finishes processing
- * of any pending messages. This callback is invoked only in remoteproc mode.
- */
-static int k3_dsp_rproc_stop(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
-
- k3_rproc_reset(kproc);
-
- return 0;
-}
-
/*
* Attach to a running DSP remote processor (IPC-only mode)
*
@@ -203,7 +188,7 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool
static const struct rproc_ops k3_dsp_rproc_ops = {
.start = k3_dsp_rproc_start,
- .stop = k3_dsp_rproc_stop,
+ .stop = k3_rproc_stop,
.kick = k3_rproc_kick,
.da_to_va = k3_dsp_rproc_da_to_va,
};
@@ -429,7 +414,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_info(dev, "configured DSP for IPC-only mode\n");
rproc->state = RPROC_DETACHED;
/* override rproc ops with only required IPC-only mode ops */
- rproc->ops->stop = NULL;
rproc->ops->attach = k3_dsp_rproc_attach;
rproc->ops->detach = k3_dsp_rproc_detach;
rproc->ops->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table;
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 0f1237172233..27bf8ed49f59 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -244,19 +244,6 @@ static void k3_m4_release_tsp(void *data)
ti_sci_proc_release(tsp);
}
-/*
- * Stop the M4 remote processor.
- *
- * This function puts the M4 processor into reset, and finishes processing
- * of any pending messages. This callback is invoked only in remoteproc mode.
- */
-static int k3_m4_rproc_stop(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
-
- return k3_rproc_reset(kproc);
-}
-
/*
* Attach to a running M4 remote processor (IPC-only mode)
*
@@ -297,7 +284,7 @@ static const struct rproc_ops k3_m4_rproc_ops = {
.prepare = k3_rproc_prepare,
.unprepare = k3_rproc_unprepare,
.start = k3_rproc_start,
- .stop = k3_m4_rproc_stop,
+ .stop = k3_rproc_stop,
.attach = k3_m4_rproc_attach,
.detach = k3_m4_rproc_detach,
.kick = k3_rproc_kick,
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 13/20] remoteproc: k3: Refactor .attach rproc ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (11 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 12/20] remoteproc: k3: Refactor .stop " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 14/20] remoteproc: k3: Refactor .detach " Beleswar Padhi
` (8 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The .attach rproc ops implementations in ti_k3_dsp_remoteproc.c and
ti_k3_m4_remoteproc.c drivers set the "is_attach_ongoing" flag to
signify that the core is undergoing transition from detached to
attached state. Refactor the implementations into ti_k3_common.c driver
as k3_rproc_attach() and align DSP and M4 drivers to register this
common function as .attach ops.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 20 ++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 21 +--------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 20 +-------------------
4 files changed, 23 insertions(+), 39 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 799152d1a736..296a47de9d72 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -310,5 +310,25 @@ int k3_rproc_stop(struct rproc *rproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_stop);
+/*
+ * Attach to a running remote processor (IPC-only mode)
+ *
+ * This rproc attach callback only needs to set the "is_attach_ongoing" flag to
+ * notify k3_rproc_{kick/mbox_callback} functions that the core is in the
+ * process of getting attached in IPC-only mode. The remote processor is already
+ * booted, and all required resources have been acquired during probe routine,
+ * so there is no need to issue any TI-SCI commands to boot the remote core.
+ * This callback is invoked only in IPC-only mode.
+ */
+int k3_rproc_attach(struct rproc *rproc)
+{
+ struct k3_rproc *kproc = rproc->priv;
+
+ kproc->is_attach_ongoing = true;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_attach);
+
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 bfcb5d086cff..89175cb5a006 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -97,4 +97,5 @@ int k3_rproc_prepare(struct rproc *rproc);
int k3_rproc_unprepare(struct rproc *rproc);
int k3_rproc_start(struct rproc *rproc);
int k3_rproc_stop(struct rproc *rproc);
+int k3_rproc_attach(struct rproc *rproc);
#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 a9896ba51399..43c1eda47be2 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -58,25 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
return 0;
}
-/*
- * Attach to a running DSP remote processor (IPC-only mode)
- *
- * This rproc attach callback only needs to set the "is_attach_ongoing" flag to
- * notify k3_rproc_{kick/mbox_callback} functions that the core is in the
- * process of getting attached in IPC-only mode. The remote processor is already
- * booted, and all required resources have been acquired during probe routine,
- * so there is no need to issue any TI-SCI commands to boot the DSP core. This
- * callback is invoked only in IPC-only mode.
- */
-static int k3_dsp_rproc_attach(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
-
- kproc->is_attach_ongoing = true;
-
- return 0;
-}
-
/*
* Detach from a running DSP remote processor (IPC-only mode)
*
@@ -189,6 +170,7 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool
static const struct rproc_ops k3_dsp_rproc_ops = {
.start = k3_dsp_rproc_start,
.stop = k3_rproc_stop,
+ .attach = k3_rproc_attach,
.kick = k3_rproc_kick,
.da_to_va = k3_dsp_rproc_da_to_va,
};
@@ -414,7 +396,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_info(dev, "configured DSP for IPC-only mode\n");
rproc->state = RPROC_DETACHED;
/* override rproc ops with only required IPC-only mode ops */
- rproc->ops->attach = k3_dsp_rproc_attach;
rproc->ops->detach = k3_dsp_rproc_detach;
rproc->ops->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table;
} else {
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 27bf8ed49f59..e78e35c1375c 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -244,24 +244,6 @@ static void k3_m4_release_tsp(void *data)
ti_sci_proc_release(tsp);
}
-/*
- * Attach to a running M4 remote processor (IPC-only mode)
- *
- * This rproc attach callback only needs to set the "is_attach_ongoing" flag to
- * notify k3_rproc_{kick/mbox_callback} functions that the core is in the
- * process of getting attached in IPC-only mode. The remote processor is already
- * booted, so there is no need to issue any TI-SCI commands to boot the M4 core.
- * This callback is used only in IPC-only mode.
- */
-static int k3_m4_rproc_attach(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
-
- kproc->is_attach_ongoing = true;
-
- return 0;
-}
-
/*
* Detach from a running M4 remote processor (IPC-only mode)
*
@@ -285,7 +267,7 @@ static const struct rproc_ops k3_m4_rproc_ops = {
.unprepare = k3_rproc_unprepare,
.start = k3_rproc_start,
.stop = k3_rproc_stop,
- .attach = k3_m4_rproc_attach,
+ .attach = k3_rproc_attach,
.detach = k3_m4_rproc_detach,
.kick = k3_rproc_kick,
.da_to_va = k3_m4_rproc_da_to_va,
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 14/20] remoteproc: k3: Refactor .detach rproc ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (12 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 13/20] remoteproc: k3: Refactor .attach " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 15/20] remoteproc: k3: Refactor .get_loaded_rsc_table " Beleswar Padhi
` (7 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The .detach rproc ops implementations in ti_k3_dsp_remoteproc.c and
ti_k3_m4_remoteproc.c drivers clears the "is_attach_ongoing" flag which
was set in .attach ops. Refactor the implementations into ti_k3_common.c
driver as k3_rproc_detach() and align DSP and M4 drivers to register
this common function as .detach ops.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 19 +++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 20 +-------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 20 +-------------------
4 files changed, 22 insertions(+), 38 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 296a47de9d72..b5ef2ac0d399 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -330,5 +330,24 @@ int k3_rproc_attach(struct rproc *rproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_attach);
+/*
+ * Detach from a running remote processor (IPC-only mode)
+ *
+ * This rproc detach callback performs the opposite operation to attach callback
+ * and only needs to clear the "is_attach_ongoing" flag to ensure no mailbox
+ * messages are sent to or received from a detached core. The remote core is not
+ * stopped and will be left to continue to run its booted firmware. This callback
+ * is invoked only in IPC-only mode.
+ */
+int k3_rproc_detach(struct rproc *rproc)
+{
+ struct k3_rproc *kproc = rproc->priv;
+
+ kproc->is_attach_ongoing = false;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_detach);
+
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 89175cb5a006..c7be85b0e5ac 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -98,4 +98,5 @@ int k3_rproc_unprepare(struct rproc *rproc);
int k3_rproc_start(struct rproc *rproc);
int k3_rproc_stop(struct rproc *rproc);
int k3_rproc_attach(struct rproc *rproc);
+int k3_rproc_detach(struct rproc *rproc);
#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 43c1eda47be2..dd81bcc8e1e4 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -58,24 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
return 0;
}
-/*
- * Detach from a running DSP remote processor (IPC-only mode)
- *
- * This rproc detach callback performs the opposite operation to attach callback
- * and only needs to clear the "is_attach_ongoing" flag to ensure no mailbox
- * messages are sent to or received from a detached core. The DSP core is not
- * stopped and will be left to continue to run its booted firmware. This callback
- * is invoked only in IPC-only mode.
- */
-static int k3_dsp_rproc_detach(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
-
- kproc->is_attach_ongoing = false;
-
- return 0;
-}
-
/*
* This function implements the .get_loaded_rsc_table() callback and is used
* to provide the resource table for a booted DSP in IPC-only mode. The K3 DSP
@@ -171,6 +153,7 @@ static const struct rproc_ops k3_dsp_rproc_ops = {
.start = k3_dsp_rproc_start,
.stop = k3_rproc_stop,
.attach = k3_rproc_attach,
+ .detach = k3_rproc_detach,
.kick = k3_rproc_kick,
.da_to_va = k3_dsp_rproc_da_to_va,
};
@@ -396,7 +379,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_info(dev, "configured DSP for IPC-only mode\n");
rproc->state = RPROC_DETACHED;
/* override rproc ops with only required IPC-only mode ops */
- rproc->ops->detach = k3_dsp_rproc_detach;
rproc->ops->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table;
} else {
dev_info(dev, "configured DSP for remoteproc mode\n");
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index e78e35c1375c..6b532bda8d1d 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -244,31 +244,13 @@ static void k3_m4_release_tsp(void *data)
ti_sci_proc_release(tsp);
}
-/*
- * Detach from a running M4 remote processor (IPC-only mode)
- *
- * This rproc detach callback performs the opposite operation to attach callback
- * and only needs to clear the "is_attach_ongoing" flag to ensure no mailbox
- * messages are sent to or received from a detached core. The M4 core is not
- * stopped and will be left to continue to run its booted firmware. This
- * callback is invoked only in IPC-only mode.
- */
-static int k3_m4_rproc_detach(struct rproc *rproc)
-{
- struct k3_rproc *kproc = rproc->priv;
-
- kproc->is_attach_ongoing = false;
-
- return 0;
-}
-
static const struct rproc_ops k3_m4_rproc_ops = {
.prepare = k3_rproc_prepare,
.unprepare = k3_rproc_unprepare,
.start = k3_rproc_start,
.stop = k3_rproc_stop,
.attach = k3_rproc_attach,
- .detach = k3_m4_rproc_detach,
+ .detach = k3_rproc_detach,
.kick = k3_rproc_kick,
.da_to_va = k3_m4_rproc_da_to_va,
.get_loaded_rsc_table = k3_m4_get_loaded_rsc_table,
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 15/20] remoteproc: k3: Refactor .get_loaded_rsc_table ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (13 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 14/20] remoteproc: k3: Refactor .detach " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 16/20] remoteproc: k3: Refactor .da_to_va rproc " Beleswar Padhi
` (6 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The .get_loaded_rsc_table rproc ops implementations in
ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c drivers return a
pointer to the resource table that was pre-loaded at the base address of
the DDR region reserved for firmware usage. Refactor the implementations
into ti_k3_common.c driver as k3_get_loaded_rsc_table() and align DSP
and M4 drivers to register this common function as .get_loaded_rsc_table
ops.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 33 +++++++++++++++
drivers/remoteproc/ti_k3_common.h | 2 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 49 ++++-------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 34 +---------------
4 files changed, 44 insertions(+), 74 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index b5ef2ac0d399..f56d2553a669 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -349,5 +349,38 @@ int k3_rproc_detach(struct rproc *rproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_detach);
+/*
+ * This function implements the .get_loaded_rsc_table() callback and is used
+ * to provide the resource table for a booted remote processor in IPC-only
+ * mode. The remote processor firmwares follow a design-by-contract approach
+ * and are expected to have the resource table at the base of the DDR region
+ * reserved for firmware usage. This provides flexibility for the remote
+ * processor to be booted by different bootloaders that may or may not have the
+ * ability to publish the resource table address and size through a DT
+ * property.
+ */
+struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
+ size_t *rsc_table_sz)
+{
+ struct k3_rproc *kproc = rproc->priv;
+ struct device *dev = kproc->dev;
+
+ if (!kproc->rmem[0].cpu_addr) {
+ dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
+ return ERR_PTR(-ENOMEM);
+ }
+
+ /*
+ * NOTE: The resource table size is currently hard-coded to a maximum
+ * of 256 bytes. The most common resource table usage for K3 firmwares
+ * is to only have the vdev resource entry and an optional trace entry.
+ * The exact size could be computed based on resource table address, but
+ * the hard-coded value suffices to support the IPC-only mode.
+ */
+ *rsc_table_sz = 256;
+ return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
+}
+EXPORT_SYMBOL_GPL(k3_get_loaded_rsc_table);
+
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 c7be85b0e5ac..663911dc7032 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -99,4 +99,6 @@ int k3_rproc_start(struct rproc *rproc);
int k3_rproc_stop(struct rproc *rproc);
int k3_rproc_attach(struct rproc *rproc);
int k3_rproc_detach(struct rproc *rproc);
+struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
+ size_t *rsc_table_sz);
#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 dd81bcc8e1e4..0bfa3b730d1f 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -58,38 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
return 0;
}
-/*
- * This function implements the .get_loaded_rsc_table() callback and is used
- * to provide the resource table for a booted DSP in IPC-only mode. The K3 DSP
- * firmwares follow a design-by-contract approach and are expected to have the
- * resource table at the base of the DDR region reserved for firmware usage.
- * This provides flexibility for the remote processor to be booted by different
- * bootloaders that may or may not have the ability to publish the resource table
- * address and size through a DT property. This callback is invoked only in
- * IPC-only mode.
- */
-static struct resource_table *k3_dsp_get_loaded_rsc_table(struct rproc *rproc,
- size_t *rsc_table_sz)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
-
- if (!kproc->rmem[0].cpu_addr) {
- dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
- return ERR_PTR(-ENOMEM);
- }
-
- /*
- * NOTE: The resource table size is currently hard-coded to a maximum
- * of 256 bytes. The most common resource table usage for K3 firmwares
- * is to only have the vdev resource entry and an optional trace entry.
- * The exact size could be computed based on resource table address, but
- * the hard-coded value suffices to support the IPC-only mode.
- */
- *rsc_table_sz = 256;
- return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
-}
-
/*
* Custom function to translate a DSP device address (internal RAMs only) to a
* kernel virtual address. The DSPs can access their RAMs at either an internal
@@ -150,12 +118,13 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool
}
static const struct rproc_ops k3_dsp_rproc_ops = {
- .start = k3_dsp_rproc_start,
- .stop = k3_rproc_stop,
- .attach = k3_rproc_attach,
- .detach = k3_rproc_detach,
- .kick = k3_rproc_kick,
- .da_to_va = k3_dsp_rproc_da_to_va,
+ .start = k3_dsp_rproc_start,
+ .stop = k3_rproc_stop,
+ .attach = k3_rproc_attach,
+ .detach = k3_rproc_detach,
+ .kick = k3_rproc_kick,
+ .da_to_va = k3_dsp_rproc_da_to_va,
+ .get_loaded_rsc_table = k3_get_loaded_rsc_table,
};
static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev,
@@ -374,12 +343,10 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "failed to get initial state, mode cannot be determined\n");
- /* configure J721E devices for either remoteproc or IPC-only mode */
+ /* configure devices for either remoteproc or IPC-only mode */
if (p_state) {
dev_info(dev, "configured DSP for IPC-only mode\n");
rproc->state = RPROC_DETACHED;
- /* override rproc ops with only required IPC-only mode ops */
- rproc->ops->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table;
} else {
dev_info(dev, "configured DSP for remoteproc mode\n");
}
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 6b532bda8d1d..e1caa5ee9a0d 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,38 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-/*
- * This function implements the .get_loaded_rsc_table() callback and is used
- * to provide the resource table for a booted remote processor in IPC-only
- * mode. The remote processor firmwares follow a design-by-contract approach
- * and are expected to have the resource table at the base of the DDR region
- * reserved for firmware usage. This provides flexibility for the remote
- * processor to be booted by different bootloaders that may or may not have the
- * ability to publish the resource table address and size through a DT
- * property.
- */
-static struct resource_table *k3_m4_get_loaded_rsc_table(struct rproc *rproc,
- size_t *rsc_table_sz)
-{
- struct k3_rproc *kproc = rproc->priv;
- struct device *dev = kproc->dev;
-
- if (!kproc->rmem[0].cpu_addr) {
- dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
- return ERR_PTR(-ENOMEM);
- }
-
- /*
- * NOTE: The resource table size is currently hard-coded to a maximum
- * of 256 bytes. The most common resource table usage for K3 firmwares
- * is to only have the vdev resource entry and an optional trace entry.
- * The exact size could be computed based on resource table address, but
- * the hard-coded value suffices to support the IPC-only mode.
- */
- *rsc_table_sz = 256;
- return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
-}
-
/*
* Custom function to translate a remote processor device address (internal
* RAMs only) to a kernel virtual address. The remote processors can access
@@ -253,7 +221,7 @@ static const struct rproc_ops k3_m4_rproc_ops = {
.detach = k3_rproc_detach,
.kick = k3_rproc_kick,
.da_to_va = k3_m4_rproc_da_to_va,
- .get_loaded_rsc_table = k3_m4_get_loaded_rsc_table,
+ .get_loaded_rsc_table = k3_get_loaded_rsc_table,
};
static int k3_m4_rproc_probe(struct platform_device *pdev)
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 16/20] remoteproc: k3: Refactor .da_to_va rproc ops into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (14 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 15/20] remoteproc: k3: Refactor .get_loaded_rsc_table " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 17/20] remoteproc: k3: Refactor of_get_memories() functions " Beleswar Padhi
` (5 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The .da_to_va rproc ops implementations in ti_k3_dsp_remoteproc.c and
ti_k3_m4_remoteproc.c drivers return the Kernel virtual address for a
corresponding rproc device address. Refactor the implementations into
ti_k3_common.c driver as k3_rproc_da_to_va and align DSP and M4 drivers
to register this common function as .da_to_va ops.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 61 ++++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 4 ++
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 63 +----------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 58 +--------------------
4 files changed, 67 insertions(+), 119 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index f56d2553a669..520f3fa44195 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -382,5 +382,66 @@ struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
}
EXPORT_SYMBOL_GPL(k3_get_loaded_rsc_table);
+/*
+ * Custom function to translate a remote processor device address (internal
+ * RAMs only) to a kernel virtual address. The remote processors can access
+ * their RAMs at either an internal address visible only from a remote
+ * processor, or at the SoC-level bus address. Both these addresses need to be
+ * looked through for translation. The translated addresses can be used either
+ * by the remoteproc core for loading (when using kernel remoteproc loader), or
+ * by any rpmsg bus drivers.
+ */
+void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
+{
+ struct k3_rproc *kproc = rproc->priv;
+ void __iomem *va = NULL;
+ phys_addr_t bus_addr;
+ u32 dev_addr, offset;
+ size_t size;
+ int i;
+
+ if (len == 0)
+ return NULL;
+
+ for (i = 0; i < kproc->num_mems; i++) {
+ bus_addr = kproc->mem[i].bus_addr;
+ dev_addr = kproc->mem[i].dev_addr;
+ size = kproc->mem[i].size;
+
+ if (da < KEYSTONE_RPROC_LOCAL_ADDRESS_MASK) {
+ /* handle rproc-view addresses */
+ if (da >= dev_addr &&
+ ((da + len) <= (dev_addr + size))) {
+ offset = da - dev_addr;
+ va = kproc->mem[i].cpu_addr + offset;
+ return (__force void *)va;
+ }
+ } else {
+ /* handle SoC-view addresses */
+ if (da >= bus_addr &&
+ (da + len) <= (bus_addr + size)) {
+ offset = da - bus_addr;
+ va = kproc->mem[i].cpu_addr + offset;
+ return (__force void *)va;
+ }
+ }
+ }
+
+ /* handle static DDR reserved memory regions */
+ for (i = 0; i < kproc->num_rmems; i++) {
+ dev_addr = kproc->rmem[i].dev_addr;
+ size = kproc->rmem[i].size;
+
+ if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
+ offset = da - dev_addr;
+ va = kproc->rmem[i].cpu_addr + offset;
+ return (__force void *)va;
+ }
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_da_to_va);
+
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 663911dc7032..622711951811 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -16,6 +16,8 @@
#ifndef REMOTEPROC_TI_K3_COMMON_H
#define REMOTEPROC_TI_K3_COMMON_H
+#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
+
/**
* struct k3_rproc_mem - internal memory structure
* @cpu_addr: MPU virtual address of the memory region
@@ -101,4 +103,6 @@ int k3_rproc_attach(struct rproc *rproc);
int k3_rproc_detach(struct rproc *rproc);
struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
size_t *rsc_table_sz);
+void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len,
+ bool *is_iomem);
#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 0bfa3b730d1f..3d888ab9de6b 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -22,8 +22,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
-
/*
* Power up the DSP remote processor.
*
@@ -58,72 +56,13 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
return 0;
}
-/*
- * Custom function to translate a DSP device address (internal RAMs only) to a
- * kernel virtual address. The DSPs can access their RAMs at either an internal
- * address visible only from a DSP, or at the SoC-level bus address. Both these
- * addresses need to be looked through for translation. The translated addresses
- * can be used either by the remoteproc core for loading (when using kernel
- * remoteproc loader), or by any rpmsg bus drivers.
- */
-static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
-{
- struct k3_rproc *kproc = rproc->priv;
- void __iomem *va = NULL;
- phys_addr_t bus_addr;
- u32 dev_addr, offset;
- size_t size;
- int i;
-
- if (len == 0)
- return NULL;
-
- for (i = 0; i < kproc->num_mems; i++) {
- bus_addr = kproc->mem[i].bus_addr;
- dev_addr = kproc->mem[i].dev_addr;
- size = kproc->mem[i].size;
-
- if (da < KEYSTONE_RPROC_LOCAL_ADDRESS_MASK) {
- /* handle DSP-view addresses */
- if (da >= dev_addr &&
- ((da + len) <= (dev_addr + size))) {
- offset = da - dev_addr;
- va = kproc->mem[i].cpu_addr + offset;
- return (__force void *)va;
- }
- } else {
- /* handle SoC-view addresses */
- if (da >= bus_addr &&
- (da + len) <= (bus_addr + size)) {
- offset = da - bus_addr;
- va = kproc->mem[i].cpu_addr + offset;
- return (__force void *)va;
- }
- }
- }
-
- /* handle static DDR reserved memory regions */
- for (i = 0; i < kproc->num_rmems; i++) {
- dev_addr = kproc->rmem[i].dev_addr;
- size = kproc->rmem[i].size;
-
- if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
- offset = da - dev_addr;
- va = kproc->rmem[i].cpu_addr + offset;
- return (__force void *)va;
- }
- }
-
- return NULL;
-}
-
static const struct rproc_ops k3_dsp_rproc_ops = {
.start = k3_dsp_rproc_start,
.stop = k3_rproc_stop,
.attach = k3_rproc_attach,
.detach = k3_rproc_detach,
.kick = k3_rproc_kick,
- .da_to_va = k3_dsp_rproc_da_to_va,
+ .da_to_va = k3_rproc_da_to_va,
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
};
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index e1caa5ee9a0d..a959f361aae2 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,62 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-/*
- * Custom function to translate a remote processor device address (internal
- * RAMs only) to a kernel virtual address. The remote processors can access
- * their RAMs at either an internal address visible only from a remote
- * processor, or at the SoC-level bus address. Both these addresses need to be
- * looked through for translation. The translated addresses can be used either
- * by the remoteproc core for loading (when using kernel remoteproc loader), or
- * by any rpmsg bus drivers.
- */
-static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
-{
- struct k3_rproc *kproc = rproc->priv;
- void __iomem *va = NULL;
- phys_addr_t bus_addr;
- u32 dev_addr, offset;
- size_t size;
- int i;
-
- if (len == 0)
- return NULL;
-
- for (i = 0; i < kproc->num_mems; i++) {
- bus_addr = kproc->mem[i].bus_addr;
- dev_addr = kproc->mem[i].dev_addr;
- size = kproc->mem[i].size;
-
- /* handle M4-view addresses */
- if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
- offset = da - dev_addr;
- va = kproc->mem[i].cpu_addr + offset;
- return (__force void *)va;
- }
-
- /* handle SoC-view addresses */
- if (da >= bus_addr && ((da + len) <= (bus_addr + size))) {
- offset = da - bus_addr;
- va = kproc->mem[i].cpu_addr + offset;
- return (__force void *)va;
- }
- }
-
- /* handle static DDR reserved memory regions */
- for (i = 0; i < kproc->num_rmems; i++) {
- dev_addr = kproc->rmem[i].dev_addr;
- size = kproc->rmem[i].size;
-
- if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
- offset = da - dev_addr;
- va = kproc->rmem[i].cpu_addr + offset;
- return (__force void *)va;
- }
- }
-
- return NULL;
-}
-
static int k3_m4_rproc_of_get_memories(struct platform_device *pdev,
struct k3_rproc *kproc)
{
@@ -220,7 +164,7 @@ static const struct rproc_ops k3_m4_rproc_ops = {
.attach = k3_rproc_attach,
.detach = k3_rproc_detach,
.kick = k3_rproc_kick,
- .da_to_va = k3_m4_rproc_da_to_va,
+ .da_to_va = k3_rproc_da_to_va,
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
};
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 17/20] remoteproc: k3: Refactor of_get_memories() functions into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (15 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 16/20] remoteproc: k3: Refactor .da_to_va rproc " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 18/20] remoteproc: k3: Refactor mem_release() " Beleswar Padhi
` (4 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The k3_{dsp_/m4_}rproc_of_get_memories() function initializes and
assigns memory regions used by the remote processor. Refactor these
implementations into ti_k3_common.c driver as k3_rproc_of_get_memories()
and align DSP and M4 drivers to use this common function throughout.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 53 ++++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 2 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 54 +----------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 54 +----------------------
4 files changed, 57 insertions(+), 106 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 520f3fa44195..c1c6eabb867f 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -443,5 +443,58 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
}
EXPORT_SYMBOL_GPL(k3_rproc_da_to_va);
+int k3_rproc_of_get_memories(struct platform_device *pdev,
+ struct k3_rproc *kproc)
+{
+ const struct k3_rproc_dev_data *data = kproc->data;
+ struct device *dev = &pdev->dev;
+ struct resource *res;
+ int num_mems = 0;
+ int i;
+
+ num_mems = kproc->data->num_mems;
+ kproc->mem = devm_kcalloc(kproc->dev, num_mems,
+ sizeof(*kproc->mem), GFP_KERNEL);
+ if (!kproc->mem)
+ return -ENOMEM;
+
+ for (i = 0; i < num_mems; i++) {
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+ data->mems[i].name);
+ if (!res) {
+ dev_err(dev, "found no memory resource for %s\n",
+ data->mems[i].name);
+ return -EINVAL;
+ }
+ if (!devm_request_mem_region(dev, res->start,
+ resource_size(res),
+ dev_name(dev))) {
+ dev_err(dev, "could not request %s region for resource\n",
+ data->mems[i].name);
+ return -EBUSY;
+ }
+
+ kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
+ resource_size(res));
+ if (!kproc->mem[i].cpu_addr) {
+ dev_err(dev, "failed to map %s memory\n",
+ data->mems[i].name);
+ return -ENOMEM;
+ }
+ kproc->mem[i].bus_addr = res->start;
+ kproc->mem[i].dev_addr = data->mems[i].dev_addr;
+ kproc->mem[i].size = resource_size(res);
+
+ dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
+ data->mems[i].name, &kproc->mem[i].bus_addr,
+ kproc->mem[i].size, kproc->mem[i].cpu_addr,
+ kproc->mem[i].dev_addr);
+ }
+ kproc->num_mems = num_mems;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_of_get_memories);
+
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 622711951811..8801914a7c56 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -105,4 +105,6 @@ struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
size_t *rsc_table_sz);
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);
#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 3d888ab9de6b..476f53249793 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -66,58 +66,6 @@ static const struct rproc_ops k3_dsp_rproc_ops = {
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
};
-static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev,
- struct k3_rproc *kproc)
-{
- const struct k3_rproc_dev_data *data = kproc->data;
- struct device *dev = &pdev->dev;
- struct resource *res;
- int num_mems = 0;
- int i;
-
- num_mems = kproc->data->num_mems;
- kproc->mem = devm_kcalloc(kproc->dev, num_mems,
- sizeof(*kproc->mem), GFP_KERNEL);
- if (!kproc->mem)
- return -ENOMEM;
-
- for (i = 0; i < num_mems; i++) {
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
- data->mems[i].name);
- if (!res) {
- dev_err(dev, "found no memory resource for %s\n",
- data->mems[i].name);
- return -EINVAL;
- }
- if (!devm_request_mem_region(dev, res->start,
- resource_size(res),
- dev_name(dev))) {
- dev_err(dev, "could not request %s region for resource\n",
- data->mems[i].name);
- return -EBUSY;
- }
-
- kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
- resource_size(res));
- if (!kproc->mem[i].cpu_addr) {
- dev_err(dev, "failed to map %s memory\n",
- data->mems[i].name);
- return -ENOMEM;
- }
- kproc->mem[i].bus_addr = res->start;
- kproc->mem[i].dev_addr = data->mems[i].dev_addr;
- kproc->mem[i].size = resource_size(res);
-
- dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
- data->mems[i].name, &kproc->mem[i].bus_addr,
- kproc->mem[i].size, kproc->mem[i].cpu_addr,
- kproc->mem[i].dev_addr);
- }
- kproc->num_mems = num_mems;
-
- return 0;
-}
-
static void k3_dsp_mem_release(void *data)
{
struct device *dev = data;
@@ -269,7 +217,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = k3_dsp_rproc_of_get_memories(pdev, kproc);
+ ret = k3_rproc_of_get_memories(pdev, kproc);
if (ret)
return ret;
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index a959f361aae2..a077fe2c06aa 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,58 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-static int k3_m4_rproc_of_get_memories(struct platform_device *pdev,
- struct k3_rproc *kproc)
-{
- const struct k3_rproc_dev_data *data = kproc->data;
- struct device *dev = &pdev->dev;
- struct resource *res;
- int num_mems;
- int i;
-
- num_mems = kproc->data->num_mems;
- kproc->mem = devm_kcalloc(kproc->dev, num_mems,
- sizeof(*kproc->mem), GFP_KERNEL);
- if (!kproc->mem)
- return -ENOMEM;
-
- for (i = 0; i < num_mems; i++) {
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
- data->mems[i].name);
- if (!res) {
- dev_err(dev, "found no memory resource for %s\n",
- data->mems[i].name);
- return -EINVAL;
- }
- if (!devm_request_mem_region(dev, res->start,
- resource_size(res),
- dev_name(dev))) {
- dev_err(dev, "could not request %s region for resource\n",
- data->mems[i].name);
- return -EBUSY;
- }
-
- kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
- resource_size(res));
- if (!kproc->mem[i].cpu_addr) {
- dev_err(dev, "failed to map %s memory\n",
- data->mems[i].name);
- return -ENOMEM;
- }
- kproc->mem[i].bus_addr = res->start;
- kproc->mem[i].dev_addr = data->mems[i].dev_addr;
- kproc->mem[i].size = resource_size(res);
-
- dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
- data->mems[i].name, &kproc->mem[i].bus_addr,
- kproc->mem[i].size, kproc->mem[i].cpu_addr,
- kproc->mem[i].dev_addr);
- }
- kproc->num_mems = num_mems;
-
- return 0;
-}
-
static void k3_m4_rproc_dev_mem_release(void *data)
{
struct device *dev = data;
@@ -225,7 +173,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = k3_m4_rproc_of_get_memories(pdev, kproc);
+ ret = k3_rproc_of_get_memories(pdev, kproc);
if (ret)
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 18/20] remoteproc: k3: Refactor mem_release() functions into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (16 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 17/20] remoteproc: k3: Refactor of_get_memories() functions " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 19/20] remoteproc: k3: Refactor reserved_mem_init() " Beleswar Padhi
` (3 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The k3_dsp_mem_release() and k3_m4_rproc_dev_mem_release() functions
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 align DSP and M4 drivers to use this common
function throughout.
Signed-off-by: Beleswar Padhi <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 +--------
4 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index c1c6eabb867f..c8766a01dc19 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -496,5 +496,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 8801914a7c56..31cd202be348 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 476f53249793..1176a6f4c977 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 a077fe2c06aa..6608b13d125b 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;
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 19/20] remoteproc: k3: Refactor reserved_mem_init() functions into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (17 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 18/20] remoteproc: k3: Refactor mem_release() " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:12 ` [PATCH v8 20/20] remoteproc: k3: Refactor release_tsp() " Beleswar Padhi
` (2 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The k3_{dsp_/m4_}reserved_mem_init() functions initialize the reserved
memory regions associated with the remote processor. Refactor these
functions into ti_k3_common.c driver as k3_reserved_mem_init() and align
DSP and M4 drivers to use this common function throughout.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
drivers/remoteproc/ti_k3_common.c | 70 ++++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 72 +----------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 71 +---------------------
4 files changed, 73 insertions(+), 141 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index c8766a01dc19..8fa14b7dde25 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -504,5 +504,75 @@ void k3_mem_release(void *data)
}
EXPORT_SYMBOL_GPL(k3_mem_release);
+int k3_reserved_mem_init(struct k3_rproc *kproc)
+{
+ struct device *dev = kproc->dev;
+ struct device_node *np = dev->of_node;
+ struct device_node *rmem_np;
+ struct reserved_mem *rmem;
+ int num_rmems;
+ int ret, i;
+
+ num_rmems = of_property_count_elems_of_size(np, "memory-region",
+ sizeof(phandle));
+ if (num_rmems < 0) {
+ dev_err(dev, "device does not reserved memory regions (%d)\n",
+ num_rmems);
+ return -EINVAL;
+ }
+ if (num_rmems < 2) {
+ dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n",
+ num_rmems);
+ return -EINVAL;
+ }
+
+ /* use reserved memory region 0 for vring DMA allocations */
+ ret = of_reserved_mem_device_init_by_idx(dev, np, 0);
+ if (ret) {
+ dev_err(dev, "device cannot initialize DMA pool (%d)\n", ret);
+ return ret;
+ }
+ ret = devm_add_action_or_reset(dev, k3_mem_release, dev);
+ if (ret)
+ return ret;
+
+ num_rmems--;
+ kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL);
+ if (!kproc->rmem)
+ return -ENOMEM;
+
+ /* use remaining reserved memory regions for static carveouts */
+ for (i = 0; i < num_rmems; i++) {
+ rmem_np = of_parse_phandle(np, "memory-region", i + 1);
+ if (!rmem_np)
+ return -EINVAL;
+
+ rmem = of_reserved_mem_lookup(rmem_np);
+ of_node_put(rmem_np);
+ if (!rmem)
+ return -EINVAL;
+
+ kproc->rmem[i].bus_addr = rmem->base;
+ /* 64-bit address regions currently not supported */
+ kproc->rmem[i].dev_addr = (u32)rmem->base;
+ kproc->rmem[i].size = rmem->size;
+ kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
+ if (!kproc->rmem[i].cpu_addr) {
+ dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n",
+ i + 1, &rmem->base, &rmem->size);
+ return -ENOMEM;
+ }
+
+ dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
+ i + 1, &kproc->rmem[i].bus_addr,
+ kproc->rmem[i].size, kproc->rmem[i].cpu_addr,
+ kproc->rmem[i].dev_addr);
+ }
+ kproc->num_rmems = num_rmems;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(k3_reserved_mem_init);
+
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 31cd202be348..525d1da65105 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -108,4 +108,5 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len,
int k3_rproc_of_get_memories(struct platform_device *pdev,
struct k3_rproc *kproc);
void k3_mem_release(void *data);
+int k3_reserved_mem_init(struct k3_rproc *kproc);
#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 1176a6f4c977..40187d03206f 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -66,76 +66,6 @@ static const struct rproc_ops k3_dsp_rproc_ops = {
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
};
-static int k3_dsp_reserved_mem_init(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- struct device_node *np = dev->of_node;
- struct device_node *rmem_np;
- struct reserved_mem *rmem;
- int num_rmems;
- int ret, i;
-
- num_rmems = of_property_count_elems_of_size(np, "memory-region",
- sizeof(phandle));
- if (num_rmems < 0) {
- dev_err(dev, "device does not reserved memory regions (%pe)\n",
- ERR_PTR(num_rmems));
- return -EINVAL;
- }
- if (num_rmems < 2) {
- dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n",
- num_rmems);
- return -EINVAL;
- }
-
- /* use reserved memory region 0 for vring DMA allocations */
- ret = of_reserved_mem_device_init_by_idx(dev, np, 0);
- if (ret) {
- dev_err(dev, "device cannot initialize DMA pool (%pe)\n",
- ERR_PTR(ret));
- return ret;
- }
- ret = devm_add_action_or_reset(dev, k3_mem_release, dev);
- if (ret)
- return ret;
-
- num_rmems--;
- kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL);
- if (!kproc->rmem)
- return -ENOMEM;
-
- /* use remaining reserved memory regions for static carveouts */
- for (i = 0; i < num_rmems; i++) {
- rmem_np = of_parse_phandle(np, "memory-region", i + 1);
- if (!rmem_np)
- return -EINVAL;
-
- rmem = of_reserved_mem_lookup(rmem_np);
- of_node_put(rmem_np);
- if (!rmem)
- return -EINVAL;
-
- kproc->rmem[i].bus_addr = rmem->base;
- /* 64-bit address regions currently not supported */
- kproc->rmem[i].dev_addr = (u32)rmem->base;
- kproc->rmem[i].size = rmem->size;
- kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
- if (!kproc->rmem[i].cpu_addr) {
- dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n",
- i + 1, &rmem->base, &rmem->size);
- return -ENOMEM;
- }
-
- dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
- i + 1, &kproc->rmem[i].bus_addr,
- kproc->rmem[i].size, kproc->rmem[i].cpu_addr,
- kproc->rmem[i].dev_addr);
- }
- kproc->num_rmems = num_rmems;
-
- return 0;
-}
-
static void k3_dsp_release_tsp(void *data)
{
struct ti_sci_proc *tsp = data;
@@ -214,7 +144,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = k3_dsp_reserved_mem_init(kproc);
+ ret = k3_reserved_mem_init(kproc);
if (ret)
return dev_err_probe(dev, ret, "reserved memory init failed\n");
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 6608b13d125b..ae8335c8f9e9 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,75 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
-static int k3_m4_reserved_mem_init(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- struct device_node *np = dev->of_node;
- struct device_node *rmem_np;
- struct reserved_mem *rmem;
- int num_rmems;
- int ret, i;
-
- num_rmems = of_property_count_elems_of_size(np, "memory-region",
- sizeof(phandle));
- if (num_rmems < 0) {
- dev_err(dev, "device does not reserved memory regions (%d)\n",
- num_rmems);
- return -EINVAL;
- }
- if (num_rmems < 2) {
- dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n",
- num_rmems);
- return -EINVAL;
- }
-
- /* use reserved memory region 0 for vring DMA allocations */
- ret = of_reserved_mem_device_init_by_idx(dev, np, 0);
- if (ret) {
- dev_err(dev, "device cannot initialize DMA pool (%d)\n", ret);
- return ret;
- }
- ret = devm_add_action_or_reset(dev, k3_mem_release, dev);
- if (ret)
- return ret;
-
- num_rmems--;
- kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL);
- if (!kproc->rmem)
- return -ENOMEM;
-
- /* use remaining reserved memory regions for static carveouts */
- for (i = 0; i < num_rmems; i++) {
- rmem_np = of_parse_phandle(np, "memory-region", i + 1);
- if (!rmem_np)
- return -EINVAL;
-
- rmem = of_reserved_mem_lookup(rmem_np);
- of_node_put(rmem_np);
- if (!rmem)
- return -EINVAL;
-
- kproc->rmem[i].bus_addr = rmem->base;
- /* 64-bit address regions currently not supported */
- kproc->rmem[i].dev_addr = (u32)rmem->base;
- kproc->rmem[i].size = rmem->size;
- kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
- if (!kproc->rmem[i].cpu_addr) {
- dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n",
- i + 1, &rmem->base, &rmem->size);
- return -ENOMEM;
- }
-
- dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
- i + 1, &kproc->rmem[i].bus_addr,
- kproc->rmem[i].size, kproc->rmem[i].cpu_addr,
- kproc->rmem[i].dev_addr);
- }
- kproc->num_rmems = num_rmems;
-
- return 0;
-}
-
static void k3_m4_release_tsp(void *data)
{
struct ti_sci_proc *tsp = data;
@@ -170,7 +101,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = k3_m4_reserved_mem_init(kproc);
+ ret = k3_reserved_mem_init(kproc);
if (ret)
return dev_err_probe(dev, ret, "reserved memory init failed\n");
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v8 20/20] remoteproc: k3: Refactor release_tsp() functions into common driver
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (18 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 19/20] remoteproc: k3: Refactor reserved_mem_init() " Beleswar Padhi
@ 2025-01-03 10:12 ` Beleswar Padhi
2025-01-03 10:50 ` [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Prasad Padhi
2025-01-08 15:03 ` Andrew Davis
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Padhi @ 2025-01-03 10:12 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, b-padhi, linux-remoteproc, linux-kernel
The k3_{dsp_/m4_}release_tsp() functions release the TI-SCI processor
control of a remote processor, which is auto triggered upon device
removal. Refactor these functions into ti_k3_common.c driver as
k3_release_tsp() and align DSP and M4 drivers to use this common
function throughout.
Signed-off-by: Beleswar Padhi <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 +--------
4 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 8fa14b7dde25..d5bdda5d4976 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -574,5 +574,13 @@ int k3_reserved_mem_init(struct k3_rproc *kproc)
}
EXPORT_SYMBOL_GPL(k3_reserved_mem_init);
+void k3_release_tsp(void *data)
+{
+ struct ti_sci_proc *tsp = data;
+
+ ti_sci_proc_release(tsp);
+}
+EXPORT_SYMBOL_GPL(k3_release_tsp);
+
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 525d1da65105..94cac6c1ac62 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -109,4 +109,5 @@ int k3_rproc_of_get_memories(struct platform_device *pdev,
struct k3_rproc *kproc);
void k3_mem_release(void *data);
int k3_reserved_mem_init(struct k3_rproc *kproc);
+void k3_release_tsp(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 40187d03206f..f5f17c18fc1b 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_release_tsp(void *data)
-{
- struct ti_sci_proc *tsp = data;
-
- ti_sci_proc_release(tsp);
-}
-
static int k3_dsp_rproc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -136,7 +129,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_err_probe(dev, ret, "ti_sci_proc_request failed\n");
return ret;
}
- ret = devm_add_action_or_reset(dev, k3_dsp_release_tsp, kproc->tsp);
+ ret = devm_add_action_or_reset(dev, k3_release_tsp, kproc->tsp);
if (ret)
return ret;
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index ae8335c8f9e9..f17e44cebdc7 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_release_tsp(void *data)
-{
- struct ti_sci_proc *tsp = data;
-
- ti_sci_proc_release(tsp);
-}
-
static const struct rproc_ops k3_m4_rproc_ops = {
.prepare = k3_rproc_prepare,
.unprepare = k3_rproc_unprepare,
@@ -93,7 +86,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
ret = ti_sci_proc_request(kproc->tsp);
if (ret < 0)
return dev_err_probe(dev, ret, "ti_sci_proc_request failed\n");
- ret = devm_add_action_or_reset(dev, k3_m4_release_tsp, kproc->tsp);
+ ret = devm_add_action_or_reset(dev, k3_release_tsp, kproc->tsp);
if (ret)
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (19 preceding siblings ...)
2025-01-03 10:12 ` [PATCH v8 20/20] remoteproc: k3: Refactor release_tsp() " Beleswar Padhi
@ 2025-01-03 10:50 ` Beleswar Prasad Padhi
2025-01-08 15:03 ` Andrew Davis
21 siblings, 0 replies; 25+ messages in thread
From: Beleswar Prasad Padhi @ 2025-01-03 10:50 UTC (permalink / raw)
To: andersson, mathieu.poirier
Cc: afd, hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, linux-remoteproc, linux-kernel
Missed few changelog. Adding below.
On 03/01/25 15:42, Beleswar Padhi wrote:
> This series refactors a lot of functions & callbacks from ti_k3_dsp_remoteproc.c
> and ti_k3_m4_remoteproc.c drivers. This is the third and final series as part of
> the refactoring of K3 remoteproc drivers. The patches for internal refactoring
> and bug fixes of TI K3 R5 remoteproc driver has been already posted[0][1]. Since
> the R5 driver has worked out separate data structures and reset logic than the
> DSP/M4 drivers, I have excluded R5 from this refactoring.
>
> NOTE:
> This series is _dependent_ upon the [PATCH 2/3] of below series:
> https://lore.kernel.org/all/20241224091457.1050233-3-b-padhi@ti.com/
>
> Testing Done:
> 1. Tested boot of C66x DSPs, C71x DSPs across Jacinto J7* devices in Remoteproc
> mode and IPC-Only mode.
> 2. Tested boot of M4F core _only_ in _AM62xx SK_ board in Remoteproc mode and
> IPC-Only mode.
> 3. Tested Core stop and detach operations from sysfs for C66x DSPs, C71x DSPs
> and M4F.
> 4. Tested device removal paths by executing 'modprobe -r ti_k3_dsp_remoteproc'
> and 'modprobe -r ti_k3_m4_remoteproc'.
> 5. Tested usecases where firmware not available at device probe time, but later
> in sysfs, able to load firmware into a remotecore and start it. [C66x, C71x, M4]
> 6. Tested that each patch in this series generates no new warnings/errors.
>
> v8: Changelog:
> 1. Broken down refactoring into patches, each patch dealing with one function
> for ease in review. [Andrew]
2. Introduced checks to prevent mailbox IPC with detached M4 core.
3. Refined reset/release from reset logic for DSP cores that do not have
a local reset in PATCH #6 and PATCH #7 of this series.
4. Refactored additional .start()/.stop()/.attach()/.detach()/mbox
.rx_callback()/request_mbox() functions in this series.
Thanks,
Beleswar
>
> Links to older versions:
> v7: https://lore.kernel.org/all/20240202175538.1705-1-hnagalla@ti.com/
> v6: https://lore.kernel.org/all/20230913111644.29889-1-hnagalla@ti.com/
> v5: https://lore.kernel.org/all/20230808044529.25925-1-hnagalla@ti.com/
> v4: https://lore.kernel.org/all/20230801141117.2559-1-hnagalla@ti.com/
> v3: https://lore.kernel.org/all/20230302171450.1598576-1-martyn.welch@collabora.com/
> v2: https://lore.kernel.org/all/20230301111323.1532479-4-martyn.welch@collabora.com/
> v1: https://lore.kernel.org/all/20220110040650.18186-1-hnagalla@ti.com/
>
> Thanks,
> Beleswar
>
> [0]: https://lore.kernel.org/all/20241219110545.1898883-1-b-padhi@ti.com/
> [1]: https://lore.kernel.org/all/20241224091457.1050233-1-b-padhi@ti.com/
>
> Beleswar Padhi (20):
> remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
> remoteproc: k3: Refactor shared data structures
> remoteproc: k3: Refactor mailbox rx_callback functions into common
> driver
> remoteproc: k3: Refactor .kick rproc ops into common driver
> remoteproc: k3-m4: Use k3_rproc_mem_data structure for memory info
> remoteproc: k3: Refactor rproc_reset() implementation into common
> driver
> remoteproc: k3: Refactor rproc_release() implementation into common
> driver
> remoteproc: k3: Refactor rproc_request_mbox() implementations into
> common driver
> remoteproc: k3: Refactor .prepare rproc ops into common driver
> remoteproc: k3: Refactor .unprepare rproc ops into common driver
> remoteproc: k3: Refactor .start rproc ops into common driver
> remoteproc: k3: Refactor .stop rproc ops into common driver
> remoteproc: k3: Refactor .attach rproc ops into common driver
> remoteproc: k3: Refactor .detach rproc ops into common driver
> remoteproc: k3: Refactor .get_loaded_rsc_table ops into common driver
> remoteproc: k3: Refactor .da_to_va rproc ops into common driver
> remoteproc: k3: Refactor of_get_memories() functions into common
> driver
> remoteproc: k3: Refactor mem_release() functions into common driver
> remoteproc: k3: Refactor reserved_mem_init() functions into common
> driver
> remoteproc: k3: Refactor release_tsp() functions into common driver
>
> drivers/remoteproc/Makefile | 4 +-
> drivers/remoteproc/ti_k3_common.c | 586 ++++++++++++++++++++
> drivers/remoteproc/ti_k3_common.h | 113 ++++
> drivers/remoteproc/ti_k3_dsp_remoteproc.c | 643 +---------------------
> drivers/remoteproc/ti_k3_m4_remoteproc.c | 583 ++------------------
> 5 files changed, 765 insertions(+), 1164 deletions(-)
> create mode 100644 drivers/remoteproc/ti_k3_common.c
> create mode 100644 drivers/remoteproc/ti_k3_common.h
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers
2025-01-03 10:12 [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Padhi
` (20 preceding siblings ...)
2025-01-03 10:50 ` [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers Beleswar Prasad Padhi
@ 2025-01-08 15:03 ` Andrew Davis
2025-01-10 14:56 ` Beleswar Prasad Padhi
21 siblings, 1 reply; 25+ messages in thread
From: Andrew Davis @ 2025-01-08 15:03 UTC (permalink / raw)
To: Beleswar Padhi, andersson, mathieu.poirier
Cc: hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, linux-remoteproc, linux-kernel
On 1/3/25 4:12 AM, Beleswar Padhi wrote:
> This series refactors a lot of functions & callbacks from ti_k3_dsp_remoteproc.c
> and ti_k3_m4_remoteproc.c drivers. This is the third and final series as part of
> the refactoring of K3 remoteproc drivers. The patches for internal refactoring
> and bug fixes of TI K3 R5 remoteproc driver has been already posted[0][1]. Since
> the R5 driver has worked out separate data structures and reset logic than the
> DSP/M4 drivers, I have excluded R5 from this refactoring.
>
Diffstat looks great, 765 (+), 1164 (-), good to see all that duplicated code
factored away. But R5 is the largest of the 3 drivers and really needs it the
most.
Looking at the data structure in R5 preventing this I see what should be
the normal "struct k3_rproc" structure is really split into two,
"struct k3_r5_rproc" and "struct k3_r5_core". The first containing a single
instance of the latter. There is no reason for this split I can see, just
combine the two structs.
Next, there are some members of the struct that we don't need, such as
atcm_enable and the others that are only used in probe (or functions
called as part of probe). We only use these as a way to collect this
info in one function, and use in a later one. Instead you could either
fetch this info at the time of use. Or move these members into the
cluster level "struct k3_r5_cluster".
Speaking of "struct k3_r5_cluster", it is silly for cluster to keep a list
of cores. There are two, and will only ever be two. No clue why a list was
chosen as the data structure to hold two pointers, switch this two an array
of size two, or even just two pointers. This also cleans up a bunch of the
weird "list_for_each" logic and loops that have to then check if they have
found with core0 or core1. Instead, just directly access core0 or core1.
That gets rid of member "struct list_head" from the combined struct,
and would you look at that, the struct now matches DSP/M4 :)
I'd suggest doing the above fixups to R5 first, then you can do
this series here after that and include R5.
Thanks,
Andrew
> NOTE:
> This series is _dependent_ upon the [PATCH 2/3] of below series:
> https://lore.kernel.org/all/20241224091457.1050233-3-b-padhi@ti.com/
>
> Testing Done:
> 1. Tested boot of C66x DSPs, C71x DSPs across Jacinto J7* devices in Remoteproc
> mode and IPC-Only mode.
> 2. Tested boot of M4F core _only_ in _AM62xx SK_ board in Remoteproc mode and
> IPC-Only mode.
> 3. Tested Core stop and detach operations from sysfs for C66x DSPs, C71x DSPs
> and M4F.
> 4. Tested device removal paths by executing 'modprobe -r ti_k3_dsp_remoteproc'
> and 'modprobe -r ti_k3_m4_remoteproc'.
> 5. Tested usecases where firmware not available at device probe time, but later
> in sysfs, able to load firmware into a remotecore and start it. [C66x, C71x, M4]
> 6. Tested that each patch in this series generates no new warnings/errors.
>
> v8: Changelog:
> 1. Broken down refactoring into patches, each patch dealing with one function
> for ease in review. [Andrew]
>
> Links to older versions:
> v7: https://lore.kernel.org/all/20240202175538.1705-1-hnagalla@ti.com/
> v6: https://lore.kernel.org/all/20230913111644.29889-1-hnagalla@ti.com/
> v5: https://lore.kernel.org/all/20230808044529.25925-1-hnagalla@ti.com/
> v4: https://lore.kernel.org/all/20230801141117.2559-1-hnagalla@ti.com/
> v3: https://lore.kernel.org/all/20230302171450.1598576-1-martyn.welch@collabora.com/
> v2: https://lore.kernel.org/all/20230301111323.1532479-4-martyn.welch@collabora.com/
> v1: https://lore.kernel.org/all/20220110040650.18186-1-hnagalla@ti.com/
>
> Thanks,
> Beleswar
>
> [0]: https://lore.kernel.org/all/20241219110545.1898883-1-b-padhi@ti.com/
> [1]: https://lore.kernel.org/all/20241224091457.1050233-1-b-padhi@ti.com/
>
> Beleswar Padhi (20):
> remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
> remoteproc: k3: Refactor shared data structures
> remoteproc: k3: Refactor mailbox rx_callback functions into common
> driver
> remoteproc: k3: Refactor .kick rproc ops into common driver
> remoteproc: k3-m4: Use k3_rproc_mem_data structure for memory info
> remoteproc: k3: Refactor rproc_reset() implementation into common
> driver
> remoteproc: k3: Refactor rproc_release() implementation into common
> driver
> remoteproc: k3: Refactor rproc_request_mbox() implementations into
> common driver
> remoteproc: k3: Refactor .prepare rproc ops into common driver
> remoteproc: k3: Refactor .unprepare rproc ops into common driver
> remoteproc: k3: Refactor .start rproc ops into common driver
> remoteproc: k3: Refactor .stop rproc ops into common driver
> remoteproc: k3: Refactor .attach rproc ops into common driver
> remoteproc: k3: Refactor .detach rproc ops into common driver
> remoteproc: k3: Refactor .get_loaded_rsc_table ops into common driver
> remoteproc: k3: Refactor .da_to_va rproc ops into common driver
> remoteproc: k3: Refactor of_get_memories() functions into common
> driver
> remoteproc: k3: Refactor mem_release() functions into common driver
> remoteproc: k3: Refactor reserved_mem_init() functions into common
> driver
> remoteproc: k3: Refactor release_tsp() functions into common driver
>
> drivers/remoteproc/Makefile | 4 +-
> drivers/remoteproc/ti_k3_common.c | 586 ++++++++++++++++++++
> drivers/remoteproc/ti_k3_common.h | 113 ++++
> drivers/remoteproc/ti_k3_dsp_remoteproc.c | 643 +---------------------
> drivers/remoteproc/ti_k3_m4_remoteproc.c | 583 ++------------------
> 5 files changed, 765 insertions(+), 1164 deletions(-)
> create mode 100644 drivers/remoteproc/ti_k3_common.c
> create mode 100644 drivers/remoteproc/ti_k3_common.h
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v8 00/20] Refactor TI K3 DSP and M4 Drivers
2025-01-08 15:03 ` Andrew Davis
@ 2025-01-10 14:56 ` Beleswar Prasad Padhi
0 siblings, 0 replies; 25+ messages in thread
From: Beleswar Prasad Padhi @ 2025-01-10 14:56 UTC (permalink / raw)
To: Andrew Davis, andersson, mathieu.poirier
Cc: hnagalla, u-kumar1, p.zabel, jan.kiszka, christophe.jaillet,
jkangas, eballetbo, linux-remoteproc, linux-kernel
Hi Andrew,
On 08/01/25 20:33, Andrew Davis wrote:
> On 1/3/25 4:12 AM, Beleswar Padhi wrote:
>> This series refactors a lot of functions & callbacks from
>> ti_k3_dsp_remoteproc.c
>> and ti_k3_m4_remoteproc.c drivers. This is the third and final series
>> as part of
>> the refactoring of K3 remoteproc drivers. The patches for internal
>> refactoring
>> and bug fixes of TI K3 R5 remoteproc driver has been already
>> posted[0][1]. Since
>> the R5 driver has worked out separate data structures and reset logic
>> than the
>> DSP/M4 drivers, I have excluded R5 from this refactoring.
>>
>
> Diffstat looks great, 765 (+), 1164 (-), good to see all that
> duplicated code
> factored away. But R5 is the largest of the 3 drivers and really needs
> it the
> most.
>
> Looking at the data structure in R5 preventing this I see what should be
> the normal "struct k3_rproc" structure is really split into two,
> "struct k3_r5_rproc" and "struct k3_r5_core". The first containing a
> single
> instance of the latter. There is no reason for this split I can see, just
> combine the two structs.
>
> Next, there are some members of the struct that we don't need, such as
> atcm_enable and the others that are only used in probe (or functions
> called as part of probe). We only use these as a way to collect this
> info in one function, and use in a later one. Instead you could either
> fetch this info at the time of use. Or move these members into the
> cluster level "struct k3_r5_cluster".
>
> Speaking of "struct k3_r5_cluster", it is silly for cluster to keep a
> list
> of cores. There are two, and will only ever be two. No clue why a list
> was
> chosen as the data structure to hold two pointers, switch this two an
> array
> of size two, or even just two pointers. This also cleans up a bunch of
> the
> weird "list_for_each" logic and loops that have to then check if they
> have
> found with core0 or core1. Instead, just directly access core0 or core1.
>
> That gets rid of member "struct list_head" from the combined struct,
> and would you look at that, the struct now matches DSP/M4 :)
>
> I'd suggest doing the above fixups to R5 first, then you can do
> this series here after that and include R5.
Thanks a lot for suggesting this detailed plan! I agree with your
assessment, and I will post a series addressing this.
Thanks,
Beleswar
>
> Thanks,
> Andrew
>
>> NOTE:
>> This series is _dependent_ upon the [PATCH 2/3] of below series:
>> https://lore.kernel.org/all/20241224091457.1050233-3-b-padhi@ti.com/
>>
>> Testing Done:
>> 1. Tested boot of C66x DSPs, C71x DSPs across Jacinto J7* devices in
>> Remoteproc
>> mode and IPC-Only mode.
>> 2. Tested boot of M4F core _only_ in _AM62xx SK_ board in Remoteproc
>> mode and
>> IPC-Only mode.
>> 3. Tested Core stop and detach operations from sysfs for C66x DSPs,
>> C71x DSPs
>> and M4F.
>> 4. Tested device removal paths by executing 'modprobe -r
>> ti_k3_dsp_remoteproc'
>> and 'modprobe -r ti_k3_m4_remoteproc'.
>> 5. Tested usecases where firmware not available at device probe time,
>> but later
>> in sysfs, able to load firmware into a remotecore and start it.
>> [C66x, C71x, M4]
>> 6. Tested that each patch in this series generates no new
>> warnings/errors.
>>
>> v8: Changelog:
>> 1. Broken down refactoring into patches, each patch dealing with one
>> function
>> for ease in review. [Andrew]
>>
>> Links to older versions:
>> v7: https://lore.kernel.org/all/20240202175538.1705-1-hnagalla@ti.com/
>> v6: https://lore.kernel.org/all/20230913111644.29889-1-hnagalla@ti.com/
>> v5: https://lore.kernel.org/all/20230808044529.25925-1-hnagalla@ti.com/
>> v4: https://lore.kernel.org/all/20230801141117.2559-1-hnagalla@ti.com/
>> v3:
>> https://lore.kernel.org/all/20230302171450.1598576-1-martyn.welch@collabora.com/
>> v2:
>> https://lore.kernel.org/all/20230301111323.1532479-4-martyn.welch@collabora.com/
>> v1: https://lore.kernel.org/all/20220110040650.18186-1-hnagalla@ti.com/
>>
>> Thanks,
>> Beleswar
>>
>> [0]:
>> https://lore.kernel.org/all/20241219110545.1898883-1-b-padhi@ti.com/
>> [1]:
>> https://lore.kernel.org/all/20241224091457.1050233-1-b-padhi@ti.com/
>>
>> Beleswar Padhi (20):
>> remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
>> remoteproc: k3: Refactor shared data structures
>> remoteproc: k3: Refactor mailbox rx_callback functions into common
>> driver
>> remoteproc: k3: Refactor .kick rproc ops into common driver
>> remoteproc: k3-m4: Use k3_rproc_mem_data structure for memory info
>> remoteproc: k3: Refactor rproc_reset() implementation into common
>> driver
>> remoteproc: k3: Refactor rproc_release() implementation into common
>> driver
>> remoteproc: k3: Refactor rproc_request_mbox() implementations into
>> common driver
>> remoteproc: k3: Refactor .prepare rproc ops into common driver
>> remoteproc: k3: Refactor .unprepare rproc ops into common driver
>> remoteproc: k3: Refactor .start rproc ops into common driver
>> remoteproc: k3: Refactor .stop rproc ops into common driver
>> remoteproc: k3: Refactor .attach rproc ops into common driver
>> remoteproc: k3: Refactor .detach rproc ops into common driver
>> remoteproc: k3: Refactor .get_loaded_rsc_table ops into common driver
>> remoteproc: k3: Refactor .da_to_va rproc ops into common driver
>> remoteproc: k3: Refactor of_get_memories() functions into common
>> driver
>> remoteproc: k3: Refactor mem_release() functions into common driver
>> remoteproc: k3: Refactor reserved_mem_init() functions into common
>> driver
>> remoteproc: k3: Refactor release_tsp() functions into common driver
>>
>> drivers/remoteproc/Makefile | 4 +-
>> drivers/remoteproc/ti_k3_common.c | 586 ++++++++++++++++++++
>> drivers/remoteproc/ti_k3_common.h | 113 ++++
>> drivers/remoteproc/ti_k3_dsp_remoteproc.c | 643 +---------------------
>> drivers/remoteproc/ti_k3_m4_remoteproc.c | 583 ++------------------
>> 5 files changed, 765 insertions(+), 1164 deletions(-)
>> create mode 100644 drivers/remoteproc/ti_k3_common.c
>> create mode 100644 drivers/remoteproc/ti_k3_common.h
>>
^ permalink raw reply [flat|nested] 25+ messages in thread