Skip to content

Commit

Permalink
openamp: divide shram to TX shram & RX shram by config:txrx_shpool
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jiuzhu Dong <[email protected]>
  • Loading branch information
Donny9 committed May 6, 2022
1 parent e4307e1 commit 9e9613c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 9 additions & 3 deletions lib/include/openamp/rpmsg_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct rpmsg_virtio_shm_pool {
struct rpmsg_virtio_config {
uint32_t h2r_buf_size;
uint32_t r2h_buf_size;
bool txrx_shpool;
};

/**
Expand Down Expand Up @@ -181,8 +182,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 - double pointer to shared memory pool array.
* If the config->txrx_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
Expand All @@ -191,7 +197,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
struct virtio_device *vdev,
rpmsg_ns_bind_cb ns_bind_cb,
struct metal_io_region *shm_io,
struct rpmsg_virtio_shm_pool *shpool,
struct rpmsg_virtio_shm_pool **shpool,
const struct rpmsg_virtio_config *config);

/**
Expand Down
14 changes: 8 additions & 6 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
(&(const struct rpmsg_virtio_config) { \
.h2r_buf_size = RPMSG_BUFFER_SIZE, \
.r2h_buf_size = RPMSG_BUFFER_SIZE, \
.txrx_shpool = false, \
})
#else
#define RPMSG_VIRTIO_DEFAULT_CONFIG NULL
Expand Down Expand Up @@ -625,14 +626,14 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
struct rpmsg_virtio_shm_pool *shpool)
{
return rpmsg_init_vdev_with_config(rvdev, vdev, ns_bind_cb, shm_io,
shpool, RPMSG_VIRTIO_DEFAULT_CONFIG);
&shpool, RPMSG_VIRTIO_DEFAULT_CONFIG);
}

int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
struct virtio_device *vdev,
rpmsg_ns_bind_cb ns_bind_cb,
struct metal_io_region *shm_io,
struct rpmsg_virtio_shm_pool *shpool,
struct rpmsg_virtio_shm_pool **shpool,
const struct rpmsg_virtio_config *config)
{
struct rpmsg_device *rdev;
Expand Down Expand Up @@ -686,11 +687,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.
*/
if (!shpool)
if (!shpool[0] || (config->txrx_shpool && !shpool[1]))
return RPMSG_ERR_PARAM;
if (!shpool->size)
if (!shpool[0]->size || (config->txrx_shpool && !shpool[1]->size))
return RPMSG_ERR_NO_BUFF;
rvdev->shpool = shpool;
rvdev->shpool = shpool[0];

vq_names[0] = "rx_vq";
vq_names[1] = "tx_vq";
Expand Down Expand Up @@ -743,7 +744,8 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
vqbuf.len = rvdev->config.r2h_buf_size;
for (idx = 0; idx < rvdev->rvq->vq_nentries; idx++) {
/* Initialize TX virtqueue buffers for remote device */
buffer = rpmsg_virtio_shm_pool_get_buffer(shpool,
buffer = rpmsg_virtio_shm_pool_get_buffer(
shpool[config->txrx_shpool ? 1 : 0],
rvdev->config.r2h_buf_size);

if (!buffer) {
Expand Down

0 comments on commit 9e9613c

Please sign in to comment.