On Thu, Nov 28, 2024 at 09:42:10AM +0100, Arnaud Pouliquen wrote:
> This patch updates the rproc_ops structures to include two new optional
> operations.
> 
> - The load_fw() op is responsible for loading the remote processor
> non-ELF firmware image before starting the boot sequence. This ops will
> be used, for instance, to call OP-TEE to  authenticate an load the firmware

1) two space between "to" and "authenticate"
2) s/"an load"/"and load"

> image before accessing to its resources (a.e the resource table)
> 
> - The release_fw op is responsible for releasing the remote processor
> firmware image. For instance to clean memories.
> The ops is called in the following cases:
>  - An error occurs between the loading of the firmware image and the
>    start of the remote processor.
>  - after stopping the remote processor.
> 
> Signed-off-by: Arnaud Pouliquen <arnaud.pouliq...@foss.st.com>
> ---
> Update vs version V13:
> - Rework the commit to introduce load_fw() op.
> - remove rproc_release_fw() call from  rproc_start() as called in
>   rproc_boot() and rproc_boot_recovery() in case of error.
> - create rproc_load_fw() and rproc_release_fw() internal functions.
> ---
>  drivers/remoteproc/remoteproc_core.c     | 16 +++++++++++++++-
>  drivers/remoteproc/remoteproc_internal.h | 14 ++++++++++++++
>  include/linux/remoteproc.h               |  6 ++++++
>  3 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c 
> b/drivers/remoteproc/remoteproc_core.c
> index ace11ea17097..8df4b2c59bb6 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1488,6 +1488,7 @@ static int rproc_fw_boot(struct rproc *rproc, const 
> struct firmware *fw)
>       kfree(rproc->cached_table);
>       rproc->cached_table = NULL;
>       rproc->table_ptr = NULL;
> +     rproc_release_fw(rproc);
>  unprepare_rproc:
>       /* release HW resources if needed */
>       rproc_unprepare_device(rproc);
> @@ -1855,8 +1856,14 @@ static int rproc_boot_recovery(struct rproc *rproc)
>               return ret;
>       }
>  
> +     ret = rproc_load_fw(rproc, firmware_p);
> +     if (ret)
> +             return ret;
> +
>       /* boot the remote processor up again */
>       ret = rproc_start(rproc, firmware_p);
> +     if (ret)
> +             rproc_release_fw(rproc);
>  
>       release_firmware(firmware_p);
>  
> @@ -1997,7 +2004,13 @@ int rproc_boot(struct rproc *rproc)
>                       goto downref_rproc;
>               }
>  
> +             ret = rproc_load_fw(rproc, firmware_p);
> +             if (ret)
> +                     goto downref_rproc;
> +
>               ret = rproc_fw_boot(rproc, firmware_p);
> +             if (ret)
> +                     rproc_release_fw(rproc);
>  
>               release_firmware(firmware_p);
>       }
> @@ -2071,6 +2084,7 @@ int rproc_shutdown(struct rproc *rproc)
>       kfree(rproc->cached_table);
>       rproc->cached_table = NULL;
>       rproc->table_ptr = NULL;
> +     rproc_release_fw(rproc);
>  out:
>       mutex_unlock(&rproc->lock);
>       return ret;
> @@ -2471,7 +2485,7 @@ static int rproc_alloc_ops(struct rproc *rproc, const 
> struct rproc_ops *ops)
>       if (!rproc->ops->coredump)
>               rproc->ops->coredump = rproc_coredump;
>  
> -     if (rproc->ops->load)
> +     if (rproc->ops->load || rproc->ops->load_fw)
>               return 0;
>  
>       /* Default to ELF loader if no load function is specified */
> diff --git a/drivers/remoteproc/remoteproc_internal.h 
> b/drivers/remoteproc/remoteproc_internal.h
> index 0cd09e67ac14..2104ca449178 100644
> --- a/drivers/remoteproc/remoteproc_internal.h
> +++ b/drivers/remoteproc/remoteproc_internal.h
> @@ -221,4 +221,18 @@ bool rproc_u64_fit_in_size_t(u64 val)
>       return (val <= (size_t) -1);
>  }
>  
> +static inline void rproc_release_fw(struct rproc *rproc)
> +{
> +     if (rproc->ops->release_fw)
> +             rproc->ops->release_fw(rproc);
> +}
> +
> +static inline int rproc_load_fw(struct rproc *rproc, const struct firmware 
> *fw)
> +{
> +     if (rproc->ops->load_fw)
> +             return rproc->ops->load_fw(rproc, fw);
> +
> +     return 0;
> +}
> +
>  #endif /* REMOTEPROC_INTERNAL_H */
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 2e0ddcb2d792..ba6fd560f7ba 100644
> --- a/include/linux/remoteproc.h
> +++ b/include/linux/remoteproc.h
> @@ -381,6 +381,10 @@ enum rsc_handling_status {
>   * @panic:   optional callback to react to system panic, core will delay
>   *           panic at least the returned number of milliseconds
>   * @coredump:          collect firmware dump after the subsystem is shutdown
> + * @load_fw: optional function to load non-ELF firmware image to memory, 
> where the remote
> + *           processor expects to find it.
> + * @release_fw:      optional function to release the firmware image from 
> memories.
> + *           This function is called after stopping the remote processor or 
> in case of error
>   */
>  struct rproc_ops {
>       int (*prepare)(struct rproc *rproc);
> @@ -403,6 +407,8 @@ struct rproc_ops {
>       u64 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw);
>       unsigned long (*panic)(struct rproc *rproc);
>       void (*coredump)(struct rproc *rproc);
> +     int (*load_fw)(struct rproc *rproc, const struct firmware *fw);
> +     void (*release_fw)(struct rproc *rproc);
>  };
>  
>  /**
> -- 
> 2.25.1
> 

Reply via email to