On Tue, May 21, 2024 at 10:09:58AM +0200, Arnaud Pouliquen wrote:
> Split rproc_start()to prepare the update of the management of

I don't see any "splitting" for rproc_start() in this patch.  Please consider
rewording or removing.

> the cache table on start, for the support of the firmware loading
> by the TEE interface.
> - create rproc_set_rsc_table_on_start() to address the management of
>   the cache table in a specific function, as done in
>   rproc_reset_rsc_table_on_stop().
> - rename rproc_set_rsc_table in rproc_set_rsc_table_on_attach()
> - move rproc_reset_rsc_table_on_stop() to be close to the
>   rproc_set_rsc_table_on_start() function

This patch is really hard to read due to all 3 operations happening at the same
time.  Please split in 3 smaller patches.

> 
> Suggested-by: Mathieu Poirier <mathieu.poir...@linaro.org>
> Signed-off-by: Arnaud Pouliquen <arnaud.pouliq...@foss.st.com>
> ---
>  drivers/remoteproc/remoteproc_core.c | 116 ++++++++++++++-------------
>  1 file changed, 62 insertions(+), 54 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c 
> b/drivers/remoteproc/remoteproc_core.c
> index f276956f2c5c..42bca01f3bde 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1264,18 +1264,9 @@ void rproc_resource_cleanup(struct rproc *rproc)
>  }
>  EXPORT_SYMBOL(rproc_resource_cleanup);
>  
> -static int rproc_start(struct rproc *rproc, const struct firmware *fw)
> +static int rproc_set_rsc_table_on_start(struct rproc *rproc, const struct 
> firmware *fw)
>  {
>       struct resource_table *loaded_table;
> -     struct device *dev = &rproc->dev;
> -     int ret;
> -
> -     /* load the ELF segments to memory */
> -     ret = rproc_load_segments(rproc, fw);
> -     if (ret) {
> -             dev_err(dev, "Failed to load program segments: %d\n", ret);
> -             return ret;
> -     }
>  
>       /*
>        * The starting device has been given the rproc->cached_table as the
> @@ -1291,6 +1282,64 @@ static int rproc_start(struct rproc *rproc, const 
> struct firmware *fw)
>               rproc->table_ptr = loaded_table;
>       }
>  
> +     return 0;
> +}
> +
> +static int rproc_reset_rsc_table_on_stop(struct rproc *rproc)
> +{
> +     /* A resource table was never retrieved, nothing to do here */
> +     if (!rproc->table_ptr)
> +             return 0;
> +
> +     /*
> +      * If a cache table exists the remote processor was started by
> +      * the remoteproc core.  That cache table should be used for
> +      * the rest of the shutdown process.
> +      */
> +     if (rproc->cached_table)
> +             goto out;
> +
> +     /*
> +      * If we made it here the remote processor was started by another
> +      * entity and a cache table doesn't exist.  As such make a copy of
> +      * the resource table currently used by the remote processor and
> +      * use that for the rest of the shutdown process.  The memory
> +      * allocated here is free'd in rproc_shutdown().
> +      */
> +     rproc->cached_table = kmemdup(rproc->table_ptr,
> +                                   rproc->table_sz, GFP_KERNEL);
> +     if (!rproc->cached_table)
> +             return -ENOMEM;
> +
> +     /*
> +      * Since the remote processor is being switched off the clean table
> +      * won't be needed.  Allocated in rproc_set_rsc_table_on_start().
> +      */
> +     kfree(rproc->clean_table);
> +
> +out:
> +     /*
> +      * Use a copy of the resource table for the remainder of the
> +      * shutdown process.
> +      */
> +     rproc->table_ptr = rproc->cached_table;
> +     return 0;
> +}
> +
> +static int rproc_start(struct rproc *rproc, const struct firmware *fw)
> +{
> +     struct device *dev = &rproc->dev;
> +     int ret;
> +
> +     /* load the ELF segments to memory */
> +     ret = rproc_load_segments(rproc, fw);
> +     if (ret) {
> +             dev_err(dev, "Failed to load program segments: %d\n", ret);
> +             return ret;
> +     }
> +
> +     rproc_set_rsc_table_on_start(rproc, fw);
> +
>       ret = rproc_prepare_subdevices(rproc);
>       if (ret) {
>               dev_err(dev, "failed to prepare subdevices for %s: %d\n",
> @@ -1450,7 +1499,7 @@ static int rproc_fw_boot(struct rproc *rproc, const 
> struct firmware *fw)
>       return ret;
>  }
>  
> -static int rproc_set_rsc_table(struct rproc *rproc)
> +static int rproc_set_rsc_table_on_attach(struct rproc *rproc)
>  {
>       struct resource_table *table_ptr;
>       struct device *dev = &rproc->dev;
> @@ -1540,54 +1589,13 @@ static int rproc_reset_rsc_table_on_detach(struct 
> rproc *rproc)
>  
>       /*
>        * The clean resource table is no longer needed.  Allocated in
> -      * rproc_set_rsc_table().
> +      * rproc_set_rsc_table_on_attach().
>        */
>       kfree(rproc->clean_table);
>  
>       return 0;
>  }
>  
> -static int rproc_reset_rsc_table_on_stop(struct rproc *rproc)
> -{
> -     /* A resource table was never retrieved, nothing to do here */
> -     if (!rproc->table_ptr)
> -             return 0;
> -
> -     /*
> -      * If a cache table exists the remote processor was started by
> -      * the remoteproc core.  That cache table should be used for
> -      * the rest of the shutdown process.
> -      */
> -     if (rproc->cached_table)
> -             goto out;
> -
> -     /*
> -      * If we made it here the remote processor was started by another
> -      * entity and a cache table doesn't exist.  As such make a copy of
> -      * the resource table currently used by the remote processor and
> -      * use that for the rest of the shutdown process.  The memory
> -      * allocated here is free'd in rproc_shutdown().
> -      */
> -     rproc->cached_table = kmemdup(rproc->table_ptr,
> -                                   rproc->table_sz, GFP_KERNEL);
> -     if (!rproc->cached_table)
> -             return -ENOMEM;
> -
> -     /*
> -      * Since the remote processor is being switched off the clean table
> -      * won't be needed.  Allocated in rproc_set_rsc_table().
> -      */
> -     kfree(rproc->clean_table);
> -
> -out:
> -     /*
> -      * Use a copy of the resource table for the remainder of the
> -      * shutdown process.
> -      */
> -     rproc->table_ptr = rproc->cached_table;
> -     return 0;
> -}
> -
>  /*
>   * Attach to remote processor - similar to rproc_fw_boot() but without
>   * the steps that deal with the firmware image.
> @@ -1614,7 +1622,7 @@ static int rproc_attach(struct rproc *rproc)
>               goto disable_iommu;
>       }
>  
> -     ret = rproc_set_rsc_table(rproc);
> +     ret = rproc_set_rsc_table_on_attach(rproc);
>       if (ret) {
>               dev_err(dev, "can't load resource table: %d\n", ret);
>               goto unprepare_device;
> -- 
> 2.25.1
> 

Reply via email to