Skip to content

Commit 7310369

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 7310369

2 files changed

Lines changed: 27 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: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,8 @@ int rpmsg_virtio_get_tx_buffer_size(struct rpmsg_device *rdev)
743743
int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
744744
{
745745
struct rpmsg_virtio_device *rvdev;
746-
int size = 0;
746+
int size = 0, ret;
747+
uint32_t features = 0;
747748

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

771785
if (size <= 0)
@@ -831,6 +845,13 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
831845
}
832846

833847
if (VIRTIO_ROLE_IS_DEVICE(vdev)) {
848+
status = virtio_get_features(vdev, &features);
849+
if (status)
850+
return status;
851+
852+
if (features & (1 << VIRTIO_RPMSG_F_BUFSZ))
853+
rvdev->config = *config;
854+
834855
/* wait synchro with the host */
835856
status = rpmsg_virtio_wait_remote_ready(rvdev);
836857
if (status)

0 commit comments

Comments
 (0)