ipc: rpmsg_multi_instance: Rework instance tracking

This patch is the first step to make the rpmsg_multi_instance usable in
a multi-core scenario.

The current driver is using a local driver variable (instance) to track
the number of allocated instances. This counter is practically used to
allocate to the instance the correct portion of the shared memory.

This is fundamentally wrong because this is assuming that it does exist
only one single shared memory region to split amongs all the allocated
instances.  When the platform has more than one core this is obviously
not the case since each couple of cores are communicating using a
different memory region.

To solve this issue we introduce a new struct rpmsg_mi_ctx_shm_cfg that
is doing two things: (1) it's carrying the information about the shared
memory and (2) it's carrying an internal variable used to track the
instances allocated in that region. The same struct should be used every
time a new instance is allocated in the same shared memory region.

We also fix a problem with the current code where there is a race
between threads when accessing the instance variable, so this patch is
adding a serializing mutex.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
This commit is contained in:
Carlo Caione 2021-07-30 12:02:27 +02:00 committed by Christopher Friedt
commit 0c2dabb4b9
5 changed files with 65 additions and 37 deletions

View file

@ -117,18 +117,23 @@ struct rpmsg_mi_ctx {
sys_slist_t endpoints;
};
struct rpmsg_mi_ctx_shm_cfg {
/** Physical address shared memory region. */
uintptr_t addr;
/** Size shared memory region. */
size_t size;
/** Internal counter. */
unsigned int instance;
};
/** @brief Configuration of the RPMsg instance. */
struct rpmsg_mi_ctx_cfg {
/** Name of instance. */
const char *name;
/** Physical address shared memory region. */
uintptr_t shm_addr;
/** Size shared memory region. */
size_t shm_size;
/** Stack area for k_work_q. */
k_thread_stack_t *ipm_stack_area;
@ -149,6 +154,9 @@ struct rpmsg_mi_ctx_cfg {
/** IPM message identifier. */
unsigned int ipm_tx_id;
/** SHM struct. */
struct rpmsg_mi_ctx_shm_cfg *shm;
};
/** @brief Initialization of RPMsg instance.