Skip to content

Commit

Permalink
rpmsg_virtio: fix the rpmsg_get_tx/rx_buffer() api
Browse files Browse the repository at this point in the history
user tx/rx buffer size = orignal tx/rx buffer_size - sizeof(rpmsg_hdr)

And use buffer size in config to calculate the user buffer size instead
the buffer size from virtqueue, because there may be no buffer in virtqueeu.

Signed-off-by: Tao Yin <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
  • Loading branch information
CV-Bowen committed Nov 4, 2024
1 parent 71887e7 commit f113099
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,22 +714,11 @@ int rpmsg_virtio_get_tx_buffer_size(struct rpmsg_device *rdev)
metal_mutex_acquire(&rdev->lock);
rvdev = (struct rpmsg_virtio_device *)rdev;

if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev)) {
/*
* If device role is host then buffers are provided by us,
* so just provide the macro.
*/
if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev))
size = rvdev->config.h2r_buf_size - sizeof(struct rpmsg_hdr);
}

if (VIRTIO_ROLE_IS_DEVICE(rvdev->vdev)) {
/*
* If other core is host then buffers are provided by it,
* so get the buffer size from the virtqueue.
*/
size = (int)virtqueue_get_desc_size(rvdev->svq) -
sizeof(struct rpmsg_hdr);
}
if (VIRTIO_ROLE_IS_DEVICE(rvdev->vdev))
size = rvdev->config.r2h_buf_size - sizeof(struct rpmsg_hdr);

if (size <= 0)
size = RPMSG_ERR_NO_BUFF;
Expand All @@ -750,22 +739,11 @@ int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
metal_mutex_acquire(&rdev->lock);
rvdev = (struct rpmsg_virtio_device *)rdev;

if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev)) {
/*
* If device role is host then buffers are provided by us,
* so just provide the macro.
*/
if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev))
size = rvdev->config.r2h_buf_size - sizeof(struct rpmsg_hdr);
}

if (VIRTIO_ROLE_IS_DEVICE(rvdev->vdev)) {
/*
* If other core is host then buffers are provided by it,
* so get the buffer size from the virtqueue.
*/
size = (int)virtqueue_get_desc_size(rvdev->rvq) -
sizeof(struct rpmsg_hdr);
}
if (VIRTIO_ROLE_IS_DEVICE(rvdev->vdev))
size = rvdev->config.h2r_buf_size - sizeof(struct rpmsg_hdr);

if (size <= 0)
size = RPMSG_ERR_NO_BUFF;
Expand Down

0 comments on commit f113099

Please sign in to comment.