Refactor TI K3 DSP and M4 Drivers
v8 cover Refactor TI K3 DSP and M4 Drivers
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/[email protected]/
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/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Thanks,
Beleswar
[0]: https://lore.kernel.org/all/[email protected]/
[1]: https://lore.kernel.org/all/[email protected]/
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
Signature · 1 line
2.34.1
PATCH v8 1/20 remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
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.
--- drivers/remoteproc/ti_k3_m4_remoteproc.c | 41 ++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-)
drivers/remoteproc/ti_k3_m4_remoteproc.c +35 -6
@@ -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);
Signature · 1 line
2.34.1
Re: [PATCH v8 01/20] remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
Quoted 31 lines · Beleswar Padhi
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()andk3_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 <[email protected]>--- drivers/remoteproc/ti_k3_m4_remoteproc.c | 41 ++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-)drivers/remoteproc/ti_k3_m4_remoteproc.c +1
-0@@ -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
drivers/remoteproc/ti_k3_m4_remoteproc.c struct k3_m4_rproc_mem_data { · line 64
Quoted 4 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c +1
-0@@ -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
Quoted 98 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c +33
-6*/ 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);
PATCH v8 2/20 remoteproc: k3: Refactor shared data structures
In reply to Beleswar PadhiThe 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.
--- 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
drivers/remoteproc/ti_k3_common.h new file +91 -0
@@ -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 <[email protected]> +* +* ti_k3_m4_remoteproc.c: +* Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/ +* Hari Nagalla <[email protected]> +*/ + +#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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +26 -98
267 lines not on this page · raw message
drivers/remoteproc/ti_k3_m4_remoteproc.c +15 -70
179 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 3/20 remoteproc: k3: Refactor mailbox rx_callback functions into common driver
In reply to Beleswar PadhiThe 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.
--- 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
drivers/remoteproc/Makefile +2 -2
@@ -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
drivers/remoteproc/ti_k3_common.c new file +90 -0
90 lines not on this page · raw message
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -56
69 lines not on this page · raw message
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -56
69 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 4/20 remoteproc: k3: Refactor .kick rproc ops into common driver
In reply to Beleswar PadhiThe .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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +31 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +2 -29
@@ -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, boolstatic 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, };
drivers/remoteproc/ti_k3_m4_remoteproc.c +2 -32
@@ -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, };
Signature · 1 line
2.34.1
PATCH v8 5/20 remoteproc: k3-m4: Use k3_rproc_mem_data structure for memory info
In reply to Beleswar PadhiThe 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.
--- drivers/remoteproc/ti_k3_m4_remoteproc.c | 40 ++++++++++++++++-------- 1 file changed, 27 insertions(+), 13 deletions(-)
drivers/remoteproc/ti_k3_m4_remoteproc.c +27 -13
@@ -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, boolstatic 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);
Signature · 1 line
2.34.1
PATCH v8 6/20 remoteproc: k3: Refactor rproc_reset() implementation into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +25 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +2 -28
@@ -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); } } }
drivers/remoteproc/ti_k3_m4_remoteproc.c +3 -13
@@ -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); }/*
Signature · 1 line
2.34.1
PATCH v8 7/20 remoteproc: k3: Refactor rproc_release() implementation into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +27 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -29
@@ -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;
drivers/remoteproc/ti_k3_m4_remoteproc.c +3 -5
@@ -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; }/*
Signature · 1 line
2.34.1
PATCH v8 8/20 remoteproc: k3: Refactor rproc_request_mbox() implementations into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +36 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -35
@@ -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;
drivers/remoteproc/ti_k3_m4_remoteproc.c +3 -39
69 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 9/20 remoteproc: k3: Refactor .prepare rproc ops into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +46 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -41
66 lines not on this page · raw message
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -44
57 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 10/20 remoteproc: k3: Refactor .unprepare rproc ops into common driver
In reply to Beleswar PadhiThe .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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +30 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -25
@@ -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;
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -30
@@ -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,
Signature · 1 line
2.34.1
PATCH v8 11/20 remoteproc: k3: Refactor .start rproc ops into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +15 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +2 -2
@@ -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;
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -21
@@ -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,
Signature · 1 line
2.34.1
PATCH v8 12/20 remoteproc: k3: Refactor .stop rproc ops into common driver
In reply to Beleswar PadhiThe .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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +14 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -17
@@ -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, boolstatic 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;
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -14
@@ -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,
Signature · 1 line
2.34.1
PATCH v8 13/20 remoteproc: k3: Refactor .attach rproc ops into common driver
In reply to Beleswar PadhiThe .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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +20 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -20
@@ -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, boolstatic 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 {
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -19
@@ -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,
Signature · 1 line
2.34.1
PATCH v8 14/20 remoteproc: k3: Refactor .detach rproc ops into common driver
In reply to Beleswar PadhiThe .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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +19 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -19
@@ -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" );
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -19
@@ -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,
Signature · 1 line
2.34.1
PATCH v8 15/20 remoteproc: k3: Refactor .get_loaded_rsc_table ops into common driver
In reply to Beleswar PadhiThe .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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +33 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +2 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +8 -41
70 lines not on this page · raw message
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -33
@@ -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)
Signature · 1 line
2.34.1
PATCH v8 16/20 remoteproc: k3: Refactor .da_to_va rproc ops into common driver
In reply to Beleswar PadhiThe .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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +61 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +4 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -62
81 lines not on this page · raw message
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -57
70 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 17/20 remoteproc: k3: Refactor of_get_memories() functions into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +53 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +2 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -53
66 lines not on this page · raw message
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -53
66 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 18/20 remoteproc: k3: Refactor mem_release() functions into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +8 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -8
@@ -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;
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -8
@@ -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;
Signature · 1 line
2.34.1
PATCH v8 19/20 remoteproc: k3: Refactor reserved_mem_init() functions into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +70 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -71
84 lines not on this page · raw message
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -70
83 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 20/20 remoteproc: k3: Refactor release_tsp() functions into common driver
In reply to Beleswar PadhiThe 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.
--- 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(-)
drivers/remoteproc/ti_k3_common.c +8 -0
@@ -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" );
drivers/remoteproc/ti_k3_common.h +1 -0
@@ -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 */
drivers/remoteproc/ti_k3_dsp_remoteproc.c +1 -8
@@ -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;
drivers/remoteproc/ti_k3_m4_remoteproc.c +1 -8
@@ -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;
Signature · 1 line
2.34.1
Missed few changelog. Adding below.
Quoted 24 lines · Beleswar Padhi
This series refactors a lot of functions & callbacks from
ti_k3_dsp_remoteproc.candti_k3_m4_remoteproc.cdrivers. 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/[email protected]/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_AM62xxSK_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 -rti_k3_dsp_remoteproc' and 'modprobe -rti_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.
Quoted 3 lines
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
Quoted 53 lines
Links to older versions:
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/Thanks,
Beleswar[0]: https://lore.kernel.org/all/[email protected]/
[1]: https://lore.kernel.org/all/[email protected]/Beleswar Padhi (20):
remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
remoteproc: k3: Refactor shared data structures
remoteproc: k3: Refactor mailboxrx_callbackfunctions into common
driver
remoteproc: k3: Refactor .kick rproc ops into common driver
remoteproc: k3-m4: Usek3_rproc_mem_datastructure for memory info
remoteproc: k3: Refactorrproc_reset()implementation into common
driver
remoteproc: k3: Refactorrproc_release()implementation into common
driver
remoteproc: k3: Refactorrproc_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: Refactorof_get_memories()functions into common
driver
remoteproc: k3: Refactormem_release()functions into common driver
remoteproc: k3: Refactorreserved_mem_init()functions into common
driver
remoteproc: k3: Refactorrelease_tsp()functions into common driverdrivers/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.ccreate mode 100644drivers/remoteproc/ti_k3_common.h
Quoted 7 lines · Beleswar Padhi
This series refactors a lot of functions & callbacks from
ti_k3_dsp_remoteproc.candti_k3_m4_remoteproc.cdrivers. 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
Quoted 73 lines
NOTE:
This series is _dependent_ upon the [PATCH 2/3] of below series:
https://lore.kernel.org/all/[email protected]/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_AM62xxSK_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 -rti_k3_dsp_remoteproc' and 'modprobe -rti_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/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/Thanks,
Beleswar[0]: https://lore.kernel.org/all/[email protected]/
[1]: https://lore.kernel.org/all/[email protected]/Beleswar Padhi (20):
remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
remoteproc: k3: Refactor shared data structures
remoteproc: k3: Refactor mailboxrx_callbackfunctions into common
driver
remoteproc: k3: Refactor .kick rproc ops into common driver
remoteproc: k3-m4: Usek3_rproc_mem_datastructure for memory info
remoteproc: k3: Refactorrproc_reset()implementation into common
driver
remoteproc: k3: Refactorrproc_release()implementation into common
driver
remoteproc: k3: Refactorrproc_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: Refactorof_get_memories()functions into common
driver
remoteproc: k3: Refactormem_release()functions into common driver
remoteproc: k3: Refactorreserved_mem_init()functions into common
driver
remoteproc: k3: Refactorrelease_tsp()functions into common driverdrivers/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.ccreate mode 100644drivers/remoteproc/ti_k3_common.h
Hi Andrew,
Quoted 33 lines · Andrew Davis
Quoted 7 lines · Beleswar Padhi
This series refactors a lot of functions & callbacks from
ti_k3_dsp_remoteproc.candti_k3_m4_remoteproc.cdrivers. 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 "structk3_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_enableand 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 "structk3_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.
Quoted 5 lines
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
Quoted 77 lines
Thanks,
AndrewQuoted 73 lines
NOTE:
This series is _dependent_ upon the [PATCH 2/3] of below series:
https://lore.kernel.org/all/[email protected]/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_AM62xxSK_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 -rti_k3_dsp_remoteproc' and 'modprobe -rti_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/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/Thanks,
Beleswar[0]: https://lore.kernel.org/all/[email protected]/
[1]: https://lore.kernel.org/all/[email protected]/Beleswar Padhi (20):
remoteproc: k3-m4: Prevent Mailbox level IPC with detached core
remoteproc: k3: Refactor shared data structures
remoteproc: k3: Refactor mailboxrx_callbackfunctions into common driver
remoteproc: k3: Refactor .kick rproc ops into common driver
remoteproc: k3-m4: Usek3_rproc_mem_datastructure for memory info
remoteproc: k3: Refactorrproc_reset()implementation into common driver
remoteproc: k3: Refactorrproc_release()implementation into common driver
remoteproc: k3: Refactorrproc_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: Refactorof_get_memories()functions into common driver
remoteproc: k3: Refactormem_release()functions into common driver
remoteproc: k3: Refactorreserved_mem_init()functions into common driver
remoteproc: k3: Refactorrelease_tsp()functions into common driverdrivers/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.ccreate mode 100644drivers/remoteproc/ti_k3_common.h