Skip to content

Commit 3474c42

Browse files
committed
rpmsg: rpmsg_virtio: fix API to get rx buf
New virtio feature allows to configure rpmsg single buffer size via virtio device config space. Hence, rx buffer size can be provided by vdev device config space as well. If failed to calculate rx buf size using vq descriptor, and rx buf size is available in the config space, then use it from there. Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
1 parent 5ac8096 commit 3474c42

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

lib/include/openamp/rpmsg_virtio.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ struct rpmsg_virtio_shm_pool {
6464
METAL_PACKED_BEGIN
6565
struct rpmsg_virtio_config {
6666
/** version of this struct */
67-
uint16_t version;
67+
uint8_t version;
6868

69+
/** size of the config space */
70+
uint16_t size;
6971
/** The size of the buffer used to send data from host to remote */
7072
uint32_t h2r_buf_size;
7173

lib/rpmsg/rpmsg_virtio.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct vbuff_reclaimer_t {
6363
#define RPMSG_VIRTIO_DEFAULT_CONFIG \
6464
(&(const struct rpmsg_virtio_config) { \
6565
.version = 1, \
66+
.size = sizeof(struct rpmsg_virtio_config) , \
6667
.h2r_buf_size = RPMSG_BUFFER_SIZE, \
6768
.r2h_buf_size = RPMSG_BUFFER_SIZE, \
6869
.split_shpool = false, \
@@ -743,7 +744,8 @@ int rpmsg_virtio_get_tx_buffer_size(struct rpmsg_device *rdev)
743744
int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
744745
{
745746
struct rpmsg_virtio_device *rvdev;
746-
int size = 0;
747+
int size = 0, ret;
748+
uint32_t features = 0;
747749

748750
if (!rdev)
749751
return RPMSG_ERR_PARAM;
@@ -763,9 +765,22 @@ int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
763765
/*
764766
* If other core is host then buffers are provided by it,
765767
* so get the buffer size from the virtqueue.
768+
* If virtio device has BUFSZ feature, then the rx buffer is
769+
* provided by the vdev config space in the resource table.
766770
*/
767-
size = (int)virtqueue_get_desc_size(rvdev->rvq) -
768-
sizeof(struct rpmsg_hdr);
771+
features = 0;
772+
ret = virtio_get_features(rvdev->vdev, &features);
773+
if (ret) {
774+
metal_mutex_release(&rdev->lock);
775+
return RPMSG_ERR_DEV_STATE;
776+
}
777+
778+
if (features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
779+
size = rvdev->config.r2h_buf_size - sizeof(struct rpmsg_hdr);
780+
} else {
781+
size = (int)virtqueue_get_desc_size(rvdev->rvq) -
782+
sizeof(struct rpmsg_hdr);
783+
}
769784
}
770785

771786
if (size <= 0)
@@ -831,6 +846,13 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
831846
}
832847

833848
if (VIRTIO_ROLE_IS_DEVICE(vdev)) {
849+
status = virtio_get_features(vdev, &features);
850+
if (status)
851+
return status;
852+
853+
if (features & (1 << VIRTIO_RPMSG_F_BUFSZ))
854+
rvdev->config = *config;
855+
834856
/* wait synchro with the host */
835857
status = rpmsg_virtio_wait_remote_ready(rvdev);
836858
if (status)

0 commit comments

Comments
 (0)