linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] rproc core patches needed for TI K3 drivers
@ 2020-04-17  0:20 Suman Anna
  2020-04-17  0:20 ` [PATCH 1/2] remoteproc: Add prepare and unprepare ops Suman Anna
  2020-04-17  0:20 ` [PATCH 2/2] remoteproc: Use a local copy for the name field Suman Anna
  0 siblings, 2 replies; 8+ messages in thread
From: Suman Anna @ 2020-04-17  0:20 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-arm-kernel, linux-kernel, Suman Anna

Hi Bjorn, Mathieu,

The following 2 patches were a revised version and split out from the
TI K3 R5F remoteproc support patch series [1]. The patches do use the
cleanup logic from  Mathieu's "remoteproc: Refactor function rproc_alloc()"
series. The patches address both of your comments.

Delta changes in individual patches.

regards
Suman

[1] https://patchwork.kernel.org/cover/11456367/
[2] https://patchwork.kernel.org/cover/11492005/

Loic Pallardy (1):
  remoteproc: Add prepare and unprepare ops

Suman Anna (1):
  remoteproc: Use a local copy for the name field

 drivers/remoteproc/remoteproc_core.c     | 21 +++++++++++++++++++--
 drivers/remoteproc/remoteproc_internal.h | 16 ++++++++++++++++
 include/linux/remoteproc.h               |  4 ++++
 3 files changed, 39 insertions(+), 2 deletions(-)

-- 
2.26.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] remoteproc: Add prepare and unprepare ops
  2020-04-17  0:20 [PATCH 0/2] rproc core patches needed for TI K3 drivers Suman Anna
@ 2020-04-17  0:20 ` Suman Anna
  2020-04-21  2:52   ` Bjorn Andersson
  2020-04-17  0:20 ` [PATCH 2/2] remoteproc: Use a local copy for the name field Suman Anna
  1 sibling, 1 reply; 8+ messages in thread
From: Suman Anna @ 2020-04-17  0:20 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-arm-kernel, linux-kernel, Loic Pallardy,
	Suman Anna

From: Loic Pallardy <loic.pallardy@st.com>

On some SoC architecture, it is needed to enable HW like
clock, bus, regulator, memory region... before loading
co-processor firmware.

This patch introduces prepare and unprepare ops to execute
platform specific function before firmware loading and after
stop execution.

Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
Signed-off-by: Suman Anna <s-anna@ti.com>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
v1:
 - Make the direct ops into inline helper functions in line
   with the comments on the MCU sync series (v1 comments).
   No change in functionality.
 - Picked up the Reviewed-by tags
v0: https://patchwork.kernel.org/patch/11456383/

 drivers/remoteproc/remoteproc_core.c     | 15 ++++++++++++++-
 drivers/remoteproc/remoteproc_internal.h | 16 ++++++++++++++++
 include/linux/remoteproc.h               |  4 ++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index d681eeb962b6..e38f627059ac 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1394,12 +1394,19 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
 		return ret;
 	}
 
+	/* Prepare rproc for firmware loading if needed */
+	ret = rproc_prepare_device(rproc);
+	if (ret) {
+		dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret);
+		goto disable_iommu;
+	}
+
 	rproc->bootaddr = rproc_get_boot_addr(rproc, fw);
 
 	/* Load resource table, core dump segment list etc from the firmware */
 	ret = rproc_parse_fw(rproc, fw);
 	if (ret)
-		goto disable_iommu;
+		goto unprepare_rproc;
 
 	/* reset max_notifyid */
 	rproc->max_notifyid = -1;
@@ -1433,6 +1440,9 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
 	kfree(rproc->cached_table);
 	rproc->cached_table = NULL;
 	rproc->table_ptr = NULL;
+unprepare_rproc:
+	/* release HW resources if needed */
+	rproc_unprepare_device(rproc);
 disable_iommu:
 	rproc_disable_iommu(rproc);
 	return ret;
@@ -1838,6 +1848,9 @@ void rproc_shutdown(struct rproc *rproc)
 	/* clean up all acquired resources */
 	rproc_resource_cleanup(rproc);
 
+	/* release HW resources if needed */
+	rproc_unprepare_device(rproc);
+
 	rproc_disable_iommu(rproc);
 
 	/* Free the copy of the resource table */
diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h
index b389dc79da81..101e6be8d240 100644
--- a/drivers/remoteproc/remoteproc_internal.h
+++ b/drivers/remoteproc/remoteproc_internal.h
@@ -64,6 +64,22 @@ struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
 struct rproc_mem_entry *
 rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
 
+static inline int rproc_prepare_device(struct rproc *rproc)
+{
+	if (rproc->ops->prepare)
+		return rproc->ops->prepare(rproc);
+
+	return 0;
+}
+
+static inline int rproc_unprepare_device(struct rproc *rproc)
+{
+	if (rproc->ops->unprepare)
+		return rproc->ops->unprepare(rproc);
+
+	return 0;
+}
+
 static inline
 int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
 {
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 38607107b7cb..b8481ac969f1 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -355,6 +355,8 @@ enum rsc_handling_status {
 
 /**
  * struct rproc_ops - platform-specific device handlers
+ * @prepare:	prepare device for code loading
+ * @unprepare:	unprepare device after stop
  * @start:	power on the device and boot it
  * @stop:	power off the device
  * @kick:	kick a virtqueue (virtqueue id given as a parameter)
@@ -373,6 +375,8 @@ enum rsc_handling_status {
  *		panic at least the returned number of milliseconds
  */
 struct rproc_ops {
+	int (*prepare)(struct rproc *rproc);
+	int (*unprepare)(struct rproc *rproc);
 	int (*start)(struct rproc *rproc);
 	int (*stop)(struct rproc *rproc);
 	void (*kick)(struct rproc *rproc, int vqid);
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] remoteproc: Use a local copy for the name field
  2020-04-17  0:20 [PATCH 0/2] rproc core patches needed for TI K3 drivers Suman Anna
  2020-04-17  0:20 ` [PATCH 1/2] remoteproc: Add prepare and unprepare ops Suman Anna
@ 2020-04-17  0:20 ` Suman Anna
  2020-04-17 17:04   ` Mathieu Poirier
  2020-04-20  4:59   ` Bjorn Andersson
  1 sibling, 2 replies; 8+ messages in thread
From: Suman Anna @ 2020-04-17  0:20 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-arm-kernel, linux-kernel, Suman Anna

The current name field used in the remoteproc structure is simply
a pointer to a name field supplied during the rproc_alloc() call.
The pointer passed in by remoteproc drivers during registration is
typically a dev_name pointer, but it is possible that the pointer
will no longer remain valid if the devices themselves were created
at runtime like in the case of of_platform_populate(), and were
deleted upon any failures within the respective remoteproc driver
probe function.

So, allocate and maintain a local copy for this name field to
keep it agnostic of the logic used in the remoteproc drivers.

Signed-off-by: Suman Anna <s-anna@ti.com>
---
v1:
 - Patch baselined on top of Mathieu's rproc_alloc() refactor
   series, and so addresses Bjorn's simplified cleanup comments
 - Switch to {kstrdup/kfree}_const variants
v0: https://patchwork.kernel.org/patch/11456385/

 drivers/remoteproc/remoteproc_core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index e38f627059ac..3cebface3f26 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1984,6 +1984,7 @@ static void rproc_type_release(struct device *dev)
 
 	kfree(rproc->firmware);
 	kfree(rproc->ops);
+	kfree_const(rproc->name);
 	kfree(rproc);
 }
 
@@ -2069,7 +2070,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	if (!rproc)
 		return NULL;
 
-	rproc->name = name;
 	rproc->priv = &rproc[1];
 	rproc->auto_boot = true;
 	rproc->elf_class = ELFCLASS32;
@@ -2081,6 +2081,10 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	rproc->dev.driver_data = rproc;
 	idr_init(&rproc->notifyids);
 
+	rproc->name = kstrdup_const(name, GFP_KERNEL);
+	if (!rproc->name)
+		goto put_device;
+
 	if (rproc_alloc_firmware(rproc, name, firmware))
 		goto put_device;
 
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] remoteproc: Use a local copy for the name field
  2020-04-17  0:20 ` [PATCH 2/2] remoteproc: Use a local copy for the name field Suman Anna
@ 2020-04-17 17:04   ` Mathieu Poirier
  2020-04-20  4:59   ` Bjorn Andersson
  1 sibling, 0 replies; 8+ messages in thread
From: Mathieu Poirier @ 2020-04-17 17:04 UTC (permalink / raw)
  To: Suman Anna
  Cc: Bjorn Andersson, linux-remoteproc, linux-arm-kernel,
	Linux Kernel Mailing List

On Thu, 16 Apr 2020 at 18:20, Suman Anna <s-anna@ti.com> wrote:
>
> The current name field used in the remoteproc structure is simply
> a pointer to a name field supplied during the rproc_alloc() call.
> The pointer passed in by remoteproc drivers during registration is
> typically a dev_name pointer, but it is possible that the pointer
> will no longer remain valid if the devices themselves were created
> at runtime like in the case of of_platform_populate(), and were
> deleted upon any failures within the respective remoteproc driver
> probe function.
>
> So, allocate and maintain a local copy for this name field to
> keep it agnostic of the logic used in the remoteproc drivers.
>
> Signed-off-by: Suman Anna <s-anna@ti.com>
> ---
> v1:
>  - Patch baselined on top of Mathieu's rproc_alloc() refactor
>    series, and so addresses Bjorn's simplified cleanup comments
>  - Switch to {kstrdup/kfree}_const variants
> v0: https://patchwork.kernel.org/patch/11456385/
>
>  drivers/remoteproc/remoteproc_core.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index e38f627059ac..3cebface3f26 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1984,6 +1984,7 @@ static void rproc_type_release(struct device *dev)
>
>         kfree(rproc->firmware);
>         kfree(rproc->ops);
> +       kfree_const(rproc->name);
>         kfree(rproc);
>  }
>
> @@ -2069,7 +2070,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>         if (!rproc)
>                 return NULL;
>
> -       rproc->name = name;
>         rproc->priv = &rproc[1];
>         rproc->auto_boot = true;
>         rproc->elf_class = ELFCLASS32;
> @@ -2081,6 +2081,10 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>         rproc->dev.driver_data = rproc;
>         idr_init(&rproc->notifyids);
>
> +       rproc->name = kstrdup_const(name, GFP_KERNEL);
> +       if (!rproc->name)
> +               goto put_device;
> +

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>         if (rproc_alloc_firmware(rproc, name, firmware))
>                 goto put_device;
>
> --
> 2.26.0
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] remoteproc: Use a local copy for the name field
  2020-04-17  0:20 ` [PATCH 2/2] remoteproc: Use a local copy for the name field Suman Anna
  2020-04-17 17:04   ` Mathieu Poirier
@ 2020-04-20  4:59   ` Bjorn Andersson
  1 sibling, 0 replies; 8+ messages in thread
From: Bjorn Andersson @ 2020-04-20  4:59 UTC (permalink / raw)
  To: Suman Anna
  Cc: Mathieu Poirier, linux-remoteproc, linux-arm-kernel, linux-kernel

On Thu 16 Apr 17:20 PDT 2020, Suman Anna wrote:

> The current name field used in the remoteproc structure is simply
> a pointer to a name field supplied during the rproc_alloc() call.
> The pointer passed in by remoteproc drivers during registration is
> typically a dev_name pointer, but it is possible that the pointer
> will no longer remain valid if the devices themselves were created
> at runtime like in the case of of_platform_populate(), and were
> deleted upon any failures within the respective remoteproc driver
> probe function.
> 
> So, allocate and maintain a local copy for this name field to
> keep it agnostic of the logic used in the remoteproc drivers.
> 
> Signed-off-by: Suman Anna <s-anna@ti.com>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
> v1:
>  - Patch baselined on top of Mathieu's rproc_alloc() refactor
>    series, and so addresses Bjorn's simplified cleanup comments
>  - Switch to {kstrdup/kfree}_const variants
> v0: https://patchwork.kernel.org/patch/11456385/
> 
>  drivers/remoteproc/remoteproc_core.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index e38f627059ac..3cebface3f26 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1984,6 +1984,7 @@ static void rproc_type_release(struct device *dev)
>  
>  	kfree(rproc->firmware);
>  	kfree(rproc->ops);
> +	kfree_const(rproc->name);
>  	kfree(rproc);
>  }
>  
> @@ -2069,7 +2070,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  	if (!rproc)
>  		return NULL;
>  
> -	rproc->name = name;
>  	rproc->priv = &rproc[1];
>  	rproc->auto_boot = true;
>  	rproc->elf_class = ELFCLASS32;
> @@ -2081,6 +2081,10 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  	rproc->dev.driver_data = rproc;
>  	idr_init(&rproc->notifyids);
>  
> +	rproc->name = kstrdup_const(name, GFP_KERNEL);
> +	if (!rproc->name)
> +		goto put_device;
> +
>  	if (rproc_alloc_firmware(rproc, name, firmware))
>  		goto put_device;
>  
> -- 
> 2.26.0
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] remoteproc: Add prepare and unprepare ops
  2020-04-17  0:20 ` [PATCH 1/2] remoteproc: Add prepare and unprepare ops Suman Anna
@ 2020-04-21  2:52   ` Bjorn Andersson
  2020-04-21 14:12     ` Suman Anna
  0 siblings, 1 reply; 8+ messages in thread
From: Bjorn Andersson @ 2020-04-21  2:52 UTC (permalink / raw)
  To: Suman Anna
  Cc: Mathieu Poirier, linux-remoteproc, linux-arm-kernel,
	linux-kernel, Loic Pallardy

On Thu 16 Apr 17:20 PDT 2020, Suman Anna wrote:

> From: Loic Pallardy <loic.pallardy@st.com>
> 
> On some SoC architecture, it is needed to enable HW like
> clock, bus, regulator, memory region... before loading
> co-processor firmware.
> 
> This patch introduces prepare and unprepare ops to execute
> platform specific function before firmware loading and after
> stop execution.
> 
> Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
> Signed-off-by: Suman Anna <s-anna@ti.com>
> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Do we have an inbound user of these new oops?

Regards,
Bjorn

> ---
> v1:
>  - Make the direct ops into inline helper functions in line
>    with the comments on the MCU sync series (v1 comments).
>    No change in functionality.
>  - Picked up the Reviewed-by tags
> v0: https://patchwork.kernel.org/patch/11456383/
> 
>  drivers/remoteproc/remoteproc_core.c     | 15 ++++++++++++++-
>  drivers/remoteproc/remoteproc_internal.h | 16 ++++++++++++++++
>  include/linux/remoteproc.h               |  4 ++++
>  3 files changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index d681eeb962b6..e38f627059ac 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1394,12 +1394,19 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
>  		return ret;
>  	}
>  
> +	/* Prepare rproc for firmware loading if needed */
> +	ret = rproc_prepare_device(rproc);
> +	if (ret) {
> +		dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret);
> +		goto disable_iommu;
> +	}
> +
>  	rproc->bootaddr = rproc_get_boot_addr(rproc, fw);
>  
>  	/* Load resource table, core dump segment list etc from the firmware */
>  	ret = rproc_parse_fw(rproc, fw);
>  	if (ret)
> -		goto disable_iommu;
> +		goto unprepare_rproc;
>  
>  	/* reset max_notifyid */
>  	rproc->max_notifyid = -1;
> @@ -1433,6 +1440,9 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
>  	kfree(rproc->cached_table);
>  	rproc->cached_table = NULL;
>  	rproc->table_ptr = NULL;
> +unprepare_rproc:
> +	/* release HW resources if needed */
> +	rproc_unprepare_device(rproc);
>  disable_iommu:
>  	rproc_disable_iommu(rproc);
>  	return ret;
> @@ -1838,6 +1848,9 @@ void rproc_shutdown(struct rproc *rproc)
>  	/* clean up all acquired resources */
>  	rproc_resource_cleanup(rproc);
>  
> +	/* release HW resources if needed */
> +	rproc_unprepare_device(rproc);
> +
>  	rproc_disable_iommu(rproc);
>  
>  	/* Free the copy of the resource table */
> diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h
> index b389dc79da81..101e6be8d240 100644
> --- a/drivers/remoteproc/remoteproc_internal.h
> +++ b/drivers/remoteproc/remoteproc_internal.h
> @@ -64,6 +64,22 @@ struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
>  struct rproc_mem_entry *
>  rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
>  
> +static inline int rproc_prepare_device(struct rproc *rproc)
> +{
> +	if (rproc->ops->prepare)
> +		return rproc->ops->prepare(rproc);
> +
> +	return 0;
> +}
> +
> +static inline int rproc_unprepare_device(struct rproc *rproc)
> +{
> +	if (rproc->ops->unprepare)
> +		return rproc->ops->unprepare(rproc);
> +
> +	return 0;
> +}
> +
>  static inline
>  int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
>  {
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 38607107b7cb..b8481ac969f1 100644
> --- a/include/linux/remoteproc.h
> +++ b/include/linux/remoteproc.h
> @@ -355,6 +355,8 @@ enum rsc_handling_status {
>  
>  /**
>   * struct rproc_ops - platform-specific device handlers
> + * @prepare:	prepare device for code loading
> + * @unprepare:	unprepare device after stop
>   * @start:	power on the device and boot it
>   * @stop:	power off the device
>   * @kick:	kick a virtqueue (virtqueue id given as a parameter)
> @@ -373,6 +375,8 @@ enum rsc_handling_status {
>   *		panic at least the returned number of milliseconds
>   */
>  struct rproc_ops {
> +	int (*prepare)(struct rproc *rproc);
> +	int (*unprepare)(struct rproc *rproc);
>  	int (*start)(struct rproc *rproc);
>  	int (*stop)(struct rproc *rproc);
>  	void (*kick)(struct rproc *rproc, int vqid);
> -- 
> 2.26.0
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] remoteproc: Add prepare and unprepare ops
  2020-04-21  2:52   ` Bjorn Andersson
@ 2020-04-21 14:12     ` Suman Anna
  2020-04-23  5:01       ` Bjorn Andersson
  0 siblings, 1 reply; 8+ messages in thread
From: Suman Anna @ 2020-04-21 14:12 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Mathieu Poirier, linux-remoteproc, linux-arm-kernel,
	linux-kernel, Loic Pallardy

On 4/20/20 9:52 PM, Bjorn Andersson wrote:
> On Thu 16 Apr 17:20 PDT 2020, Suman Anna wrote:
> 
>> From: Loic Pallardy <loic.pallardy@st.com>
>>
>> On some SoC architecture, it is needed to enable HW like
>> clock, bus, regulator, memory region... before loading
>> co-processor firmware.
>>
>> This patch introduces prepare and unprepare ops to execute
>> platform specific function before firmware loading and after
>> stop execution.
>>
>> Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
>> Signed-off-by: Suman Anna <s-anna@ti.com>
>> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
>> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> 
> Do we have an inbound user of these new oops?

Yes, both the TI K3 R5F and DSP remoteproc drivers use these ops, the 
patches are already on the lists.

regards
Suman

> 
> Regards,
> Bjorn
> 
>> ---
>> v1:
>>   - Make the direct ops into inline helper functions in line
>>     with the comments on the MCU sync series (v1 comments).
>>     No change in functionality.
>>   - Picked up the Reviewed-by tags
>> v0: https://patchwork.kernel.org/patch/11456383/
>>
>>   drivers/remoteproc/remoteproc_core.c     | 15 ++++++++++++++-
>>   drivers/remoteproc/remoteproc_internal.h | 16 ++++++++++++++++
>>   include/linux/remoteproc.h               |  4 ++++
>>   3 files changed, 34 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
>> index d681eeb962b6..e38f627059ac 100644
>> --- a/drivers/remoteproc/remoteproc_core.c
>> +++ b/drivers/remoteproc/remoteproc_core.c
>> @@ -1394,12 +1394,19 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
>>   		return ret;
>>   	}
>>   
>> +	/* Prepare rproc for firmware loading if needed */
>> +	ret = rproc_prepare_device(rproc);
>> +	if (ret) {
>> +		dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret);
>> +		goto disable_iommu;
>> +	}
>> +
>>   	rproc->bootaddr = rproc_get_boot_addr(rproc, fw);
>>   
>>   	/* Load resource table, core dump segment list etc from the firmware */
>>   	ret = rproc_parse_fw(rproc, fw);
>>   	if (ret)
>> -		goto disable_iommu;
>> +		goto unprepare_rproc;
>>   
>>   	/* reset max_notifyid */
>>   	rproc->max_notifyid = -1;
>> @@ -1433,6 +1440,9 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
>>   	kfree(rproc->cached_table);
>>   	rproc->cached_table = NULL;
>>   	rproc->table_ptr = NULL;
>> +unprepare_rproc:
>> +	/* release HW resources if needed */
>> +	rproc_unprepare_device(rproc);
>>   disable_iommu:
>>   	rproc_disable_iommu(rproc);
>>   	return ret;
>> @@ -1838,6 +1848,9 @@ void rproc_shutdown(struct rproc *rproc)
>>   	/* clean up all acquired resources */
>>   	rproc_resource_cleanup(rproc);
>>   
>> +	/* release HW resources if needed */
>> +	rproc_unprepare_device(rproc);
>> +
>>   	rproc_disable_iommu(rproc);
>>   
>>   	/* Free the copy of the resource table */
>> diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h
>> index b389dc79da81..101e6be8d240 100644
>> --- a/drivers/remoteproc/remoteproc_internal.h
>> +++ b/drivers/remoteproc/remoteproc_internal.h
>> @@ -64,6 +64,22 @@ struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
>>   struct rproc_mem_entry *
>>   rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
>>   
>> +static inline int rproc_prepare_device(struct rproc *rproc)
>> +{
>> +	if (rproc->ops->prepare)
>> +		return rproc->ops->prepare(rproc);
>> +
>> +	return 0;
>> +}
>> +
>> +static inline int rproc_unprepare_device(struct rproc *rproc)
>> +{
>> +	if (rproc->ops->unprepare)
>> +		return rproc->ops->unprepare(rproc);
>> +
>> +	return 0;
>> +}
>> +
>>   static inline
>>   int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
>>   {
>> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>> index 38607107b7cb..b8481ac969f1 100644
>> --- a/include/linux/remoteproc.h
>> +++ b/include/linux/remoteproc.h
>> @@ -355,6 +355,8 @@ enum rsc_handling_status {
>>   
>>   /**
>>    * struct rproc_ops - platform-specific device handlers
>> + * @prepare:	prepare device for code loading
>> + * @unprepare:	unprepare device after stop
>>    * @start:	power on the device and boot it
>>    * @stop:	power off the device
>>    * @kick:	kick a virtqueue (virtqueue id given as a parameter)
>> @@ -373,6 +375,8 @@ enum rsc_handling_status {
>>    *		panic at least the returned number of milliseconds
>>    */
>>   struct rproc_ops {
>> +	int (*prepare)(struct rproc *rproc);
>> +	int (*unprepare)(struct rproc *rproc);
>>   	int (*start)(struct rproc *rproc);
>>   	int (*stop)(struct rproc *rproc);
>>   	void (*kick)(struct rproc *rproc, int vqid);
>> -- 
>> 2.26.0
>>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] remoteproc: Add prepare and unprepare ops
  2020-04-21 14:12     ` Suman Anna
@ 2020-04-23  5:01       ` Bjorn Andersson
  0 siblings, 0 replies; 8+ messages in thread
From: Bjorn Andersson @ 2020-04-23  5:01 UTC (permalink / raw)
  To: Suman Anna
  Cc: Mathieu Poirier, linux-remoteproc, linux-arm-kernel,
	linux-kernel, Loic Pallardy

On Tue 21 Apr 07:12 PDT 2020, Suman Anna wrote:

> On 4/20/20 9:52 PM, Bjorn Andersson wrote:
> > On Thu 16 Apr 17:20 PDT 2020, Suman Anna wrote:
> > 
> > > From: Loic Pallardy <loic.pallardy@st.com>
> > > 
> > > On some SoC architecture, it is needed to enable HW like
> > > clock, bus, regulator, memory region... before loading
> > > co-processor firmware.
> > > 
> > > This patch introduces prepare and unprepare ops to execute
> > > platform specific function before firmware loading and after
> > > stop execution.
> > > 
> > > Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
> > > Signed-off-by: Suman Anna <s-anna@ti.com>
> > > Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> > > Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> > 
> > Do we have an inbound user of these new oops?
> 
> Yes, both the TI K3 R5F and DSP remoteproc drivers use these ops, the
> patches are already on the lists.
> 

Thanks for confirming Suman, I'll apply this.

Regards,
Bjorn

> regards
> Suman
> 
> > 
> > Regards,
> > Bjorn
> > 
> > > ---
> > > v1:
> > >   - Make the direct ops into inline helper functions in line
> > >     with the comments on the MCU sync series (v1 comments).
> > >     No change in functionality.
> > >   - Picked up the Reviewed-by tags
> > > v0: https://patchwork.kernel.org/patch/11456383/
> > > 
> > >   drivers/remoteproc/remoteproc_core.c     | 15 ++++++++++++++-
> > >   drivers/remoteproc/remoteproc_internal.h | 16 ++++++++++++++++
> > >   include/linux/remoteproc.h               |  4 ++++
> > >   3 files changed, 34 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> > > index d681eeb962b6..e38f627059ac 100644
> > > --- a/drivers/remoteproc/remoteproc_core.c
> > > +++ b/drivers/remoteproc/remoteproc_core.c
> > > @@ -1394,12 +1394,19 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
> > >   		return ret;
> > >   	}
> > > +	/* Prepare rproc for firmware loading if needed */
> > > +	ret = rproc_prepare_device(rproc);
> > > +	if (ret) {
> > > +		dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret);
> > > +		goto disable_iommu;
> > > +	}
> > > +
> > >   	rproc->bootaddr = rproc_get_boot_addr(rproc, fw);
> > >   	/* Load resource table, core dump segment list etc from the firmware */
> > >   	ret = rproc_parse_fw(rproc, fw);
> > >   	if (ret)
> > > -		goto disable_iommu;
> > > +		goto unprepare_rproc;
> > >   	/* reset max_notifyid */
> > >   	rproc->max_notifyid = -1;
> > > @@ -1433,6 +1440,9 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
> > >   	kfree(rproc->cached_table);
> > >   	rproc->cached_table = NULL;
> > >   	rproc->table_ptr = NULL;
> > > +unprepare_rproc:
> > > +	/* release HW resources if needed */
> > > +	rproc_unprepare_device(rproc);
> > >   disable_iommu:
> > >   	rproc_disable_iommu(rproc);
> > >   	return ret;
> > > @@ -1838,6 +1848,9 @@ void rproc_shutdown(struct rproc *rproc)
> > >   	/* clean up all acquired resources */
> > >   	rproc_resource_cleanup(rproc);
> > > +	/* release HW resources if needed */
> > > +	rproc_unprepare_device(rproc);
> > > +
> > >   	rproc_disable_iommu(rproc);
> > >   	/* Free the copy of the resource table */
> > > diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h
> > > index b389dc79da81..101e6be8d240 100644
> > > --- a/drivers/remoteproc/remoteproc_internal.h
> > > +++ b/drivers/remoteproc/remoteproc_internal.h
> > > @@ -64,6 +64,22 @@ struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
> > >   struct rproc_mem_entry *
> > >   rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
> > > +static inline int rproc_prepare_device(struct rproc *rproc)
> > > +{
> > > +	if (rproc->ops->prepare)
> > > +		return rproc->ops->prepare(rproc);
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static inline int rproc_unprepare_device(struct rproc *rproc)
> > > +{
> > > +	if (rproc->ops->unprepare)
> > > +		return rproc->ops->unprepare(rproc);
> > > +
> > > +	return 0;
> > > +}
> > > +
> > >   static inline
> > >   int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
> > >   {
> > > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> > > index 38607107b7cb..b8481ac969f1 100644
> > > --- a/include/linux/remoteproc.h
> > > +++ b/include/linux/remoteproc.h
> > > @@ -355,6 +355,8 @@ enum rsc_handling_status {
> > >   /**
> > >    * struct rproc_ops - platform-specific device handlers
> > > + * @prepare:	prepare device for code loading
> > > + * @unprepare:	unprepare device after stop
> > >    * @start:	power on the device and boot it
> > >    * @stop:	power off the device
> > >    * @kick:	kick a virtqueue (virtqueue id given as a parameter)
> > > @@ -373,6 +375,8 @@ enum rsc_handling_status {
> > >    *		panic at least the returned number of milliseconds
> > >    */
> > >   struct rproc_ops {
> > > +	int (*prepare)(struct rproc *rproc);
> > > +	int (*unprepare)(struct rproc *rproc);
> > >   	int (*start)(struct rproc *rproc);
> > >   	int (*stop)(struct rproc *rproc);
> > >   	void (*kick)(struct rproc *rproc, int vqid);
> > > -- 
> > > 2.26.0
> > > 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-04-23  5:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17  0:20 [PATCH 0/2] rproc core patches needed for TI K3 drivers Suman Anna
2020-04-17  0:20 ` [PATCH 1/2] remoteproc: Add prepare and unprepare ops Suman Anna
2020-04-21  2:52   ` Bjorn Andersson
2020-04-21 14:12     ` Suman Anna
2020-04-23  5:01       ` Bjorn Andersson
2020-04-17  0:20 ` [PATCH 2/2] remoteproc: Use a local copy for the name field Suman Anna
2020-04-17 17:04   ` Mathieu Poirier
2020-04-20  4:59   ` Bjorn Andersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).