Skip to content

Commit 7c0b658

Browse files
committed
rpmsg_virtio: add new virtio feature bit
Introduce new feature bit that allows rpmsg buffer size via virtio device config space. If the feature is available then, driver will set single rpmsg buffer size from virtio device config space in the resource table. 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 BUFSZ feature bit is set, then use rx buffer size from the virtio config space in the resource table. Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
1 parent 6def535 commit 7c0b658

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

lib/include/openamp/rpmsg_virtio.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <metal/io.h>
1616
#include <metal/mutex.h>
1717
#include <metal/cache.h>
18+
#include <metal/compiler.h>
1819
#include <openamp/rpmsg.h>
1920
#include <openamp/virtio.h>
2021

@@ -29,6 +30,7 @@ extern "C" {
2930

3031
/* The feature bitmap for virtio rpmsg */
3132
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
33+
#define VIRTIO_RPMSG_F_BUFSZ 1 /* fw provides tx and rx single buf size */
3234

3335
#if defined(VIRTIO_USE_DCACHE)
3436
#define BUFFER_FLUSH(x, s) metal_cache_flush(x, s)
@@ -59,7 +61,13 @@ struct rpmsg_virtio_shm_pool {
5961
* This structure is used by the RPMsg virtio host to configure the virtiio
6062
* layer.
6163
*/
64+
METAL_PACKED_BEGIN
6265
struct rpmsg_virtio_config {
66+
/** version of this struct */
67+
uint8_t version;
68+
69+
/** size of the config space */
70+
uint16_t size;
6371
/** The size of the buffer used to send data from host to remote */
6472
uint32_t h2r_buf_size;
6573

@@ -68,7 +76,7 @@ struct rpmsg_virtio_config {
6876

6977
/** The flag for splitting shared memory pool to TX and RX */
7078
bool split_shpool;
71-
};
79+
} METAL_PACKED_END;
7280

7381
/** @brief Representation of a RPMsg device based on virtio */
7482
struct rpmsg_virtio_device {

lib/rpmsg/rpmsg_virtio.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ struct vbuff_reclaimer_t {
6262
#if VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT)
6363
#define RPMSG_VIRTIO_DEFAULT_CONFIG \
6464
(&(const struct rpmsg_virtio_config) { \
65+
.version = 1, \
66+
.size = sizeof(struct rpmsg_virtio_config), \
6567
.h2r_buf_size = RPMSG_BUFFER_SIZE, \
6668
.r2h_buf_size = RPMSG_BUFFER_SIZE, \
6769
.split_shpool = false, \
@@ -742,7 +744,8 @@ int rpmsg_virtio_get_tx_buffer_size(struct rpmsg_device *rdev)
742744
int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
743745
{
744746
struct rpmsg_virtio_device *rvdev;
745-
int size = 0;
747+
int size = 0, ret;
748+
uint32_t features = 0;
746749

747750
if (!rdev)
748751
return RPMSG_ERR_PARAM;
@@ -762,9 +765,22 @@ int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
762765
/*
763766
* If other core is host then buffers are provided by it,
764767
* 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.
765770
*/
766-
size = (int)virtqueue_get_desc_size(rvdev->rvq) -
767-
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+
}
768784
}
769785

770786
if (size <= 0)
@@ -830,6 +846,13 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
830846
}
831847

832848
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+
833856
/* wait synchro with the host */
834857
status = rpmsg_virtio_wait_remote_ready(rvdev);
835858
if (status)

0 commit comments

Comments
 (0)