Skip to content

Commit 30fc4ff

Browse files
author
Hubert Miś
committed
rpmsg_virtio: configuration option to set buffer sizes per instance
Enable user of rpmsg_virtio to set sizes of TX and RX buffers per created rpmsg_virtio instance. Each instance can use other buffer sizes. Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
1 parent f7640de commit 30fc4ff

2 files changed

Lines changed: 68 additions & 7 deletions

File tree

lib/include/openamp/rpmsg_virtio.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@ struct rpmsg_virtio_shm_pool {
4141
size_t size;
4242
};
4343

44+
/**
45+
* struct rpmsg_virtio_config - configuration of rpmsg device based on virtio
46+
* @txbuf_size: the tx buffer size, used to send data from host to remote
47+
* @rxbuf_size: the rx buffer size, used to send data from remote to host
48+
*/
49+
struct rpmsg_virtio_config {
50+
uint32_t txbuf_size;
51+
uint32_t rxbuf_size;
52+
};
53+
4454
/**
4555
* struct rpmsg_virtio_device - representation of a rpmsg device based on virtio
4656
* @rdev: rpmsg device, first property in the struct
4757
* @vdev: pointer to the virtio device
58+
* @config: structure containing device configuration
4859
* @rvq: pointer to receive virtqueue
4960
* @svq: pointer to send virtqueue
5061
* @shbuf_io: pointer to the shared buffer I/O region
@@ -53,6 +64,7 @@ struct rpmsg_virtio_shm_pool {
5364
struct rpmsg_virtio_device {
5465
struct rpmsg_device rdev;
5566
struct virtio_device *vdev;
67+
struct rpmsg_virtio_config config;
5668
struct virtqueue *rvq;
5769
struct virtqueue *svq;
5870
struct metal_io_region *shbuf_io;
@@ -145,6 +157,36 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
145157
struct metal_io_region *shm_io,
146158
struct rpmsg_virtio_shm_pool *shpool);
147159

160+
/**
161+
* rpmsg_init_vdev_with_config - initialize rpmsg virtio device
162+
* Master side:
163+
* Initialize RPMsg virtio queues and shared buffers, the address of shm can be
164+
* ANY. In this case, function will get shared memory from system shared memory
165+
* pools. If the vdev has RPMsg name service feature, this API will create an
166+
* name service endpoint.
167+
*
168+
* Slave side:
169+
* This API will not return until the driver ready is set by the master side.
170+
*
171+
* @param rvdev - pointer to the rpmsg virtio device
172+
* @param vdev - pointer to the virtio device
173+
* @param ns_bind_cb - callback handler for name service announcement without
174+
* local endpoints waiting to bind.
175+
* @param shm_io - pointer to the share memory I/O region.
176+
* @param shpool - pointer to shared memory pool. rpmsg_virtio_init_shm_pool has
177+
* to be called first to fill this structure.
178+
* @param config - pointer to configuration structure, if NULL default
179+
* configuration is used like in @ref rpmsg_init_vdev
180+
*
181+
* @return - status of function execution
182+
*/
183+
int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
184+
struct virtio_device *vdev,
185+
rpmsg_ns_bind_cb ns_bind_cb,
186+
struct metal_io_region *shm_io,
187+
struct rpmsg_virtio_shm_pool *shpool,
188+
const struct rpmsg_virtio_config *config);
189+
148190
/**
149191
* rpmsg_deinit_vdev - deinitialize rpmsg virtio device
150192
*

lib/rpmsg/rpmsg_virtio.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* All rights reserved.
44
* Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
55
* Copyright (c) 2018 Linaro, Inc. All rights reserved.
6+
* Copyright (c) 2021 Nordic Semiconductor ASA
67
*
78
* SPDX-License-Identifier: BSD-3-Clause
89
*/
@@ -151,8 +152,8 @@ static void *rpmsg_virtio_get_tx_buffer(struct rpmsg_virtio_device *rvdev,
151152
data = virtqueue_get_buffer(rvdev->svq, len, idx);
152153
if (!data && rvdev->svq->vq_free_cnt) {
153154
data = rpmsg_virtio_shm_pool_get_buffer(rvdev->shpool,
154-
RPMSG_BUFFER_SIZE);
155-
*len = RPMSG_BUFFER_SIZE;
155+
rvdev->config.txbuf_size);
156+
*len = rvdev->config.txbuf_size;
156157
*idx = 0;
157158
}
158159
}
@@ -250,7 +251,7 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev)
250251
* If device role is Master then buffers are provided by us,
251252
* so just provide the macro.
252253
*/
253-
length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr);
254+
length = rvdev->config.txbuf_size - sizeof(struct rpmsg_hdr);
254255
}
255256
#endif /*!VIRTIO_SLAVE_ONLY*/
256257

@@ -384,7 +385,7 @@ static int rpmsg_virtio_send_offchannel_nocopy(struct rpmsg_device *rdev,
384385

385386
#ifndef VIRTIO_SLAVE_ONLY
386387
if (rpmsg_virtio_get_role(rvdev) == RPMSG_MASTER)
387-
buff_len = RPMSG_BUFFER_SIZE;
388+
buff_len = rvdev->config.txbuf_size;
388389
else
389390
#endif /*!VIRTIO_SLAVE_ONLY*/
390391
buff_len = virtqueue_get_buffer_length(rvdev->svq, idx);
@@ -610,6 +611,17 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
610611
rpmsg_ns_bind_cb ns_bind_cb,
611612
struct metal_io_region *shm_io,
612613
struct rpmsg_virtio_shm_pool *shpool)
614+
{
615+
return rpmsg_init_vdev_with_config(rvdev, vdev, ns_bind_cb, shm_io,
616+
shpool, NULL);
617+
}
618+
619+
int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
620+
struct virtio_device *vdev,
621+
rpmsg_ns_bind_cb ns_bind_cb,
622+
struct metal_io_region *shm_io,
623+
struct rpmsg_virtio_shm_pool *shpool,
624+
const struct rpmsg_virtio_config *config)
613625
{
614626
struct rpmsg_device *rdev;
615627
const char *vq_names[RPMSG_NUM_VRINGS];
@@ -630,6 +642,13 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
630642
rdev->ops.send_offchannel_nocopy = rpmsg_virtio_send_offchannel_nocopy;
631643
role = rpmsg_virtio_get_role(rvdev);
632644

645+
if (config) {
646+
rvdev->config = *config;
647+
} else {
648+
rvdev->config.txbuf_size = RPMSG_BUFFER_SIZE;
649+
rvdev->config.rxbuf_size = RPMSG_BUFFER_SIZE;
650+
}
651+
633652
#ifndef VIRTIO_MASTER_ONLY
634653
if (role == RPMSG_REMOTE) {
635654
/* wait synchro with the master */
@@ -699,11 +718,11 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
699718
unsigned int idx;
700719
void *buffer;
701720

702-
vqbuf.len = RPMSG_BUFFER_SIZE;
721+
vqbuf.len = rvdev->config.rxbuf_size;
703722
for (idx = 0; idx < rvdev->rvq->vq_nentries; idx++) {
704723
/* Initialize TX virtqueue buffers for remote device */
705724
buffer = rpmsg_virtio_shm_pool_get_buffer(shpool,
706-
RPMSG_BUFFER_SIZE);
725+
rvdev->config.rxbuf_size);
707726

708727
if (!buffer) {
709728
return RPMSG_ERR_NO_BUFF;
@@ -714,7 +733,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
714733
metal_io_block_set(shm_io,
715734
metal_io_virt_to_offset(shm_io,
716735
buffer),
717-
0x00, RPMSG_BUFFER_SIZE);
736+
0x00, rvdev->config.rxbuf_size);
718737
status =
719738
virtqueue_add_buffer(rvdev->rvq, &vqbuf, 0, 1,
720739
buffer);

0 commit comments

Comments
 (0)