From f78dba2ad39ec4f97e657b214f64f1d7f834729b Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Fri, 6 May 2022 10:41:57 +0800 Subject: [PATCH] openamp: divide shram to TX shram & RX shram by config:split_shpool In the multi core of lower power device, when one of core enters sleep, it needs to put its corresponding share memory into retention mode to save power consumption. Based on the limitations of the chip design, when the CPU to which share memory belongs goes to sleep, the share memory enters the retention mode, and other cores will not be able to access it. When the share memory divides tx shm and rx shm and the core of tx shm and rx shm are different, so that when one CPU sleeps, the other CPU can still access its own tx shm. Signed-off-by: Guiding Li Signed-off-by: Jiuzhu Dong --- lib/include/openamp/rpmsg_virtio.h | 11 +++++++++-- lib/rpmsg/rpmsg_virtio.c | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/include/openamp/rpmsg_virtio.h b/lib/include/openamp/rpmsg_virtio.h index ff1e17119..f86da3ad3 100644 --- a/lib/include/openamp/rpmsg_virtio.h +++ b/lib/include/openamp/rpmsg_virtio.h @@ -49,10 +49,12 @@ struct rpmsg_virtio_shm_pool { * * @h2r_buf_size: the size of the buffer used to send data from host to remote * @r2h_buf_size: the size of the buffer used to send data from remote to host + * @split_shpool: the flag that splitting share memory pool to TX and RX */ struct rpmsg_virtio_config { uint32_t h2r_buf_size; uint32_t r2h_buf_size; + bool split_shpool; }; /** @@ -196,8 +198,13 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, * @param ns_bind_cb - callback handler for name service announcement without * local endpoints waiting to bind. * @param shm_io - pointer to the share memory I/O region. - * @param shpool - pointer to shared memory pool. rpmsg_virtio_init_shm_pool has - * to be called first to fill this structure. + * @param shpool - pointer to shared memory pool array. + * If the config->split_shpool is turn on, the array will contain + * two elements, the shpool of txshpool and rxshpool, Otherwise, + * the array has only one element, and txshpool rxshpool shares + * a shpool. + * And rpmsg_virtio_init_shm_pool has to be called first to fill + * each shpool in this array. * @param config - pointer to configuration structure * * @return - status of function execution diff --git a/lib/rpmsg/rpmsg_virtio.c b/lib/rpmsg/rpmsg_virtio.c index cd08f40b7..265547006 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ b/lib/rpmsg/rpmsg_virtio.c @@ -32,6 +32,7 @@ (&(const struct rpmsg_virtio_config) { \ .h2r_buf_size = RPMSG_BUFFER_SIZE, \ .r2h_buf_size = RPMSG_BUFFER_SIZE, \ + .split_shpool = false, \ }) #else #define RPMSG_VIRTIO_DEFAULT_CONFIG NULL @@ -689,11 +690,11 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev, * Since device is RPMSG Remote so we need to manage the * shared buffers. Create shared memory pool to handle buffers. */ + rvdev->shpool = config->split_shpool ? shpool + 1 : shpool; if (!shpool) return RPMSG_ERR_PARAM; - if (!shpool->size) + if (!shpool->size || !rvdev->shpool->size) return RPMSG_ERR_NO_BUFF; - rvdev->shpool = shpool; vq_names[0] = "rx_vq"; vq_names[1] = "tx_vq";