diff mbox series

[v4,3/5] remoteproc: Add prepare/unprepare callbacks

Message ID 20191210164014.50739-3-paul@crapouillou.net (mailing list archive)
State Superseded
Headers show
Series [v4,1/5] dt-bindings: Document JZ47xx VPU auxiliary processor | expand

Commit Message

Paul Cercueil Dec. 10, 2019, 4:40 p.m. UTC
The .prepare() callback is called before the firmware is loaded to
memory. This is useful for instance in the case where some setup is
required for the memory to be accessible.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---

Notes:
    v2-v4: No change

 drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
 include/linux/remoteproc.h           |  4 ++++
 2 files changed, 19 insertions(+), 1 deletion(-)

Comments

Fabien DESSENNE Dec. 12, 2019, 10:03 a.m. UTC | #1
Hi Paul


On 10/12/2019 5:40 PM, Paul Cercueil wrote:
> The .prepare() callback is called before the firmware is loaded to
> memory. This is useful for instance in the case where some setup is
> required for the memory to be accessible.


I am trying to figure out what king of 'setup' may be required. From the 
ingenic driver I understand that you need to enable clocks to allow some 
memory access.

Instead of adding this new ops, why not enabling clocks in probe()?

BR

Fabien


>
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>
> Notes:
>      v2-v4: No change
>
>   drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
>   include/linux/remoteproc.h           |  4 ++++
>   2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 0a9fc7fdd1c3..3ea5f675a148 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
>   	struct device *dev = &rproc->dev;
>   	int ret;
>   
> +	if (rproc->ops->prepare) {
> +		ret = rproc->ops->prepare(rproc);
> +		if (ret) {
> +			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
> +			return 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;
> +		goto unprepare_rproc;
>   	}
>   
>   	/*
> @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
>   	rproc_unprepare_subdevices(rproc);
>   reset_table_ptr:
>   	rproc->table_ptr = rproc->cached_table;
> +unprepare_rproc:
> +	if (rproc->ops->unprepare)
> +		rproc->ops->unprepare(rproc);
>   
>   	return ret;
>   }
> @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc, bool crashed)
>   
>   	rproc->state = RPROC_OFFLINE;
>   
> +	if (rproc->ops->unprepare)
> +		rproc->ops->unprepare(rproc);
> +
>   	dev_info(dev, "stopped remote processor %s\n", rproc->name);
>   
>   	return 0;
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware is loaded)
> + * @unprepare:	unprepare the device after it is stopped
>    * @start:	power on the device and boot it
>    * @stop:	power off the device
>    * @kick:	kick a virtqueue (virtqueue id given as a parameter)
> @@ -371,6 +373,8 @@ enum rsc_handling_status {
>    * @get_boot_addr:	get boot address to entry point specified in firmware
>    */
>   struct rproc_ops {
> +	int (*prepare)(struct rproc *rproc);
> +	void (*unprepare)(struct rproc *rproc);
>   	int (*start)(struct rproc *rproc);
>   	int (*stop)(struct rproc *rproc);
>   	void (*kick)(struct rproc *rproc, int vqid);
Paul Cercueil Dec. 14, 2019, 10:30 p.m. UTC | #2
Hi Fabien,


Le jeu., déc. 12, 2019 at 10:03, Fabien DESSENNE 
<fabien.dessenne@st.com> a écrit :
> Hi Paul
> 
> 
> On 10/12/2019 5:40 PM, Paul Cercueil wrote:
>>  The .prepare() callback is called before the firmware is loaded to
>>  memory. This is useful for instance in the case where some setup is
>>  required for the memory to be accessible.
> 
> 
> I am trying to figure out what king of 'setup' may be required. From 
> the
> ingenic driver I understand that you need to enable clocks to allow 
> some
> memory access.
> 
> Instead of adding this new ops, why not enabling clocks in probe()?

Enabling the clocks in the probe means that the clocks will be 
unconditionally enabled until the driver is removed, even if the remote 
processor end up being unused. That would be a waste of power.

Cheers,
-Paul


> 
> BR
> 
> Fabien
> 
> 
>> 
>>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>  ---
>> 
>>  Notes:
>>       v2-v4: No change
>> 
>>    drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
>>    include/linux/remoteproc.h           |  4 ++++
>>    2 files changed, 19 insertions(+), 1 deletion(-)
>> 
>>  diff --git a/drivers/remoteproc/remoteproc_core.c 
>> b/drivers/remoteproc/remoteproc_core.c
>>  index 0a9fc7fdd1c3..3ea5f675a148 100644
>>  --- a/drivers/remoteproc/remoteproc_core.c
>>  +++ b/drivers/remoteproc/remoteproc_core.c
>>  @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc, 
>> const struct firmware *fw)
>>    	struct device *dev = &rproc->dev;
>>    	int ret;
>> 
>>  +	if (rproc->ops->prepare) {
>>  +		ret = rproc->ops->prepare(rproc);
>>  +		if (ret) {
>>  +			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
>>  +			return 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;
>>  +		goto unprepare_rproc;
>>    	}
>> 
>>    	/*
>>  @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc, 
>> const struct firmware *fw)
>>    	rproc_unprepare_subdevices(rproc);
>>    reset_table_ptr:
>>    	rproc->table_ptr = rproc->cached_table;
>>  +unprepare_rproc:
>>  +	if (rproc->ops->unprepare)
>>  +		rproc->ops->unprepare(rproc);
>> 
>>    	return ret;
>>    }
>>  @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc, 
>> bool crashed)
>> 
>>    	rproc->state = RPROC_OFFLINE;
>> 
>>  +	if (rproc->ops->unprepare)
>>  +		rproc->ops->unprepare(rproc);
>>  +
>>    	dev_info(dev, "stopped remote processor %s\n", rproc->name);
>> 
>>    	return 0;
>>  diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>>  index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware 
>> is loaded)
>>  + * @unprepare:	unprepare the device after it is stopped
>>     * @start:	power on the device and boot it
>>     * @stop:	power off the device
>>     * @kick:	kick a virtqueue (virtqueue id given as a parameter)
>>  @@ -371,6 +373,8 @@ enum rsc_handling_status {
>>     * @get_boot_addr:	get boot address to entry point specified in 
>> firmware
>>     */
>>    struct rproc_ops {
>>  +	int (*prepare)(struct rproc *rproc);
>>  +	void (*unprepare)(struct rproc *rproc);
>>    	int (*start)(struct rproc *rproc);
>>    	int (*stop)(struct rproc *rproc);
>>    	void (*kick)(struct rproc *rproc, int vqid);
Clément Leger Dec. 16, 2019, 8:42 a.m. UTC | #3
Hi Paul

----- On 14 Dec, 2019, at 23:30, Paul Cercueil paul@crapouillou.net wrote:

> Hi Fabien,
> 
> 
> Le jeu., déc. 12, 2019 at 10:03, Fabien DESSENNE
> <fabien.dessenne@st.com> a écrit :
>> Hi Paul
>> 
>> 
>> On 10/12/2019 5:40 PM, Paul Cercueil wrote:
>>>  The .prepare() callback is called before the firmware is loaded to
>>>  memory. This is useful for instance in the case where some setup is
>>>  required for the memory to be accessible.
>> 
>> 
>> I am trying to figure out what king of 'setup' may be required. From
>> the
>> ingenic driver I understand that you need to enable clocks to allow
>> some
>> memory access.
>> 
>> Instead of adding this new ops, why not enabling clocks in probe()?
> 
> Enabling the clocks in the probe means that the clocks will be
> unconditionally enabled until the driver is removed, even if the remote
> processor end up being unused. That would be a waste of power.

We have the same kind of "problem" for k1c remoteproc driver (not yet
upstream, depends on new arch). We need to enable clocks to load code
into remote processor memory and currently we do that in probe.
However, as you stated, we would like to enable them as late as possible
(just before loading code) to avoid wasting power unnecessarily. So the
"prepare" callback totally makes sense.

Regards,

Clément

> 
> Cheers,
> -Paul
> 
> 
>> 
>> BR
>> 
>> Fabien
>> 
>> 
>>> 
>>>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>>  ---
>>> 
>>>  Notes:
>>>       v2-v4: No change
>>> 
>>>    drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
>>>    include/linux/remoteproc.h           |  4 ++++
>>>    2 files changed, 19 insertions(+), 1 deletion(-)
>>> 
>>>  diff --git a/drivers/remoteproc/remoteproc_core.c
>>> b/drivers/remoteproc/remoteproc_core.c
>>>  index 0a9fc7fdd1c3..3ea5f675a148 100644
>>>  --- a/drivers/remoteproc/remoteproc_core.c
>>>  +++ b/drivers/remoteproc/remoteproc_core.c
>>>  @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc,
>>> const struct firmware *fw)
>>>    	struct device *dev = &rproc->dev;
>>>    	int ret;
>>> 
>>>  +	if (rproc->ops->prepare) {
>>>  +		ret = rproc->ops->prepare(rproc);
>>>  +		if (ret) {
>>>  +			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
>>>  +			return 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;
>>>  +		goto unprepare_rproc;
>>>    	}
>>> 
>>>    	/*
>>>  @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc,
>>> const struct firmware *fw)
>>>    	rproc_unprepare_subdevices(rproc);
>>>    reset_table_ptr:
>>>    	rproc->table_ptr = rproc->cached_table;
>>>  +unprepare_rproc:
>>>  +	if (rproc->ops->unprepare)
>>>  +		rproc->ops->unprepare(rproc);
>>> 
>>>    	return ret;
>>>    }
>>>  @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc,
>>> bool crashed)
>>> 
>>>    	rproc->state = RPROC_OFFLINE;
>>> 
>>>  +	if (rproc->ops->unprepare)
>>>  +		rproc->ops->unprepare(rproc);
>>>  +
>>>    	dev_info(dev, "stopped remote processor %s\n", rproc->name);
>>> 
>>>    	return 0;
>>>  diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>>>  index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware
>>> is loaded)
>>>  + * @unprepare:	unprepare the device after it is stopped
>>>     * @start:	power on the device and boot it
>>>     * @stop:	power off the device
>>>     * @kick:	kick a virtqueue (virtqueue id given as a parameter)
>>>  @@ -371,6 +373,8 @@ enum rsc_handling_status {
>>>     * @get_boot_addr:	get boot address to entry point specified in
>>> firmware
>>>     */
>>>    struct rproc_ops {
>>>  +	int (*prepare)(struct rproc *rproc);
>>>  +	void (*unprepare)(struct rproc *rproc);
>>>    	int (*start)(struct rproc *rproc);
>>>    	int (*stop)(struct rproc *rproc);
> >>    	void (*kick)(struct rproc *rproc, int vqid);
Clément Leger Dec. 16, 2019, 4:16 p.m. UTC | #4
Hi Paul,

I tested your patch and implemented the prepare callback only.
This is working correctly and the callback is correctly called
to enable clocks right before loading code into memory.

Regarding unprepare, I have no usecase for this since clocks
disabling and resetting is done in rproc_stop. Thus, I did not
tested this part. Did you add it to be called after the subdevices
unprepare call ? If not, what is the use case for this ?
ie, what are you doing in unprepare that you don't do in stop ?

Obviously it should work but I can't say I tested it completely !

Regards,

Clément


----- On 16 Dec, 2019, at 09:42, Clément Leger cleger@kalray.eu wrote:

> Hi Paul
> 
> ----- On 14 Dec, 2019, at 23:30, Paul Cercueil paul@crapouillou.net wrote:
> 
>> Hi Fabien,
>> 
>> 
>> Le jeu., déc. 12, 2019 at 10:03, Fabien DESSENNE
>> <fabien.dessenne@st.com> a écrit :
>>> Hi Paul
>>> 
>>> 
>>> On 10/12/2019 5:40 PM, Paul Cercueil wrote:
>>>>  The .prepare() callback is called before the firmware is loaded to
>>>>  memory. This is useful for instance in the case where some setup is
>>>>  required for the memory to be accessible.
>>> 
>>> 
>>> I am trying to figure out what king of 'setup' may be required. From
>>> the
>>> ingenic driver I understand that you need to enable clocks to allow
>>> some
>>> memory access.
>>> 
>>> Instead of adding this new ops, why not enabling clocks in probe()?
>> 
>> Enabling the clocks in the probe means that the clocks will be
>> unconditionally enabled until the driver is removed, even if the remote
>> processor end up being unused. That would be a waste of power.
> 
> We have the same kind of "problem" for k1c remoteproc driver (not yet
> upstream, depends on new arch). We need to enable clocks to load code
> into remote processor memory and currently we do that in probe.
> However, as you stated, we would like to enable them as late as possible
> (just before loading code) to avoid wasting power unnecessarily. So the
> "prepare" callback totally makes sense.
> 
> Regards,
> 
> Clément
> 
>> 
>> Cheers,
>> -Paul
>> 
>> 
>>> 
>>> BR
>>> 
>>> Fabien
>>> 
>>> 
>>>> 
>>>>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>>>  ---
>>>> 
>>>>  Notes:
>>>>       v2-v4: No change
>>>> 
>>>>    drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
>>>>    include/linux/remoteproc.h           |  4 ++++
>>>>    2 files changed, 19 insertions(+), 1 deletion(-)
>>>> 
>>>>  diff --git a/drivers/remoteproc/remoteproc_core.c
>>>> b/drivers/remoteproc/remoteproc_core.c
>>>>  index 0a9fc7fdd1c3..3ea5f675a148 100644
>>>>  --- a/drivers/remoteproc/remoteproc_core.c
>>>>  +++ b/drivers/remoteproc/remoteproc_core.c
>>>>  @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc,
>>>> const struct firmware *fw)
>>>>    	struct device *dev = &rproc->dev;
>>>>    	int ret;
>>>> 
>>>>  +	if (rproc->ops->prepare) {
>>>>  +		ret = rproc->ops->prepare(rproc);
>>>>  +		if (ret) {
>>>>  +			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
>>>>  +			return 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;
>>>>  +		goto unprepare_rproc;
>>>>    	}
>>>> 
>>>>    	/*
>>>>  @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc,
>>>> const struct firmware *fw)
>>>>    	rproc_unprepare_subdevices(rproc);
>>>>    reset_table_ptr:
>>>>    	rproc->table_ptr = rproc->cached_table;
>>>>  +unprepare_rproc:
>>>>  +	if (rproc->ops->unprepare)
>>>>  +		rproc->ops->unprepare(rproc);
>>>> 
>>>>    	return ret;
>>>>    }
>>>>  @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc,
>>>> bool crashed)
>>>> 
>>>>    	rproc->state = RPROC_OFFLINE;
>>>> 
>>>>  +	if (rproc->ops->unprepare)
>>>>  +		rproc->ops->unprepare(rproc);
>>>>  +
>>>>    	dev_info(dev, "stopped remote processor %s\n", rproc->name);
>>>> 
>>>>    	return 0;
>>>>  diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>>>>  index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware
>>>> is loaded)
>>>>  + * @unprepare:	unprepare the device after it is stopped
>>>>     * @start:	power on the device and boot it
>>>>     * @stop:	power off the device
>>>>     * @kick:	kick a virtqueue (virtqueue id given as a parameter)
>>>>  @@ -371,6 +373,8 @@ enum rsc_handling_status {
>>>>     * @get_boot_addr:	get boot address to entry point specified in
>>>> firmware
>>>>     */
>>>>    struct rproc_ops {
>>>>  +	int (*prepare)(struct rproc *rproc);
>>>>  +	void (*unprepare)(struct rproc *rproc);
>>>>    	int (*start)(struct rproc *rproc);
>>>>    	int (*stop)(struct rproc *rproc);
> > >>    	void (*kick)(struct rproc *rproc, int vqid);
Fabien DESSENNE Dec. 17, 2019, 10:21 a.m. UTC | #5
Hi Paul


On 14/12/2019 11:30 PM, Paul Cercueil wrote:
> Hi Fabien,
>
>
> Le jeu., déc. 12, 2019 at 10:03, Fabien DESSENNE 
> <fabien.dessenne@st.com> a écrit :
>> Hi Paul
>>
>>
>> On 10/12/2019 5:40 PM, Paul Cercueil wrote:
>>>  The .prepare() callback is called before the firmware is loaded to
>>>  memory. This is useful for instance in the case where some setup is
>>>  required for the memory to be accessible.
>>
>>
>> I am trying to figure out what king of 'setup' may be required. From the
>> ingenic driver I understand that you need to enable clocks to allow some
>> memory access.
>>
>> Instead of adding this new ops, why not enabling clocks in probe()?
>
> Enabling the clocks in the probe means that the clocks will be 
> unconditionally enabled until the driver is removed, even if the 
> remote processor end up being unused. That would be a waste of power.


OK I understand.

Nevertheless I think that you may need to call .prepare() from 
rproc_fw_boot() since you may need to access some memories from the 
point rproc_handle_resources() is called (this sets up virtio which is 
used if you have a resource table defining vdev).

And rproc_fw_boot() calls rproc_enable_iommu(), which sounds like 
"prepare memory", so this may be the right place to call .prepare()


BR

Fabien


>
> Cheers,
> -Paul
>
>
>>
>> BR
>>
>> Fabien
>>
>>
>>>
>>>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>>  ---
>>>
>>>  Notes:
>>>       v2-v4: No change
>>>
>>>    drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
>>>    include/linux/remoteproc.h           |  4 ++++
>>>    2 files changed, 19 insertions(+), 1 deletion(-)
>>>
>>>  diff --git a/drivers/remoteproc/remoteproc_core.c 
>>> b/drivers/remoteproc/remoteproc_core.c
>>>  index 0a9fc7fdd1c3..3ea5f675a148 100644
>>>  --- a/drivers/remoteproc/remoteproc_core.c
>>>  +++ b/drivers/remoteproc/remoteproc_core.c
>>>  @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc, 
>>> const struct firmware *fw)
>>>        struct device *dev = &rproc->dev;
>>>        int ret;
>>>
>>>  +    if (rproc->ops->prepare) {
>>>  +        ret = rproc->ops->prepare(rproc);
>>>  +        if (ret) {
>>>  +            dev_err(dev, "Failed to prepare rproc: %d\n", ret);
>>>  +            return 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;
>>>  +        goto unprepare_rproc;
>>>        }
>>>
>>>        /*
>>>  @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc, 
>>> const struct firmware *fw)
>>>        rproc_unprepare_subdevices(rproc);
>>>    reset_table_ptr:
>>>        rproc->table_ptr = rproc->cached_table;
>>>  +unprepare_rproc:
>>>  +    if (rproc->ops->unprepare)
>>>  +        rproc->ops->unprepare(rproc);
>>>
>>>        return ret;
>>>    }
>>>  @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc, 
>>> bool crashed)
>>>
>>>        rproc->state = RPROC_OFFLINE;
>>>
>>>  +    if (rproc->ops->unprepare)
>>>  +        rproc->ops->unprepare(rproc);
>>>  +
>>>        dev_info(dev, "stopped remote processor %s\n", rproc->name);
>>>
>>>        return 0;
>>>  diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>>>  index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the 
>>> firmware is loaded)
>>>  + * @unprepare:    unprepare the device after it is stopped
>>>     * @start:    power on the device and boot it
>>>     * @stop:    power off the device
>>>     * @kick:    kick a virtqueue (virtqueue id given as a parameter)
>>>  @@ -371,6 +373,8 @@ enum rsc_handling_status {
>>>     * @get_boot_addr:    get boot address to entry point specified 
>>> in firmware
>>>     */
>>>    struct rproc_ops {
>>>  +    int (*prepare)(struct rproc *rproc);
>>>  +    void (*unprepare)(struct rproc *rproc);
>>>        int (*start)(struct rproc *rproc);
>>>        int (*stop)(struct rproc *rproc);
>>>        void (*kick)(struct rproc *rproc, int vqid);
>
>
Bjorn Andersson Dec. 21, 2019, 8:20 p.m. UTC | #6
On Tue 10 Dec 08:40 PST 2019, Paul Cercueil wrote:

> The .prepare() callback is called before the firmware is loaded to
> memory. This is useful for instance in the case where some setup is
> required for the memory to be accessible.
> 

Would it make sense to somehow tie this prepare/unprepare to the actual
struct rproc_mem_entry that needs the resource enabled?

Regards,
Bjorn

> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
> 
> Notes:
>     v2-v4: No change
> 
>  drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
>  include/linux/remoteproc.h           |  4 ++++
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 0a9fc7fdd1c3..3ea5f675a148 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
>  	struct device *dev = &rproc->dev;
>  	int ret;
>  
> +	if (rproc->ops->prepare) {
> +		ret = rproc->ops->prepare(rproc);
> +		if (ret) {
> +			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
> +			return 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;
> +		goto unprepare_rproc;
>  	}
>  
>  	/*
> @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
>  	rproc_unprepare_subdevices(rproc);
>  reset_table_ptr:
>  	rproc->table_ptr = rproc->cached_table;
> +unprepare_rproc:
> +	if (rproc->ops->unprepare)
> +		rproc->ops->unprepare(rproc);
>  
>  	return ret;
>  }
> @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc, bool crashed)
>  
>  	rproc->state = RPROC_OFFLINE;
>  
> +	if (rproc->ops->unprepare)
> +		rproc->ops->unprepare(rproc);
> +
>  	dev_info(dev, "stopped remote processor %s\n", rproc->name);
>  
>  	return 0;
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware is loaded)
> + * @unprepare:	unprepare the device after it is stopped
>   * @start:	power on the device and boot it
>   * @stop:	power off the device
>   * @kick:	kick a virtqueue (virtqueue id given as a parameter)
> @@ -371,6 +373,8 @@ enum rsc_handling_status {
>   * @get_boot_addr:	get boot address to entry point specified in firmware
>   */
>  struct rproc_ops {
> +	int (*prepare)(struct rproc *rproc);
> +	void (*unprepare)(struct rproc *rproc);
>  	int (*start)(struct rproc *rproc);
>  	int (*stop)(struct rproc *rproc);
>  	void (*kick)(struct rproc *rproc, int vqid);
> -- 
> 2.24.0
>
Paul Cercueil Jan. 15, 2020, 9:15 p.m. UTC | #7
Hi Bjorn,


Le sam., déc. 21, 2019 at 12:20, Bjorn Andersson 
<bjorn.andersson@linaro.org> a écrit :
> On Tue 10 Dec 08:40 PST 2019, Paul Cercueil wrote:
> 
>>  The .prepare() callback is called before the firmware is loaded to
>>  memory. This is useful for instance in the case where some setup is
>>  required for the memory to be accessible.
>> 
> 
> Would it make sense to somehow tie this prepare/unprepare to the 
> actual
> struct rproc_mem_entry that needs the resource enabled?

Do you need such granularity?

In my case, the three memories need the same clock to be enabled.

-Paul


> 
>>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>  ---
>> 
>>  Notes:
>>      v2-v4: No change
>> 
>>   drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
>>   include/linux/remoteproc.h           |  4 ++++
>>   2 files changed, 19 insertions(+), 1 deletion(-)
>> 
>>  diff --git a/drivers/remoteproc/remoteproc_core.c 
>> b/drivers/remoteproc/remoteproc_core.c
>>  index 0a9fc7fdd1c3..3ea5f675a148 100644
>>  --- a/drivers/remoteproc/remoteproc_core.c
>>  +++ b/drivers/remoteproc/remoteproc_core.c
>>  @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc, 
>> const struct firmware *fw)
>>   	struct device *dev = &rproc->dev;
>>   	int ret;
>> 
>>  +	if (rproc->ops->prepare) {
>>  +		ret = rproc->ops->prepare(rproc);
>>  +		if (ret) {
>>  +			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
>>  +			return 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;
>>  +		goto unprepare_rproc;
>>   	}
>> 
>>   	/*
>>  @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc, 
>> const struct firmware *fw)
>>   	rproc_unprepare_subdevices(rproc);
>>   reset_table_ptr:
>>   	rproc->table_ptr = rproc->cached_table;
>>  +unprepare_rproc:
>>  +	if (rproc->ops->unprepare)
>>  +		rproc->ops->unprepare(rproc);
>> 
>>   	return ret;
>>   }
>>  @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc, 
>> bool crashed)
>> 
>>   	rproc->state = RPROC_OFFLINE;
>> 
>>  +	if (rproc->ops->unprepare)
>>  +		rproc->ops->unprepare(rproc);
>>  +
>>   	dev_info(dev, "stopped remote processor %s\n", rproc->name);
>> 
>>   	return 0;
>>  diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>>  index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware 
>> is loaded)
>>  + * @unprepare:	unprepare the device after it is stopped
>>    * @start:	power on the device and boot it
>>    * @stop:	power off the device
>>    * @kick:	kick a virtqueue (virtqueue id given as a parameter)
>>  @@ -371,6 +373,8 @@ enum rsc_handling_status {
>>    * @get_boot_addr:	get boot address to entry point specified in 
>> firmware
>>    */
>>   struct rproc_ops {
>>  +	int (*prepare)(struct rproc *rproc);
>>  +	void (*unprepare)(struct rproc *rproc);
>>   	int (*start)(struct rproc *rproc);
>>   	int (*stop)(struct rproc *rproc);
>>   	void (*kick)(struct rproc *rproc, int vqid);
>>  --
>>  2.24.0
>>
Bjorn Andersson Jan. 20, 2020, 8:19 p.m. UTC | #8
On Wed 15 Jan 13:15 PST 2020, Paul Cercueil wrote:

> Hi Bjorn,
> 
> 
> Le sam., déc. 21, 2019 at 12:20, Bjorn Andersson
> <bjorn.andersson@linaro.org> a écrit :
> > On Tue 10 Dec 08:40 PST 2019, Paul Cercueil wrote:
> > 
> > >  The .prepare() callback is called before the firmware is loaded to
> > >  memory. This is useful for instance in the case where some setup is
> > >  required for the memory to be accessible.
> > > 
> > 
> > Would it make sense to somehow tie this prepare/unprepare to the actual
> > struct rproc_mem_entry that needs the resource enabled?
> 
> Do you need such granularity?
> 

I don't have such needs, but given some of the memory structure that
Suman and Loic has been talking about I would expect that such need
exists.

> In my case, the three memories need the same clock to be enabled.
> 

But we can update your driver to associate your one clock with the
memory objects if/when we end up implementing this later.

Regards,
Bjorn

> -Paul
> 
> 
> > 
> > >  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> > >  ---
> > > 
> > >  Notes:
> > >      v2-v4: No change
> > > 
> > >   drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
> > >   include/linux/remoteproc.h           |  4 ++++
> > >   2 files changed, 19 insertions(+), 1 deletion(-)
> > > 
> > >  diff --git a/drivers/remoteproc/remoteproc_core.c
> > > b/drivers/remoteproc/remoteproc_core.c
> > >  index 0a9fc7fdd1c3..3ea5f675a148 100644
> > >  --- a/drivers/remoteproc/remoteproc_core.c
> > >  +++ b/drivers/remoteproc/remoteproc_core.c
> > >  @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc,
> > > const struct firmware *fw)
> > >   	struct device *dev = &rproc->dev;
> > >   	int ret;
> > > 
> > >  +	if (rproc->ops->prepare) {
> > >  +		ret = rproc->ops->prepare(rproc);
> > >  +		if (ret) {
> > >  +			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
> > >  +			return 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;
> > >  +		goto unprepare_rproc;
> > >   	}
> > > 
> > >   	/*
> > >  @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc,
> > > const struct firmware *fw)
> > >   	rproc_unprepare_subdevices(rproc);
> > >   reset_table_ptr:
> > >   	rproc->table_ptr = rproc->cached_table;
> > >  +unprepare_rproc:
> > >  +	if (rproc->ops->unprepare)
> > >  +		rproc->ops->unprepare(rproc);
> > > 
> > >   	return ret;
> > >   }
> > >  @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc,
> > > bool crashed)
> > > 
> > >   	rproc->state = RPROC_OFFLINE;
> > > 
> > >  +	if (rproc->ops->unprepare)
> > >  +		rproc->ops->unprepare(rproc);
> > >  +
> > >   	dev_info(dev, "stopped remote processor %s\n", rproc->name);
> > > 
> > >   	return 0;
> > >  diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> > >  index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware
> > > is loaded)
> > >  + * @unprepare:	unprepare the device after it is stopped
> > >    * @start:	power on the device and boot it
> > >    * @stop:	power off the device
> > >    * @kick:	kick a virtqueue (virtqueue id given as a parameter)
> > >  @@ -371,6 +373,8 @@ enum rsc_handling_status {
> > >    * @get_boot_addr:	get boot address to entry point specified in
> > > firmware
> > >    */
> > >   struct rproc_ops {
> > >  +	int (*prepare)(struct rproc *rproc);
> > >  +	void (*unprepare)(struct rproc *rproc);
> > >   	int (*start)(struct rproc *rproc);
> > >   	int (*stop)(struct rproc *rproc);
> > >   	void (*kick)(struct rproc *rproc, int vqid);
> > >  --
> > >  2.24.0
> > > 
> 
>
Arnaud POULIQUEN Jan. 21, 2020, 10:24 a.m. UTC | #9
Hi Bjorn,Paul,

On 1/20/20 9:19 PM, Bjorn Andersson wrote:
> On Wed 15 Jan 13:15 PST 2020, Paul Cercueil wrote:
> 
>> Hi Bjorn,
>>
>>
>> Le sam., déc. 21, 2019 at 12:20, Bjorn Andersson
>> <bjorn.andersson@linaro.org> a écrit :
>>> On Tue 10 Dec 08:40 PST 2019, Paul Cercueil wrote:
>>>
>>>>  The .prepare() callback is called before the firmware is loaded to
>>>>  memory. This is useful for instance in the case where some setup is
>>>>  required for the memory to be accessible.
>>>>
>>>
>>> Would it make sense to somehow tie this prepare/unprepare to the actual
>>> struct rproc_mem_entry that needs the resource enabled?
>>
>> Do you need such granularity?
>>
> 
> I don't have such needs, but given some of the memory structure that
> Suman and Loic has been talking about I would expect that such need
> exists
> 
>> In my case, the three memories need the same clock to be enabled.
>>
> 
> But we can update your driver to associate your one clock with the
> memory objects if/when we end up implementing this later.

IMHO, as mention Fabien the prepare/unprepare should probably not in the stop/start
but in rproc_fw_boot and rproc_resource_cleanup. This should cover more usecases (such as power domain) and
avoid a unprepare/prepare on crash recovery.

Nevertheless I'm wondering if it's more like PM runtime that should be implemented here...?

Regards,
Arnaud

> 
> Regards,
> Bjorn
> 
>> -Paul
>>
>>
>>>
>>>>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>>>  ---
>>>>
>>>>  Notes:
>>>>      v2-v4: No change
>>>>
>>>>   drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++-
>>>>   include/linux/remoteproc.h           |  4 ++++
>>>>   2 files changed, 19 insertions(+), 1 deletion(-)
>>>>
>>>>  diff --git a/drivers/remoteproc/remoteproc_core.c
>>>> b/drivers/remoteproc/remoteproc_core.c
>>>>  index 0a9fc7fdd1c3..3ea5f675a148 100644
>>>>  --- a/drivers/remoteproc/remoteproc_core.c
>>>>  +++ b/drivers/remoteproc/remoteproc_core.c
>>>>  @@ -1299,11 +1299,19 @@ static int rproc_start(struct rproc *rproc,
>>>> const struct firmware *fw)
>>>>   	struct device *dev = &rproc->dev;
>>>>   	int ret;
>>>>
>>>>  +	if (rproc->ops->prepare) {
>>>>  +		ret = rproc->ops->prepare(rproc);
>>>>  +		if (ret) {
>>>>  +			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
>>>>  +			return 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;
>>>>  +		goto unprepare_rproc;
>>>>   	}
>>>>
>>>>   	/*
>>>>  @@ -1354,6 +1362,9 @@ static int rproc_start(struct rproc *rproc,
>>>> const struct firmware *fw)
>>>>   	rproc_unprepare_subdevices(rproc);
>>>>   reset_table_ptr:
>>>>   	rproc->table_ptr = rproc->cached_table;
>>>>  +unprepare_rproc:
>>>>  +	if (rproc->ops->unprepare)
>>>>  +		rproc->ops->unprepare(rproc);
>>>>
>>>>   	return ret;
>>>>   }
>>>>  @@ -1483,6 +1494,9 @@ static int rproc_stop(struct rproc *rproc,
>>>> bool crashed)
>>>>
>>>>   	rproc->state = RPROC_OFFLINE;
>>>>
>>>>  +	if (rproc->ops->unprepare)
>>>>  +		rproc->ops->unprepare(rproc);
>>>>  +
>>>>   	dev_info(dev, "stopped remote processor %s\n", rproc->name);
>>>>
>>>>   	return 0;
>>>>  diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>>>>  index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware
>>>> is loaded)
>>>>  + * @unprepare:	unprepare the device after it is stopped
>>>>    * @start:	power on the device and boot it
>>>>    * @stop:	power off the device
>>>>    * @kick:	kick a virtqueue (virtqueue id given as a parameter)
>>>>  @@ -371,6 +373,8 @@ enum rsc_handling_status {
>>>>    * @get_boot_addr:	get boot address to entry point specified in
>>>> firmware
>>>>    */
>>>>   struct rproc_ops {
>>>>  +	int (*prepare)(struct rproc *rproc);
>>>>  +	void (*unprepare)(struct rproc *rproc);
>>>>   	int (*start)(struct rproc *rproc);
>>>>   	int (*stop)(struct rproc *rproc);
>>>>   	void (*kick)(struct rproc *rproc, int vqid);
>>>>  --
>>>>  2.24.0
>>>>
>>
>>
diff mbox series

Patch

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 0a9fc7fdd1c3..3ea5f675a148 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1299,11 +1299,19 @@  static int rproc_start(struct rproc *rproc, const struct firmware *fw)
 	struct device *dev = &rproc->dev;
 	int ret;
 
+	if (rproc->ops->prepare) {
+		ret = rproc->ops->prepare(rproc);
+		if (ret) {
+			dev_err(dev, "Failed to prepare rproc: %d\n", ret);
+			return 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;
+		goto unprepare_rproc;
 	}
 
 	/*
@@ -1354,6 +1362,9 @@  static int rproc_start(struct rproc *rproc, const struct firmware *fw)
 	rproc_unprepare_subdevices(rproc);
 reset_table_ptr:
 	rproc->table_ptr = rproc->cached_table;
+unprepare_rproc:
+	if (rproc->ops->unprepare)
+		rproc->ops->unprepare(rproc);
 
 	return ret;
 }
@@ -1483,6 +1494,9 @@  static int rproc_stop(struct rproc *rproc, bool crashed)
 
 	rproc->state = RPROC_OFFLINE;
 
+	if (rproc->ops->unprepare)
+		rproc->ops->unprepare(rproc);
+
 	dev_info(dev, "stopped remote processor %s\n", rproc->name);
 
 	return 0;
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 5f201f0c86c3..a6272d1ba384 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 the device for power up (before the firmware is loaded)
+ * @unprepare:	unprepare the device after it is stopped
  * @start:	power on the device and boot it
  * @stop:	power off the device
  * @kick:	kick a virtqueue (virtqueue id given as a parameter)
@@ -371,6 +373,8 @@  enum rsc_handling_status {
  * @get_boot_addr:	get boot address to entry point specified in firmware
  */
 struct rproc_ops {
+	int (*prepare)(struct rproc *rproc);
+	void (*unprepare)(struct rproc *rproc);
 	int (*start)(struct rproc *rproc);
 	int (*stop)(struct rproc *rproc);
 	void (*kick)(struct rproc *rproc, int vqid);