remoteproc: Add support for synchronisation with MCU
Subsystems (2)
Mathieu Poirier
maintainercover remoteproc: Add support for synchronisation with MCU
This patchset is a new flavour of the work started by TI, ST and NXP to add support for attaching with an MCU at kernel boot time rather than starting it.
The name has been changed from "late attach" to "synchronisation" because it offers the former as a subset of the latter. It moves all the decision making as to whether the remoteproc core should synchronise with an MCU or boot from the platform code to the core, eliminating a lot of duplication in the logic.
In order to accomodate the infinite amount of possibilites and scenarios, the platform code is given the opportunity to dictate how MCUs should be handled at three different stages of the MCU lifecycle, that is when the remoteproc core initiates, when an MCU is stopped from the sysfs interface and when it crashes. More stages can be added if and when we see fit.
The last patch in the set is a refactor of a patch sent by Arnaud and Fabien. It is provided as an example of how to use the new functionality.
Best regards,
Mathieu
Fabien Dessenne (1):
remoteproc: stm32: add support for co-processor booted before kernel
Mathieu Poirier (17):
remoteproc: Add new operation and state machine for MCU
synchronisation
remoteproc: Introduce function rproc_set_mcu_sync_state()
remoteproc: Split firmware name allocation from rproc_alloc()
remoteproc: Split rproc_ops allocation from rproc_alloc()
remoteproc: Get rid of tedious error path
remoteproc: Introduce function rproc_alloc_internals()
remoteproc: Introduce function rproc_alloc_state_machine()
remoteproc: Allocate synchronisation state machine
remoteproc: Call the right core function based on synchronisation
state
remoteproc: Decouple firmware load and remoteproc booting
remoteproc: Repurpose function rproc_trigger_auto_boot()
remoteproc: Rename function rproc_fw_boot()
remoteproc: Introducting new functions to start and stop an MCU
remoteproc: Refactor function rproc_trigger_recovery()
remoteproc: Correctly deal with MCU synchronisation when changing FW
image
remoteproc: Correctly deal with MCU synchronisation when changing
state
remoteproc: Make MCU synchronisation state changes on stop and crashed
drivers/remoteproc/remoteproc_core.c | 383 ++++++++++++++++++----- drivers/remoteproc/remoteproc_debugfs.c | 31 ++ drivers/remoteproc/remoteproc_internal.h | 90 ++++-- drivers/remoteproc/remoteproc_sysfs.c | 57 +++- drivers/remoteproc/stm32_rproc.c | 207 +++++++++++- include/linux/remoteproc.h | 28 +- 6 files changed, 684 insertions(+), 112 deletions(-)
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 1/18 remoteproc: Add new operation and state machine for MCU synchronisation
Add a new rproc_ops sync_ops to support use cases where the remoteproc core is synchronisting with the MCU. When exactly to use the sync_ops is directed by the states in struct rproc_sync_states.
--- drivers/remoteproc/remoteproc_debugfs.c | 31 ++++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 5 ++++ include/linux/remoteproc.h | 23 +++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_debugfs.c +31 -0
@@ -311,6 +311,35 @@ static const struct file_operations rproc_carveouts_ops = { .release = single_release, }; +/* Expose synchronisation states via debugfs */ +static int rproc_sync_states_show (struct seq_file *seq,void *p) +{ +struct rproc *rproc = seq->private; + +seq_printf (seq,"Sync with MCU: %s\n" , + rproc->sync_with_mcu ?"true" :"false" ); +seq_printf (seq,"On init: %s\n" , + rproc->sync_states->on_init ?"true" :"false" ); +seq_printf (seq,"After stop: %s\n" , + rproc->sync_states->after_stop ?"true" :"false" ); +seq_printf (seq,"After crash: %s\n" , + rproc->sync_states->after_crash ?"true" :"false" ); + +return 0 ; +} + +static int rproc_sync_states_open (struct inode *inode,struct file *file) +{ +return single_open (file, rproc_sync_states_show, inode->i_private); +} + +static const struct file_operations rproc_sync_states_ops = { + .open = rproc_sync_states_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +void rproc_remove_trace_file (struct dentry *tfile) {debugfs_remove (tfile);
@@ -357,6 +386,8 @@ void rproc_create_debug_dir(struct rproc *rproc) rproc, &rproc_rsc_table_ops);debugfs_create_file ("carveout_memories" ,0400 , rproc->dbg_dir, rproc, &rproc_carveouts_ops); +debugfs_create_file ("sync_states" ,0400 , rproc->dbg_dir, + rproc, &rproc_sync_states_ops); }void __init rproc_init_debugfs (void )
drivers/remoteproc/remoteproc_internal.h +5 -0
@@ -63,6 +63,11 @@ 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 bool rproc_sync_with_mcu (struct rproc *rproc) +{ +return rproc->sync_with_mcu; +} +static inline int rproc_fw_sanity_check (struct rproc *rproc,const struct firmware *fw) {
include/linux/remoteproc.h +22 -1
@@ -353,6 +353,21 @@ enum rsc_handling_status { RSC_IGNORED = 1, }; +/** +* struct rproc_sync_states - platform specific states indicating which +* rproc_ops to use at specific times during +* the MCU lifecycle. +* @on_init: true if synchronising with MCU at system initialisation time +* @after_stop: true if synchronising with MCU after stopped from the +* command line +* @after_crash: true if synchonising with MCU after the MCU has crashed +*/ +struct rproc_sync_states { +bool on_init; +bool after_stop; +bool after_crash; +}; +/** * struct rproc_ops - platform-specific device handlers * @start: power on the device and boot it
@@ -456,6 +471,9 @@ struct rproc_dump_segment {* @firmware: name of firmware file to be loaded * @priv: private data which belongs to the platform-specific rproc module * @ops: platform-specific start/stop rproc handlers +* @sync_ops: paltform-specific start/stop rproc handlers when +* synchronising with a remote processor. +* @sync_states: Determine the rproc_ops to choose in specific states. * @dev: virtual device for refcounting and common remoteproc behavior * @power: refcount of users who need this rproc powered up * @state: state of the device
@@ -479,6 +497,7 @@ struct rproc_dump_segment {* @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU * @auto_boot: flag to indicate if remote processor should be auto-started +* @sync_with_mcu: true if currently synchronising with MCU * @dump_segments: list of segments in the firmware * @nb_vdev: number of vdev currently handled by rproc */
@@ -488,7 +507,8 @@ struct rproc {const char *name;char *firmware;void *priv; -struct rproc_ops *ops; +struct rproc_ops *ops, *sync_ops; +struct rproc_sync_states *sync_states;struct device dev;atomic_t power;unsigned int state;
@@ -512,6 +532,7 @@ struct rproc {size_t table_sz;bool has_iommu;bool auto_boot; +bool sync_with_mcu;struct list_head dump_segments;int nb_vdev; };
Signature · 1 line
2.20.1
Re: [PATCH 01/18] remoteproc: Add new operation and state machine for MCU synchronisation
Quoted 132 lines · Mathieu Poirier
Add a new
rproc_opssync_opsto support use cases where the remoteproc core is synchronisting with the MCU. When exactly to use thesync_opsis directed by the states in structrproc_sync_states.Signed-off-by Mathieu Poirier <[email protected]>--- drivers/remoteproc/remoteproc_debugfs.c | 31 ++++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 5 ++++ include/linux/remoteproc.h | 23 +++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-)drivers/remoteproc/remoteproc_debugfs.c +31
-0@@ -311,6 +311,35 @@ static const struct file_operations rproc_carveouts_ops = { .release = single_release, }; +/* Expose synchronisation states via debugfs */ +static int rproc_sync_states_show (struct seq_file *seq,void *p) +{ +struct rproc *rproc = seq->private; + +seq_printf (seq,"Sync with MCU: %s\n" , + rproc->sync_with_mcu ?"true" :"false" ); +seq_printf (seq,"On init: %s\n" , + rproc->sync_states->on_init ?"true" :"false" ); +seq_printf (seq,"After stop: %s\n" , + rproc->sync_states->after_stop ?"true" :"false" ); +seq_printf (seq,"After crash: %s\n" , + rproc->sync_states->after_crash ?"true" :"false" ); + +return 0 ; +} + +static int rproc_sync_states_open (struct inode *inode,struct file *file) +{ +return single_open (file, rproc_sync_states_show, inode->i_private); +} + +static const struct file_operations rproc_sync_states_ops = { + .open = rproc_sync_states_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +void rproc_remove_trace_file (struct dentry *tfile) {debugfs_remove (tfile);@@ -357,6 +386,8 @@ void rproc_create_debug_dir(struct rproc *rproc) rproc, &rproc_rsc_table_ops);debugfs_create_file ("carveout_memories" ,0400 , rproc->dbg_dir, rproc, &rproc_carveouts_ops); +debugfs_create_file ("sync_states" ,0400 , rproc->dbg_dir, + rproc, &rproc_sync_states_ops); }void __init rproc_init_debugfs (void )drivers/remoteproc/remoteproc_internal.h +5
-0@@ -63,6 +63,11 @@ 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 bool rproc_sync_with_mcu (struct rproc *rproc) +{ +return rproc->sync_with_mcu; +} +static inline int rproc_fw_sanity_check (struct rproc *rproc,const struct firmware *fw) {include/linux/remoteproc.h +21
-1@@ -353,6 +353,21 @@ enum rsc_handling_status { RSC_IGNORED = 1, }; +/** +* struct rproc_sync_states - platform specific states indicating which +* rproc_ops to use at specific times during +* the MCU lifecycle. +* @on_init: true if synchronising with MCU at system initialisation time +* @after_stop: true if synchronising with MCU after stopped from the +* command line +* @after_crash: true if synchonising with MCU after the MCU has crashed +*/ +struct rproc_sync_states { +bool on_init; +bool after_stop; +bool after_crash; +}; +/** * struct rproc_ops - platform-specific device handlers * @start: power on the device and boot it @@ -456,6 +471,9 @@ struct rproc_dump_segment {* @firmware: name of firmware file to be loaded * @priv: private data which belongs to the platform-specific rproc module * @ops: platform-specific start/stop rproc handlers +* @sync_ops: paltform-specific start/stop rproc handlers when +* synchronising with a remote processor. +* @sync_states: Determine the rproc_ops to choose in specific states. * @dev: virtual device for refcounting and common remoteproc behavior * @power: refcount of users who need this rproc powered up * @state: state of the device @@ -479,6 +497,7 @@ struct rproc_dump_segment {* @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU * @auto_boot: flag to indicate if remote processor should be auto-started +* @sync_with_mcu: true if currently synchronising with MCU * @dump_segments: list of segments in the firmware * @nb_vdev: number of vdev currently handled by rproc */ @@ -488,7 +507,8 @@ struct rproc {const char *name;char *firmware;void *priv; -struct rproc_ops *ops; +struct rproc_ops *ops, *sync_ops; +struct rproc_sync_states *sync_states;struct device dev;atomic_t power;unsigned int state;
include/linux/remoteproc.h struct rproc { · line 535
Quoted 4 lines
include/linux/remoteproc.h +1
-0@@ -512,6 +532,7 @@ struct rproc {size_t table_sz;bool has_iommu;bool auto_boot; +bool sync_with_mcu;
mcu isn't good suffix here, why DSP/VSP can't start before kernel?
Quoted 6 lines
include/linux/remoteproc.h +0
-1struct list_head dump_segments;int nb_vdev; }; --2.20.1
Mathieu Poirier
maintainerRe: [PATCH 01/18] remoteproc: Add new operation and state machine for MCU synchronisation
Hi Xiao,
Quoted 133 lines · Xiang Xiao
Quoted 130 lines · Mathieu Poirier
Add a new
rproc_opssync_opsto support use cases where the remoteproc core is synchronisting with the MCU. When exactly to use thesync_opsis directed by the states in structrproc_sync_states.Signed-off-by Mathieu Poirier <[email protected]>--- drivers/remoteproc/remoteproc_debugfs.c | 31 ++++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 5 ++++ include/linux/remoteproc.h | 23 +++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-)drivers/remoteproc/remoteproc_debugfs.c +31
-0@@ -311,6 +311,35 @@ static const struct file_operations rproc_carveouts_ops = { .release = single_release, }; +/* Expose synchronisation states via debugfs */ +static int rproc_sync_states_show (struct seq_file *seq,void *p) +{ +struct rproc *rproc = seq->private; + +seq_printf (seq,"Sync with MCU: %s\n" , + rproc->sync_with_mcu ?"true" :"false" ); +seq_printf (seq,"On init: %s\n" , + rproc->sync_states->on_init ?"true" :"false" ); +seq_printf (seq,"After stop: %s\n" , + rproc->sync_states->after_stop ?"true" :"false" ); +seq_printf (seq,"After crash: %s\n" , + rproc->sync_states->after_crash ?"true" :"false" ); + +return 0 ; +} + +static int rproc_sync_states_open (struct inode *inode,struct file *file) +{ +return single_open (file, rproc_sync_states_show, inode->i_private); +} + +static const struct file_operations rproc_sync_states_ops = { + .open = rproc_sync_states_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +void rproc_remove_trace_file (struct dentry *tfile) {debugfs_remove (tfile);@@ -357,6 +386,8 @@ void rproc_create_debug_dir(struct rproc *rproc) rproc, &rproc_rsc_table_ops);debugfs_create_file ("carveout_memories" ,0400 , rproc->dbg_dir, rproc, &rproc_carveouts_ops); +debugfs_create_file ("sync_states" ,0400 , rproc->dbg_dir, + rproc, &rproc_sync_states_ops); }void __init rproc_init_debugfs (void )drivers/remoteproc/remoteproc_internal.h +5
-0@@ -63,6 +63,11 @@ 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 bool rproc_sync_with_mcu (struct rproc *rproc) +{ +return rproc->sync_with_mcu; +} +static inline int rproc_fw_sanity_check (struct rproc *rproc,const struct firmware *fw) {include/linux/remoteproc.h +21
-1@@ -353,6 +353,21 @@ enum rsc_handling_status { RSC_IGNORED = 1, }; +/** +* struct rproc_sync_states - platform specific states indicating which +* rproc_ops to use at specific times during +* the MCU lifecycle. +* @on_init: true if synchronising with MCU at system initialisation time +* @after_stop: true if synchronising with MCU after stopped from the +* command line +* @after_crash: true if synchonising with MCU after the MCU has crashed +*/ +struct rproc_sync_states { +bool on_init; +bool after_stop; +bool after_crash; +}; +/** * struct rproc_ops - platform-specific device handlers * @start: power on the device and boot it @@ -456,6 +471,9 @@ struct rproc_dump_segment {* @firmware: name of firmware file to be loaded * @priv: private data which belongs to the platform-specific rproc module * @ops: platform-specific start/stop rproc handlers +* @sync_ops: paltform-specific start/stop rproc handlers when +* synchronising with a remote processor. +* @sync_states: Determine the rproc_ops to choose in specific states. * @dev: virtual device for refcounting and common remoteproc behavior * @power: refcount of users who need this rproc powered up * @state: state of the device @@ -479,6 +497,7 @@ struct rproc_dump_segment {* @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU * @auto_boot: flag to indicate if remote processor should be auto-started +* @sync_with_mcu: true if currently synchronising with MCU * @dump_segments: list of segments in the firmware * @nb_vdev: number of vdev currently handled by rproc */ @@ -488,7 +507,8 @@ struct rproc {const char *name;char *firmware;void *priv; -struct rproc_ops *ops; +struct rproc_ops *ops, *sync_ops; +struct rproc_sync_states *sync_states;struct device dev;atomic_t power;
Quoted 8 lines
include/linux/remoteproc.h struct rproc { · line 535
Quoted 6 lines
include/linux/remoteproc.h +1
-0unsigned int state;@@ -512,6 +532,7 @@ struct rproc {size_t table_sz;bool has_iommu;bool auto_boot; +bool sync_with_mcu;mcu isn't good suffix here, why DSP/VSP can't start before kernel?
The term MCU is used in a generic sense throughout the patchset - it can reflect anything that can be a remote processor. I can easily change it to "rproc", but I'll wait to hear from other people though.
Thanks,
Mathieu
Quoted 7 lines
Quoted 7 lines
include/linux/remoteproc.h +0
-1struct list_head dump_segments;int nb_vdev; }; --2.20.1
Re: [PATCH 01/18] remoteproc: Add new operation and state machine for MCU synchronisation
Quoted 145 lines · Mathieu Poirier
Hi Xiao,
Quoted 133 lines · Xiang Xiao
Quoted 130 lines · Mathieu Poirier
Add a new
rproc_opssync_opsto support use cases where the remoteproc core is synchronisting with the MCU. When exactly to use thesync_opsis directed by the states in structrproc_sync_states.Signed-off-by Mathieu Poirier <[email protected]>--- drivers/remoteproc/remoteproc_debugfs.c | 31 ++++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 5 ++++ include/linux/remoteproc.h | 23 +++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-)drivers/remoteproc/remoteproc_debugfs.c +31
-0@@ -311,6 +311,35 @@ static const struct file_operations rproc_carveouts_ops = { .release = single_release, }; +/* Expose synchronisation states via debugfs */ +static int rproc_sync_states_show (struct seq_file *seq,void *p) +{ +struct rproc *rproc = seq->private; + +seq_printf (seq,"Sync with MCU: %s\n" , + rproc->sync_with_mcu ?"true" :"false" ); +seq_printf (seq,"On init: %s\n" , + rproc->sync_states->on_init ?"true" :"false" ); +seq_printf (seq,"After stop: %s\n" , + rproc->sync_states->after_stop ?"true" :"false" ); +seq_printf (seq,"After crash: %s\n" , + rproc->sync_states->after_crash ?"true" :"false" ); + +return 0 ; +} + +static int rproc_sync_states_open (struct inode *inode,struct file *file) +{ +return single_open (file, rproc_sync_states_show, inode->i_private); +} + +static const struct file_operations rproc_sync_states_ops = { + .open = rproc_sync_states_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +void rproc_remove_trace_file (struct dentry *tfile) {debugfs_remove (tfile);@@ -357,6 +386,8 @@ void rproc_create_debug_dir(struct rproc *rproc) rproc, &rproc_rsc_table_ops);debugfs_create_file ("carveout_memories" ,0400 , rproc->dbg_dir, rproc, &rproc_carveouts_ops); +debugfs_create_file ("sync_states" ,0400 , rproc->dbg_dir, + rproc, &rproc_sync_states_ops); }void __init rproc_init_debugfs (void )drivers/remoteproc/remoteproc_internal.h +5
-0@@ -63,6 +63,11 @@ 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 bool rproc_sync_with_mcu (struct rproc *rproc) +{ +return rproc->sync_with_mcu; +} +static inline int rproc_fw_sanity_check (struct rproc *rproc,const struct firmware *fw) {include/linux/remoteproc.h +21
-1@@ -353,6 +353,21 @@ enum rsc_handling_status { RSC_IGNORED = 1, }; +/** +* struct rproc_sync_states - platform specific states indicating which +* rproc_ops to use at specific times during +* the MCU lifecycle. +* @on_init: true if synchronising with MCU at system initialisation time +* @after_stop: true if synchronising with MCU after stopped from the +* command line +* @after_crash: true if synchonising with MCU after the MCU has crashed +*/ +struct rproc_sync_states { +bool on_init; +bool after_stop; +bool after_crash; +}; +/** * struct rproc_ops - platform-specific device handlers * @start: power on the device and boot it @@ -456,6 +471,9 @@ struct rproc_dump_segment {* @firmware: name of firmware file to be loaded * @priv: private data which belongs to the platform-specific rproc module * @ops: platform-specific start/stop rproc handlers +* @sync_ops: paltform-specific start/stop rproc handlers when +* synchronising with a remote processor. +* @sync_states: Determine the rproc_ops to choose in specific states. * @dev: virtual device for refcounting and common remoteproc behavior * @power: refcount of users who need this rproc powered up * @state: state of the device @@ -479,6 +497,7 @@ struct rproc_dump_segment {* @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU * @auto_boot: flag to indicate if remote processor should be auto-started +* @sync_with_mcu: true if currently synchronising with MCU * @dump_segments: list of segments in the firmware * @nb_vdev: number of vdev currently handled by rproc */ @@ -488,7 +507,8 @@ struct rproc {const char *name;char *firmware;void *priv; -struct rproc_ops *ops; +struct rproc_ops *ops, *sync_ops; +struct rproc_sync_states *sync_states;struct device dev;atomic_t power;Quoted 8 lines
include/linux/remoteproc.h struct rproc { · line 535
Quoted 6 lines
include/linux/remoteproc.h +1
-0unsigned int state;@@ -512,6 +532,7 @@ struct rproc {size_t table_sz;bool has_iommu;bool auto_boot; +bool sync_with_mcu;mcu isn't good suffix here, why DSP/VSP can't start before kernel?
Quoted 3 lines
The term MCU is used in a generic sense throughout the patchset - it can reflect anything that can be a remote processor. I can easily change it to "rproc", but I'll wait to hear from other people though.
Yeah, let's not introduce another term for rproc and cause the code to fork.
regards
Suman
Quoted 11 lines
Thanks,
MathieuQuoted 7 lines
Quoted 7 lines
include/linux/remoteproc.h +0
-1struct list_head dump_segments;int nb_vdev; }; --2.20.1
Mathieu Poirier
maintainerPATCH 2/18 remoteproc: Introduce function rproc_set_mcu_sync_state()
In reply to Mathieu PoirierIntroduce function rproc_set_mcu_sync_state() to set the synchronisation state of the MCU at various stages of the lifecycle process.
--- drivers/remoteproc/remoteproc_internal.h | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
drivers/remoteproc/remoteproc_internal.h +38 -0
@@ -24,6 +24,26 @@ struct rproc_debug_trace {struct rproc_mem_entry trace_mem; }; +/* +* enum rproc_sync_states - remote processsor sync states +* @RPROC_SYNC_STATE_INIT state to use when the remoteproc core +* is initialising. +* @RPROC_SYNC_STATE_SHUTDOWN state to use after the remoteproc core +* has shutdown (rproc_shutdown()) the MCU. +* @RPROC_SYNC_STATE_CRASHED state to use after the MCU has crashed but +* has not been recovered by the remoteproc +* core yet. +* +* Keeping these separate from the enum rproc_state in order to avoid +* introducing coupling between the state of the MCU and the synchronisation +* operation to use. +*/ +enum rproc_mcu_sync_states { +RPROC_SYNC_STATE_INIT , +RPROC_SYNC_STATE_SHUTDOWN , +RPROC_SYNC_STATE_CRASHED , +}; +/* from remoteproc_core.c */ void rproc_release (struct kref *kref);irqreturn_t rproc_vq_interrupt (struct rproc *rproc,int vq_id);
@@ -68,6 +88,24 @@ static inline bool rproc_sync_with_mcu(struct rproc *rproc)return rproc->sync_with_mcu; } +static inline void rproc_set_mcu_sync_state (struct rproc *rproc, +unsigned int state) +{ +switch (state) { +case RPROC_SYNC_STATE_INIT : + rproc->sync_with_mcu = rproc->sync_states->on_init; +break ; +case RPROC_SYNC_STATE_SHUTDOWN : + rproc->sync_with_mcu = rproc->sync_states->after_stop; +break ; +case RPROC_SYNC_STATE_CRASHED : + rproc->sync_with_mcu = rproc->sync_states->after_crash; +break ; +default : +break ; + } +} +static inline int rproc_fw_sanity_check (struct rproc *rproc,const struct firmware *fw) {
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 3/18 remoteproc: Split firmware name allocation from rproc_alloc()
In reply to Mathieu PoirierMake the firmware name allocation a function on its own in order to introduce more flexibility to function rproc_alloc().
--- drivers/remoteproc/remoteproc_core.c | 62 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 23 deletions(-)
drivers/remoteproc/remoteproc_core.c +39 -23
@@ -1962,6 +1962,36 @@ static const struct device_type rproc_type = { .release = rproc_type_release, }; +static int rproc_alloc_firmware (struct rproc *rproc, +const char *name,const char *firmware) +{ +char *p, *template ="rproc-%s-fw" ; +int name_len; + +if (!rproc || !name) +return -EINVAL ; + +if (!firmware) { +/* +* If the caller didn't pass in a firmware name then +* construct a default name. +*/ + name_len =strlen (name) +strlen (template) -2 +1 ; + p =kmalloc (name_len,GFP_KERNEL ); +if (!p) +return -ENOMEM ; +snprintf (p, name_len, template, name); + }else { + p =kstrdup (firmware,GFP_KERNEL ); +if (!p) +return -ENOMEM ; + } + + rproc->firmware = p; + +return 0 ; +} +/** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device
@@ -1990,42 +2020,24 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, const char *firmware, int len) {struct rproc *rproc; -char *p, *template ="rproc-%s-fw" ; -int name_len;if (!dev || !name || !ops)return NULL ; -if (!firmware) { -/* -* If the caller didn't pass in a firmware name then -* construct a default name. -*/ - name_len =strlen (name) +strlen (template) -2 +1 ; - p =kmalloc (name_len,GFP_KERNEL ); -if (!p) -return NULL ; -snprintf (p, name_len, template, name); - }else { - p =kstrdup (firmware,GFP_KERNEL ); -if (!p) -return NULL ; - } - rproc =kzalloc (sizeof (struct rproc ) + len,GFP_KERNEL ); -if (!rproc) { -kfree (p); +if (!rproc)return NULL ; - } + +if (rproc_alloc_firmware (rproc, name, firmware)) + goto free_rproc; rproc->ops =kmemdup (ops,sizeof (*ops),GFP_KERNEL );if (!rproc->ops) { -kfree (p); +kfree (rproc->firmware);kfree (rproc);return NULL ; } - rproc->firmware = p; rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true;
@@ -2073,6 +2085,10 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->state =RPROC_OFFLINE ;return rproc; + +free_rproc: +kfree (rproc); +return NULL ; }EXPORT_SYMBOL (rproc_alloc);
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 4/18 remoteproc: Split rproc_ops allocation from rproc_alloc()
In reply to Mathieu PoirierMake the rproc_ops allocation a function on its own in order to introduce more flexibility to function rproc_alloc().
--- drivers/remoteproc/remoteproc_core.c | 45 ++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-)
drivers/remoteproc/remoteproc_core.c +30 -15
@@ -1992,6 +1992,32 @@ static int rproc_alloc_firmware(struct rproc *rproc,return 0 ; } +static int rproc_alloc_ops (struct rproc *rproc,const struct rproc_ops *ops) +{ +if (!rproc) +return -EINVAL ; + +/* Nothing to do if there isn't and ops to work with */ +if (!ops) +return 0 ; + + rproc->ops =kmemdup (ops,sizeof (*ops),GFP_KERNEL ); +if (!rproc->ops) +return -ENOMEM ; + +/* Default to ELF loader if no load function is specified */ +if (!rproc->ops->load) { + rproc->ops->load = rproc_elf_load_segments; + rproc->ops->parse_fw = rproc_elf_load_rsc_table; + rproc->ops->find_loaded_rsc_table = + rproc_elf_find_loaded_rsc_table; + rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; + } + +return 0 ; +} +/** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device
@@ -2031,12 +2057,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,if (rproc_alloc_firmware (rproc, name, firmware)) goto free_rproc; - rproc->ops =kmemdup (ops,sizeof (*ops),GFP_KERNEL ); -if (!rproc->ops) { -kfree (rproc->firmware); -kfree (rproc); -return NULL ; - } +if (rproc_alloc_ops (rproc, ops)) + goto free_firmware; rproc->name = name; rproc->priv = &rproc[1 ];
@@ -2060,15 +2082,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,atomic_set (&rproc->power,0 ); -/* Default to ELF loader if no load function is specified */ -if (!rproc->ops->load) { - rproc->ops->load = rproc_elf_load_segments; - rproc->ops->parse_fw = rproc_elf_load_rsc_table; - rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; - rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; - } -mutex_init (&rproc->lock);idr_init (&rproc->notifyids);
@@ -2086,6 +2099,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,return rproc; +free_firmware: +kfree (rproc->firmware); free_rproc:kfree (rproc);return NULL ;
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 5/18 remoteproc: Get rid of tedious error path
In reply to Mathieu PoirierGet rid of tedious error management by moving firmware and operation allocation after calling device_initialize(). That way we take advantage of the automatic call to rproc_type_release() to cleanup after ourselves when put_device() is called.
--- drivers/remoteproc/remoteproc_core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/remoteproc/remoteproc_core.c +9 -13
@@ -2054,12 +2054,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,if (!rproc)return NULL ; -if (rproc_alloc_firmware (rproc, name, firmware)) - goto free_rproc; - -if (rproc_alloc_ops (rproc, ops)) - goto free_firmware; - rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true;
@@ -2070,12 +2064,17 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.class = &rproc_class; rproc->dev.driver_data = rproc; +if (rproc_alloc_firmware (rproc, name, firmware)) + goto out; + +if (rproc_alloc_ops (rproc, ops)) + goto out; +/* Assign a unique device index and name */ rproc->index =ida_simple_get (&rproc_dev_index,0 ,0 ,GFP_KERNEL );if (rproc->index <0 ) {dev_err (dev,"ida_simple_get failed: %d\n" , rproc->index); -put_device (&rproc->dev); -return NULL ; + goto out; }dev_set_name (&rproc->dev,"remoteproc%d" , rproc->index);
@@ -2098,11 +2097,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->state =RPROC_OFFLINE ;return rproc; - -free_firmware: -kfree (rproc->firmware); -free_rproc: -kfree (rproc); +out: +put_device (&rproc->dev);return NULL ; }EXPORT_SYMBOL (rproc_alloc);
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 6/18 remoteproc: Introduce function rproc_alloc_internals()
In reply to Mathieu PoirierIn preparation to allocate the synchronisation operation and state machine, spin off a new function in order to keep rproc_alloc() as clean as possible.
--- drivers/remoteproc/remoteproc_core.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/remoteproc/remoteproc_core.c +22 -4
@@ -2018,6 +2018,26 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops)return 0 ; } +static int rproc_alloc_internals (struct rproc *rproc,const char *name, +const struct rproc_ops *boot_ops, +const char *firmware,int len) +{ +int ret; + +/* We have a boot_ops so allocate firmware name and operations */ +if (boot_ops) { + ret =rproc_alloc_firmware (rproc, name, firmware); +if (ret) +return ret; + + ret =rproc_alloc_ops (rproc, boot_ops); +if (ret) +return ret; + } + +return 0 ; +} +/** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device
@@ -2064,10 +2084,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.class = &rproc_class; rproc->dev.driver_data = rproc; -if (rproc_alloc_firmware (rproc, name, firmware)) - goto out; - -if (rproc_alloc_ops (rproc, ops)) +if (rproc_alloc_internals (rproc, name, ops, + firmware, len)) goto out;/* Assign a unique device index and name */
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 7/18 remoteproc: Introduce function rproc_alloc_state_machine()
In reply to Mathieu PoirierIntroducing new function rproc_alloc_state_machine() to allocate the MCU synchronisation operations and position it as the central remoteproc core allocation function.
--- drivers/remoteproc/remoteproc_core.c | 84 +++++++++++++++++++++++++--- include/linux/remoteproc.h | 5 ++ 2 files changed, 81 insertions(+), 8 deletions(-)
drivers/remoteproc/remoteproc_core.c +76 -8
@@ -1954,6 +1954,7 @@ static void rproc_type_release(struct device *dev)kfree (rproc->firmware);kfree (rproc->ops); +kfree (rproc->sync_ops);kfree (rproc); }
@@ -2018,12 +2019,34 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops)return 0 ; } +static int rproc_alloc_sync_ops (struct rproc *rproc, +const struct rproc_ops *sync_ops) +{ +/* +* Given the unlimited amount of possibilities when +* synchronising with an MCU, no constraints are imposed +* on sync_ops. +*/ + rproc->sync_ops =kmemdup (sync_ops, +sizeof (*sync_ops),GFP_KERNEL ); +if (!rproc->sync_ops) +return -ENOMEM ; + +return 0 ; +} +static int rproc_alloc_internals (struct rproc *rproc,const char *name,const struct rproc_ops *boot_ops, +const struct rproc_ops *sync_ops, +struct rproc_sync_states *sync_states,const char *firmware,int len) {int ret; +/* We need at least a boot or a sync ops. */ +if (!boot_ops && !sync_ops) +return -EINVAL ; +/* We have a boot_ops so allocate firmware name and operations */ if (boot_ops) { ret =rproc_alloc_firmware (rproc, name, firmware);
@@ -2035,14 +2058,23 @@ static int rproc_alloc_internals(struct rproc *rproc, const char *name,return ret; } +/* Allocate a sync_ops if need be */ +if (sync_ops) { + ret =rproc_alloc_sync_ops (rproc, sync_ops); +if (ret) +return ret; + } +return 0 ; }/** -* rproc_alloc() - allocate a remote processor handle +* rproc_alloc_state_machine() - allocate a remote processor handle * @dev: the underlying device * @name: name of this remote processor * @ops: platform-specific handlers (mainly start/stop) +* @sync_ops: platform-specific handlers for synchronising with MCU +* @sync_states: states in which @ops and @sync_ops are to be used * @firmware: name of firmware file to load, can be NULL * @len: length of private data needed by the rproc driver (in bytes) *
@@ -2061,13 +2093,15 @@ static int rproc_alloc_internals(struct rproc *rproc, const char *name,* Note: _never_ directly deallocate @rproc, even if it was not registered * yet. Instead, when you need to unroll rproc_alloc(), use rproc_free(). */ -struct rproc *rproc_alloc (struct device *dev,const char *name, -const struct rproc_ops *ops, -const char *firmware,int len) +struct rproc *rproc_alloc_state_machine (struct device *dev,const char *name, +const struct rproc_ops *ops, +const struct rproc_ops *sync_ops, +struct rproc_sync_states *sync_states, +const char *firmware,int len) {struct rproc *rproc; -if (!dev || !name || !ops) +if (!dev || !name)return NULL ; rproc =kzalloc (sizeof (struct rproc ) + len,GFP_KERNEL );
@@ -2084,8 +2118,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.class = &rproc_class; rproc->dev.driver_data = rproc; -if (rproc_alloc_internals (rproc, name, ops, - firmware, len)) +if (rproc_alloc_internals (rproc, name, ops, sync_ops, + sync_states, firmware, len)) goto out;/* Assign a unique device index and name */
@@ -2119,7 +2153,41 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,put_device (&rproc->dev);return NULL ; } -EXPORT_SYMBOL (rproc_alloc); +EXPORT_SYMBOL (rproc_alloc_state_machine); + +/** +* rproc_alloc() - allocate a remote processor handle +* @dev: the underlying device +* @name: name of this remote processor +* @ops: platform-specific handlers (mainly start/stop) +* @firmware: name of firmware file to load, can be NULL +* @len: length of private data needed by the rproc driver (in bytes) +* +* Allocates a new remote processor handle, but does not register +* it yet. if @firmware is NULL, a default name is used. +* +* This function should be used by rproc implementations during initialization +* of the remote processor. +* +* After creating an rproc handle using this function, and when ready, +* implementations should then call rproc_add() to complete +* the registration of the remote processor. +* +* On success the new rproc is returned, and on failure, NULL. +* +* Note: _never_ directly deallocate @rproc, even if it was not registered +* yet. Instead, when you need to unroll rproc_alloc(), use rproc_free(). +*/ +struct rproc *rproc_alloc (struct device *dev,const char *name, +const struct rproc_ops *ops, +const char *firmware,int len) +{ +if (!name && !firmware) +return NULL ; + +return rproc_alloc_state_machine (dev, name, ops,NULL ,NULL , + firmware, len); +}/** * rproc_free() - unroll rproc_alloc()
include/linux/remoteproc.h +5 -0
@@ -611,6 +611,11 @@ struct rproc *rproc_get_by_child(struct device *dev);struct rproc *rproc_alloc (struct device *dev,const char *name,const struct rproc_ops *ops,const char *firmware,int len); +struct rproc *rproc_alloc_state_machine (struct device *dev,const char *name, +const struct rproc_ops *ops, +const struct rproc_ops *sync_ops, +struct rproc_sync_states *sync_states, +const char *firmware,int len);void rproc_put (struct rproc *rproc);int rproc_add (struct rproc *rproc);int rproc_del (struct rproc *rproc);
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 8/18 remoteproc: Allocate synchronisation state machine
In reply to Mathieu PoirierThis patch allocates a synchronisation state machine, either provided or not by users, in order to enact the proper behavior requested by the platform or specific scenarios.
--- drivers/remoteproc/remoteproc_core.c | 59 +++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +58 -1
@@ -1955,6 +1955,7 @@ static void rproc_type_release(struct device *dev)kfree (rproc->firmware);kfree (rproc->ops);kfree (rproc->sync_ops); +kfree (rproc->sync_states);kfree (rproc); }
@@ -2035,6 +2036,59 @@ static int rproc_alloc_sync_ops(struct rproc *rproc,return 0 ; } +static int rproc_alloc_sync_states (struct rproc *rproc, +const struct rproc_ops *boot_ops, +const struct rproc_ops *sync_ops, +struct rproc_sync_states *sync_states) +{ +struct rproc_sync_states *st; + +/* At least one set of operation is needed */ +if (!boot_ops && !sync_ops) +return -EINVAL ; + +/* We have a synchronisation state machine, no need to build one */ +if (sync_states) { + st =kmemdup (sync_states,sizeof (*st),GFP_KERNEL ); +if (!st) +return -ENOMEM ; + +/* Nothing else to do */ + goto out; + } + +/* Allocate synchronisation state machine */ + st =kzalloc (sizeof (*st),GFP_KERNEL ); +if (!st) +return -ENOMEM ; + +/* +* We have a boot_ops and no sync_ops - build a state machine that +* does _not_ synchronise with an MCU. +*/ +if (boot_ops && !sync_ops) { + st->on_init = st->after_stop = st->after_crash = false; + goto out; + } + +/* +* We have a sync_ops and an no boot_ops - build a state machine that +* _only_ synchronises with an MCU. +*/ +if (sync_ops && !boot_ops) { + st->on_init = st->after_stop = st->after_crash = true; + goto out; + } + +out: + rproc->sync_with_mcu = st->on_init; +/* And the synchronisation state machine to use */ + rproc->sync_states = st; +/* Tell the core what to do when initialising */ +rproc_set_mcu_sync_state (rproc,RPROC_SYNC_STATE_INIT ); +return 0 ; +} + static int rproc_alloc_internals(struct rproc *rproc, const char *name, const struct rproc_ops *boot_ops, const struct rproc_ops *sync_ops,
@@ -2065,7 +2119,10 @@ static int rproc_alloc_internals(struct rproc *rproc, const char *name,return ret; } -return 0 ; +/* Finally allocate the synchronisation state machine */ + ret =rproc_alloc_sync_states (rproc, boot_ops, sync_ops, sync_states); + +return ret; }/**
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 9/18 remoteproc: Call the right core function based on synchronisation state
In reply to Mathieu PoirierCall the right core function based on whether we should synchronise with an MCU or boot it from scratch.
--- drivers/remoteproc/remoteproc_internal.h | 35 +++++++++++------------- 1 file changed, 16 insertions(+), 19 deletions(-)
drivers/remoteproc/remoteproc_internal.h +16 -19
@@ -106,38 +106,40 @@ static inline void rproc_set_mcu_sync_state(struct rproc *rproc, } } +#define RPROC_OPS_HELPER (__operation, ...) \ + do { \ + if (rproc_sync_with_mcu(rproc) && \ + rproc->sync_ops && \ + rproc->sync_ops->__operation) \ + return rproc->sync_ops->__operation(__VA_ARGS__); \ + else if (rproc->ops && rproc->ops->__operation) \ + return rproc->ops->__operation(__VA_ARGS__); \ + } while (0) \ +static inline int rproc_fw_sanity_check (struct rproc *rproc,const struct firmware *fw) { -if (rproc->ops->sanity_check) -return rproc->ops->sanity_check (rproc, fw); - +RPROC_OPS_HELPER (sanity_check, rproc, fw);return 0 ; }static inline u32 rproc_get_boot_addr (struct rproc *rproc,const struct firmware *fw) { -if (rproc->ops->get_boot_addr) -return rproc->ops->get_boot_addr (rproc, fw); - +RPROC_OPS_HELPER (get_boot_addr, rproc, fw);return 0 ; }static inline int rproc_load_segments (struct rproc *rproc,const struct firmware *fw) { -if (rproc->ops->load) -return rproc->ops->load (rproc, fw); - +RPROC_OPS_HELPER (load, rproc, fw);return -EINVAL ; }static inline int rproc_parse_fw (struct rproc *rproc,const struct firmware *fw) { -if (rproc->ops->parse_fw) -return rproc->ops->parse_fw (rproc, fw); - +RPROC_OPS_HELPER (parse_fw, rproc, fw);return 0 ; }
@@ -145,10 +147,7 @@ static inlineint rproc_handle_rsc (struct rproc *rproc,u32 rsc_type,void *rsc,int offset,int avail) { -if (rproc->ops->handle_rsc) -return rproc->ops->handle_rsc (rproc, rsc_type, rsc, offset, - avail); - +RPROC_OPS_HELPER (handle_rsc, rproc, rsc_type, rsc, offset, avail);return RSC_IGNORED ; }
@@ -156,9 +155,7 @@ static inlinestruct resource_table *rproc_find_loaded_rsc_table (struct rproc *rproc,const struct firmware *fw) { -if (rproc->ops->find_loaded_rsc_table) -return rproc->ops->find_loaded_rsc_table (rproc, fw); - +RPROC_OPS_HELPER (find_loaded_rsc_table, rproc, fw);return NULL ; }
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 10/18 remoteproc: Decouple firmware load and remoteproc booting
In reply to Mathieu PoirierIn preparation to support scenarios where MCU firmware is loaded and the MCU itself booted by another entity, split function rproc_boot() to decouple the functions of loading the firwmare and starting the initialisation process. That way we can reuse the functionality provided by the current implementation without invariably dealing with firmware loading.
--- drivers/remoteproc/remoteproc_core.c | 63 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 24 deletions(-)
drivers/remoteproc/remoteproc_core.c +39 -24
@@ -1714,21 +1714,10 @@ static void rproc_crash_handler_work(struct work_struct *work)rproc_trigger_recovery (rproc); } -/** -* rproc_boot() - boot a remote processor -* @rproc: handle of a remote processor -* -* Boot a remote processor (i.e. load its firmware, power it on, ...). -* -* If the remote processor is already powered on, this function immediately -* returns (successfully). -* -* Returns 0 on success, and an appropriate error value otherwise. -*/ -int rproc_boot (struct rproc *rproc) +static int rproc_actuate (struct rproc *rproc, +const struct firmware *firmware_p) { -const struct firmware *firmware_p; -struct device *dev; +struct device *dev = &rproc->dev;int ret;if (!rproc) {
@@ -1736,8 +1725,6 @@ int rproc_boot(struct rproc *rproc)return -EINVAL ; } - dev = &rproc->dev; - ret =mutex_lock_interruptible (&rproc->lock);if (ret) {dev_err (dev,"can't lock rproc %s: %d\n" , rproc->name, ret);
@@ -1756,24 +1743,52 @@ int rproc_boot(struct rproc *rproc) goto unlock_mutex; } -dev_info (dev,"powering up %s\n" , rproc->name); +dev_info (dev,"%s %s\n" , + firmware_p ?"powering up" :"syncing with" , + rproc->name); + + ret =rproc_fw_boot (rproc, firmware_p); +if (ret) +atomic_dec (&rproc->power); + +unlock_mutex: +mutex_unlock (&rproc->lock); +return ret; +} + +/** +* rproc_boot() - boot a remote processor +* @rproc: handle of a remote processor +* +* Boot a remote processor (i.e. load its firmware, power it on, ...). +* +* If the remote processor is already powered on, this function immediately +* returns (successfully). +* +* Returns 0 on success, and an appropriate error value otherwise. +*/ +int rproc_boot (struct rproc *rproc) +{ +const struct firmware *firmware_p; +struct device *dev = &rproc->dev; +int ret; + +if (!rproc) { +pr_err ("invalid rproc handle\n" ); +return -EINVAL ; + }/* load firmware */ ret =request_firmware (&firmware_p, rproc->firmware, dev);if (ret <0 ) {dev_err (dev,"request_firmware failed: %d\n" , ret); - goto downref_rproc; +return ret; } - ret =rproc_fw_boot (rproc, firmware_p); + ret =rproc_actuate (rproc, firmware_p);release_firmware (firmware_p); -downref_rproc: -if (ret) -atomic_dec (&rproc->power); -unlock_mutex: -mutex_unlock (&rproc->lock);return ret; }EXPORT_SYMBOL (rproc_boot);
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 11/18 remoteproc: Repurpose function rproc_trigger_auto_boot()
In reply to Mathieu PoirierRepurpose function rproc_trigger_auto_boot() so that it can deal with scenarios where the MCU is already running. As such give it a new name to better represent the capabilities and add a call to rproc_actuate() if instructed by the platform code to synchronise with the MCU rather than boot it from scratch.
--- drivers/remoteproc/remoteproc_core.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/remoteproc/remoteproc_core.c +15 -3
@@ -51,6 +51,8 @@ static int rproc_alloc_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);static int rproc_release_carveout (struct rproc *rproc,struct rproc_mem_entry *mem); +static int rproc_actuate (struct rproc *rproc, +const struct firmware *firmware_p);/* Unique indices for remoteproc devices */ static DEFINE_IDA (rproc_dev_index);
@@ -1444,10 +1446,17 @@ static void rproc_auto_boot_callback(const struct firmware *fw, void *context)release_firmware (fw); } -static int rproc_trigger_auto_boot (struct rproc *rproc) +static int rproc_trigger_auto_initiate (struct rproc *rproc) {int ret; +/* +* The MCU is already booted, all we need to do is synchronise with it. +* No point dealing with a firmware image. +*/ +if (rproc_sync_with_mcu (rproc)) +return rproc_actuate (rproc,NULL ); +/* * We're initiating an asynchronous firmware loading, so we can * be built-in kernel code, without hanging the boot process.
@@ -1931,9 +1940,12 @@ int rproc_add(struct rproc *rproc)/* create debugfs entries */ rproc_create_debug_dir (rproc); -/* if rproc is marked always-on, request it to boot */ +/* +* if rproc is marked always-on, request it to boot or synchronise +* with it. +*/ if (rproc->auto_boot) { - ret =rproc_trigger_auto_boot (rproc); + ret =rproc_trigger_auto_initiate (rproc);if (ret <0 )return ret; }
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 12/18 remoteproc: Rename function rproc_fw_boot()
In reply to Mathieu PoirierRenaming function rproc_fw_boot() in order to better reflect the work that is done when supporting scenarios where the remoteproc core is synchronising with an MCU.
--- drivers/remoteproc/remoteproc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/remoteproc/remoteproc_core.c +3 -2
@@ -1363,7 +1363,8 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)/* * take a firmware and boot a remote processor with it. */ -static int rproc_fw_boot (struct rproc *rproc,const struct firmware *fw) +static int rproc_actuate_platform (struct rproc *rproc, +const struct firmware *fw) {struct device *dev = &rproc->dev;const char *name = rproc->firmware;
@@ -1756,7 +1757,7 @@ static int rproc_actuate(struct rproc *rproc, firmware_p ?"powering up" :"syncing with" , rproc->name); - ret =rproc_fw_boot (rproc, firmware_p); + ret =rproc_actuate_platform (rproc, firmware_p);if (ret)atomic_dec (&rproc->power);
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 13/18 remoteproc: Introducting new functions to start and stop an MCU
In reply to Mathieu PoirierAdd new functions to replace direct calling of rproc->ops->start() and rproc->ops->stop(). That way different behaviour can be played out when booting an MCU or synchronising with it.
--- drivers/remoteproc/remoteproc_core.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/remoteproc/remoteproc_core.c +3 -3
@@ -1330,7 +1330,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) }/* power up the remote processor */ - ret = rproc->ops->start (rproc); + ret =rproc_start_hw (rproc);if (ret) {dev_err (dev,"can't start rproc %s: %d\n" , rproc->name, ret); goto unprepare_subdevices;
@@ -1351,7 +1351,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)return 0 ; stop_rproc: - rproc->ops->stop (rproc); +rproc_stop_hw (rproc); unprepare_subdevices:rproc_unprepare_subdevices (rproc); reset_table_ptr:
@@ -1483,7 +1483,7 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc->table_ptr = rproc->cached_table;/* power off the remote processor */ - ret = rproc->ops->stop (rproc); + ret =rproc_stop_hw (rproc);if (ret) {dev_err (dev,"can't stop rproc: %d\n" , ret);return ret;
drivers/remoteproc/remoteproc_internal.h +12 -0
@@ -159,4 +159,16 @@ struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, return NULL; } +static inline int rproc_start_hw (struct rproc *rproc) +{ +RPROC_OPS_HELPER (start, rproc); +return -EINVAL ; +} + +static inline int rproc_stop_hw (struct rproc *rproc) +{ +RPROC_OPS_HELPER (stop, rproc); +return -EINVAL ; +} +#endif /* REMOTEPROC_INTERNAL_H */
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 14/18 remoteproc: Refactor function rproc_trigger_recovery()
In reply to Mathieu PoirierRefactor function rproc_trigger_recovery() in order to avoid reloading the fw image when synchronising with an MCU rather than booting it.
--- drivers/remoteproc/remoteproc_core.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/remoteproc/remoteproc_core.c +9 -7
@@ -1659,7 +1659,7 @@ static void rproc_coredump(struct rproc *rproc)*/ int rproc_trigger_recovery (struct rproc *rproc) { -const struct firmware *firmware_p; +const struct firmware *firmware_p =NULL ;struct device *dev = &rproc->dev;int ret;
@@ -1676,14 +1676,16 @@ int rproc_trigger_recovery(struct rproc *rproc)/* generate coredump */ rproc_coredump (rproc); -/* load firmware */ - ret =request_firmware (&firmware_p, rproc->firmware, dev); -if (ret <0 ) { -dev_err (dev,"request_firmware failed: %d\n" , ret); - goto unlock_mutex; +/* load firmware if need be */ +if (!rproc_sync_with_mcu (rproc)) { + ret =request_firmware (&firmware_p, rproc->firmware, dev); +if (ret <0 ) { +dev_err (dev,"request_firmware failed: %d\n" , ret); + goto unlock_mutex; + } } -/* boot the remote processor up again */ +/* boot up or synchronise with the remote processor again */ ret =rproc_start (rproc, firmware_p);release_firmware (firmware_p);
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 15/18 remoteproc: Correctly deal with MCU synchronisation when changing FW image
In reply to Mathieu PoirierThis patch prevents the firmware image from being displayed or changed when the remoteproc core is synchronising with an MCU. This is needed since there is no guarantee about the nature of the firmware image that is loaded by the external entity.
--- drivers/remoteproc/remoteproc_sysfs.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_sysfs.c +24 -1
@@ -13,9 +13,20 @@static ssize_t firmware_show (struct device *dev,struct device_attribute *attr,char *buf) { +ssize_t ret;struct rproc *rproc =to_rproc (dev); -return sprintf (buf,"%s\n" , rproc->firmware); +/* +* In most instances there is no guarantee about the firmware +* that was loaded by the external entity. As such simply don't +* print anything. +*/ +if (rproc_sync_with_mcu (rproc)) + ret =sprintf (buf,"\n" ); +else + ret =sprintf (buf,"%s\n" , rproc->firmware); + +return ret; }/* Change firmware name via sysfs */
@@ -33,6 +44,18 @@ static ssize_t firmware_store(struct device *dev,return -EINVAL ; } +/* +* There is no point in trying to change the firmware if the MCU +* is currently running or if loading of the image is done by +* another entity. +*/ +if (rproc_sync_with_mcu (rproc)) { +dev_err (dev, +"can't change firmware while synchronising with MCU\n" ); + err = -EBUSY ; + goto out; + } +if (rproc->state !=RPROC_OFFLINE ) {dev_err (dev,"can't change firmware while running\n" ); err = -EBUSY ;
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 16/18 remoteproc: Correctly deal with MCU synchronisation when changing state
In reply to Mathieu PoirierThis patch deals with state changes when synchronising with an MCU. More specifically it prevents the MCU from being started if it already has been started by another entity. Similarly it prevents the AP from stopping the MCU if it hasn't been given the capability by platform firmware.
--- drivers/remoteproc/remoteproc_sysfs.c | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_sysfs.c +31 -1
@@ -108,6 +108,29 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,return sprintf (buf,"%s\n" , rproc_state_string[state]); } +static int rproc_can_shutdown (struct rproc *rproc) +{ +/* The MCU is not running, obviously an invalid operation. */ +if (rproc->state !=RPROC_RUNNING ) +return false; + +/* +* The MCU is not running (see above) and the remoteproc core is the +* lifecycle manager, no problem calling for a shutdown. +*/ +if (!rproc_sync_with_mcu (rproc)) +return true; + +/* +* The MCU has been loaded by another entity (see above) and the +* platform code has _not_ given us the capability of stopping it. +*/ +if (!rproc->sync_ops->stop) +return false; + +return true; +} +/* Change remote processor state via sysfs */ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
@@ -120,11 +143,18 @@ static ssize_t state_store(struct device *dev,if (rproc->state ==RPROC_RUNNING )return -EBUSY ; +/* +* In synchronisation mode, booting the MCU is the +* responsibility of an external entity. +*/ +if (rproc_sync_with_mcu (rproc)) +return -EINVAL ; + ret =rproc_boot (rproc);if (ret)dev_err (&rproc->dev,"Boot failed: %d\n" , ret); }else if (sysfs_streq (buf,"stop" )) { -if (rproc->state !=RPROC_RUNNING ) +if (!rproc_can_shutdown (rproc))return -EINVAL ;rproc_shutdown (rproc);
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 17/18 remoteproc: Make MCU synchronisation state changes on stop and crashed
In reply to Mathieu PoirierCall on the MCU synchronisation state machine to determine the synchronisation status to enact when the MCU is either stop from sysfs or has crashed.
--- drivers/remoteproc/remoteproc_core.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/remoteproc/remoteproc_core.c +15 -0
@@ -1720,6 +1720,14 @@ static void rproc_crash_handler_work(struct work_struct *work)dev_err (dev,"handling crash #%u in %s\n" , ++rproc->crash_cnt, rproc->name); +/* +* The MCU has crashed - tell the core what operation to +* use from hereon, i.e whether an external entity will +* reboot the MCU or it is now the remoteproc core's +* responsability. +*/ +rproc_set_mcu_sync_state (rproc,RPROC_SYNC_STATE_CRASHED ); +mutex_unlock (&rproc->lock);if (!rproc->recovery_disabled)
@@ -1854,6 +1862,13 @@ void rproc_shutdown(struct rproc *rproc)kfree (rproc->cached_table); rproc->cached_table =NULL ; rproc->table_ptr =NULL ; + +/* +* The MCU has been switched off - tell the core what operation to +* use from hereon, i.e whether an external entity will reboot the +* MCU or it is now the remoteproc core's responsability. +*/ +rproc_set_mcu_sync_state (rproc,RPROC_SYNC_STATE_SHUTDOWN ); out:mutex_unlock (&rproc->lock); }
Signature · 1 line
2.20.1
Mathieu Poirier
maintainerPATCH 18/18 remoteproc: stm32: add support for co-processor booted before kernel
In reply to Mathieu PoirierFrom: Fabien Dessenne <[email protected]>
Refactoring of the work from Fabien Dessenne and Arnaud Pouliquen originally published here [1]. Provided as an example only.
Compiled tested but will likely crash horribly.
[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877
--- drivers/remoteproc/stm32_rproc.c | 207 ++++++++++++++++++++++++++++++- 1 file changed, 201 insertions(+), 6 deletions(-)
drivers/remoteproc/stm32_rproc.c +201 -6
@@ -38,6 +38,15 @@#define STM32_MBX_VQ1_ID 1#define STM32_MBX_SHUTDOWN "shutdown" +#define RSC_TBL_SIZE (1024) + +#define COPRO_STATE_OFF 0 +#define COPRO_STATE_INIT 1 +#define COPRO_STATE_CRUN 2 +#define COPRO_STATE_CSTOP 3 +#define COPRO_STATE_STANDBY 4 +#define COPRO_STATE_CRASH 5 +struct stm32_syscon {struct regmap *map;u32 reg;
@@ -70,12 +79,14 @@ struct stm32_rproc {struct reset_control *rst;struct stm32_syscon hold_boot;struct stm32_syscon pdds; +struct stm32_syscon copro_state;int wdg_irq;u32 nb_rmems;struct stm32_rproc_mem *rmems;struct stm32_mbox mb[MBOX_NB_MBX ];struct workqueue_struct *workqueue;bool secured_soc; +void __iomem *rsc_va; };static int stm32_rproc_pa_to_da (struct rproc *rproc,phys_addr_t pa,u64 *da)
@@ -98,6 +109,28 @@ static int stm32_rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64 *da)return -EINVAL ; } +static int stm32_rproc_da_to_pa (struct rproc *rproc,u64 da,phys_addr_t *pa) +{ +unsigned int i; +struct stm32_rproc *ddata = rproc->priv; +struct stm32_rproc_mem *p_mem; + +for (i =0 ; i < ddata->nb_rmems; i++) { + p_mem = &ddata->rmems[i]; + +if (da < p_mem->dev_addr || + da >= p_mem->dev_addr + p_mem->size) +continue ; + *pa = da - p_mem->dev_addr + p_mem->bus_addr; +dev_dbg (rproc->dev.parent,"da %llx to pa %#x\n" , da, *pa); +return 0 ; + } + +dev_err (rproc->dev.parent,"can't translate da %llx\n" , da); + +return -EINVAL ; +} +static int stm32_rproc_mem_alloc (struct rproc *rproc,struct rproc_mem_entry *mem) {
@@ -203,7 +236,17 @@ static int stm32_rproc_elf_load_rsc_table(struct rproc *rproc,return 0 ; } -static int stm32_rproc_parse_fw (struct rproc *rproc,const struct firmware *fw) +static struct resource_table * +stm32_rproc_elf_find_loaded_rsc_table_sync_mcu (struct rproc *rproc, +const struct firmware *fw) +{ +struct stm32_rproc *ddata = rproc->priv; + +return (struct resource_table *)ddata->rsc_va; +} + +static int __stm32_rproc_parse_fw (struct rproc *rproc, +const struct firmware *fw) {struct device *dev = rproc->dev.parent;struct device_node *np = dev->of_node;
@@ -256,9 +299,48 @@ static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) index++; } +return 0 ; +} + +static int stm32_rproc_parse_fw (struct rproc *rproc,const struct firmware *fw) +{ +int ret; + + ret =__stm32_rproc_parse_fw (rproc, fw); +return stm32_rproc_elf_load_rsc_table (rproc, fw); } +static int stm32_rproc_parse_fw_sync_mcu (struct rproc *rproc, +const struct firmware *fw) +{ +struct resource_table *table =NULL ; +struct stm32_rproc *ddata = rproc->priv; +int ret; + + ret =__stm32_rproc_parse_fw (rproc, fw); + +if (ddata->rsc_va) { + table = (struct resource_table *)ddata->rsc_va; +/* Assuming that the resource table fits in 1kB is fair */ + rproc->cached_table =kmemdup (table,RSC_TBL_SIZE ,GFP_KERNEL ); +if (!rproc->cached_table) +return -ENOMEM ; + + rproc->table_ptr = rproc->cached_table; + rproc->table_sz =RSC_TBL_SIZE ; +return 0 ; + } + + rproc->cached_table =NULL ; + rproc->table_ptr =NULL ; + rproc->table_sz =0 ; + +dev_warn (&rproc->dev,"no resource table found for this firmware\n" ); +return 0 ; +} + +static irqreturn_t stm32_rproc_wdg (int irq,void *data) {struct rproc *rproc = data;
@@ -429,6 +511,19 @@ static int stm32_rproc_start(struct rproc *rproc) } } +return stm32_rproc_set_hold_boot (rproc, true); +} + +static int stm32_rproc_start_sync_mcu (struct rproc *rproc) +{ +int err; + +stm32_rproc_add_coredump_trace (rproc); + +/* +* If M4 previously started by bootloader, just guarantee holdboot +* is set to catch any crash. +*/ err =stm32_rproc_set_hold_boot (rproc, false);if (err)return err;
@@ -476,6 +571,28 @@ static int stm32_rproc_stop(struct rproc *rproc)return 0 ; } +static int stm32_rproc_stop_sync_mcu (struct rproc *rproc) +{ +struct stm32_rproc *ddata = rproc->priv; +int err; + + err =stm32_rproc_stop (rproc); +if (err) +return err; + +/* update copro state to OFF */ + err =regmap_update_bits (ddata->copro_state.map, + ddata->copro_state.reg, + ddata->copro_state.mask, +COPRO_STATE_OFF ); +if (err) { +dev_err (&rproc->dev,"failed to set copro state\n" ); +return err; + } + +return 0 ; +} +static void stm32_rproc_kick (struct rproc *rproc,int vqid) {struct stm32_rproc *ddata = rproc->priv;
@@ -498,6 +615,14 @@ static void stm32_rproc_kick(struct rproc *rproc, int vqid) } } +static struct rproc_ops st_rproc_ops_sync_mcu = { + .start = stm32_rproc_start_sync_mcu, + .stop = stm32_rproc_stop_sync_mcu, + .kick = stm32_rproc_kick, + .parse_fw = stm32_rproc_parse_fw_sync_mcu, + .find_loaded_rsc_table = stm32_rproc_elf_find_loaded_rsc_table_sync_mcu, +}; +static struct rproc_ops st_rproc_ops = { .start = stm32_rproc_start, .stop = stm32_rproc_stop,
@@ -543,8 +668,10 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev)struct device_node *np = dev->of_node;struct rproc *rproc =platform_get_drvdata (pdev);struct stm32_rproc *ddata = rproc->priv; -struct stm32_syscon tz; -unsigned int tzen; +struct stm32_syscon tz, rsctbl; +phys_addr_t rsc_pa; +u32 rsc_da; +unsigned int tzen, state;int err, irq; irq =platform_get_irq (pdev,0 );
@@ -602,11 +729,72 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev) err =stm32_rproc_get_syscon (np,"st,syscfg-pdds" , &ddata->pdds);if (err) -dev_warn (dev,"failed to get pdds\n" ); +dev_warn (dev,"pdds not supported\n" ); rproc->auto_boot =of_property_read_bool (np,"st,auto-boot" ); -return stm32_rproc_of_memory_translations (rproc); + err =stm32_rproc_of_memory_translations (rproc); +if (err) +return err; + +/* check if the coprocessor has been started from the bootloader */ + err =stm32_rproc_get_syscon (np,"st,syscfg-copro-state" , + &ddata->copro_state); +if (err) { +/* no copro_state syscon (optional) */ +dev_warn (dev,"copro_state not supported\n" ); + goto bail; + } + + err =regmap_read (ddata->copro_state.map, ddata->copro_state.reg, + &state); +if (err) { +dev_err (&rproc->dev,"failed to read copro state\n" ); +return err; + } + +if (state ==COPRO_STATE_CRUN ) { +if (stm32_rproc_get_syscon (np,"st,syscfg-rsc-tbl" , &rsctbl)) { +/* no rsc table syscon (optional) */ +dev_warn (dev,"rsc tbl syscon not supported\n" ); + goto bail; + } + + err =regmap_read (rsctbl.map, rsctbl.reg, &rsc_da); +if (err) { +dev_err (&rproc->dev,"failed to read rsc tbl addr\n" ); +return err; + } +if (!rsc_da) +/* no rsc table */ + goto bail; + + err =stm32_rproc_da_to_pa (rproc, rsc_da, &rsc_pa); +if (err) +return err; + + ddata->rsc_va =devm_ioremap_wc (dev, rsc_pa,RSC_TBL_SIZE ); +if (IS_ERR_OR_NULL (ddata->rsc_va)) { +dev_err (dev,"Unable to map memory region: %pa+%zx\n" , + &rsc_pa,RSC_TBL_SIZE ); + ddata->rsc_va =NULL ; +return -ENOMEM ; + } + } +bail: +return 0 ; +} + +static struct rproc_sync_states stm32_sync_states = { + .on_init = true,/* sync with MCU when the kernel boots */ + .after_stop = false,/* don't sync with MCU if stopped from sysfs */ + .after_crash = false,/* don't sync with MCU after a crash */ +}; + +static bool stm32_sync_with_mcu (struct platform_device *pdev) +{ +/* Find something platform specific here */ +return true; }static int stm32_rproc_probe (struct platform_device *pdev)
@@ -621,7 +809,14 @@ static int stm32_rproc_probe(struct platform_device *pdev)if (ret)return ret; - rproc =rproc_alloc (dev, np->name, &st_rproc_ops,NULL ,sizeof (*ddata)); +if (stm32_sync_with_mcu (pdev)) + rproc =rproc_alloc (dev, np->name, &st_rproc_ops, +NULL ,sizeof (*ddata)); +else + rproc =rproc_alloc_state_machine (dev, np->name, &st_rproc_ops, + &st_rproc_ops_sync_mcu, + &stm32_sync_states,NULL , +sizeof (*ddata));if (!rproc)return -ENOMEM ;
Signature · 1 line
2.20.1