diff --git a/lib/include/openamp/rpmsg_virtio.h b/lib/include/openamp/rpmsg_virtio.h index 528b9bfc3..ad4fc27c2 100644 --- a/lib/include/openamp/rpmsg_virtio.h +++ b/lib/include/openamp/rpmsg_virtio.h @@ -28,6 +28,16 @@ extern "C" { /* The feature bitmap for virtio rpmsg */ #define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ +#define VIRTIO_RPMSG_F_BUFSZ 2 /* RP supports get buffer size from config space */ + +OPENAMP_PACKED_BEGIN +struct virtio_rpmsg_config { + /* The tx/rx individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */ + uint32_t txbuf_size; + uint32_t rxbuf_size; + uint32_t reserved[14]; /* Reserve for the future use */ + /* Put the customize config here */ +} OPENAMP_PACKED_END; /** * struct rpmsg_virtio_shm_pool - shared memory pool used for rpmsg buffers @@ -44,6 +54,7 @@ struct rpmsg_virtio_shm_pool { /** * struct rpmsg_virtio_device - representation of a rpmsg device based on virtio * @rdev: rpmsg device, first property in the struct + * @config: rpmsg config information * @vdev: pointer to the virtio device * @rvq: pointer to receive virtqueue * @svq: pointer to send virtqueue @@ -52,6 +63,7 @@ struct rpmsg_virtio_shm_pool { */ struct rpmsg_virtio_device { struct rpmsg_device rdev; + struct virtio_rpmsg_config config; struct virtio_device *vdev; struct virtqueue *rvq; struct virtqueue *svq; @@ -85,6 +97,13 @@ rpmsg_virtio_get_features(struct rpmsg_virtio_device *rvdev) return rvdev->vdev->func->get_features(rvdev->vdev); } +static inline void +rpmsg_virtio_read_config(struct rpmsg_virtio_device *rvdev, + uint32_t offset, void *dst, int length) +{ + rvdev->vdev->func->read_config(rvdev->vdev, offset, dst, length); +} + static inline int rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev, int flags, unsigned int nvqs, diff --git a/lib/rpmsg/rpmsg_virtio.c b/lib/rpmsg/rpmsg_virtio.c index c86e2b34f..b4572149b 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ b/lib/rpmsg/rpmsg_virtio.c @@ -145,8 +145,8 @@ static void *rpmsg_virtio_get_tx_buffer(struct rpmsg_virtio_device *rvdev, data = virtqueue_get_buffer(rvdev->svq, len, idx); if (data == NULL) { data = rpmsg_virtio_shm_pool_get_buffer(rvdev->shpool, - RPMSG_BUFFER_SIZE); - *len = RPMSG_BUFFER_SIZE; + rvdev->config.rxbuf_size); + *len = rvdev->config.rxbuf_size; } } #endif /*!VIRTIO_SLAVE_ONLY*/ @@ -240,7 +240,7 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev) * If device role is Master then buffers are provided by us, * so just provide the macro. */ - length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr); + length = rvdev->config.rxbuf_size - sizeof(struct rpmsg_hdr); } #endif /*!VIRTIO_SLAVE_ONLY*/ @@ -528,7 +528,10 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, rvdev->vdev = vdev; rdev->ns_bind_cb = ns_bind_cb; vdev->priv = rvdev; + rvdev->config.txbuf_size = RPMSG_BUFFER_SIZE; + rvdev->config.rxbuf_size = RPMSG_BUFFER_SIZE; rdev->ops.send_offchannel_raw = rpmsg_virtio_send_offchannel_raw; + role = rpmsg_virtio_get_role(rvdev); #ifndef VIRTIO_MASTER_ONLY @@ -540,6 +543,13 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, vdev->features = rpmsg_virtio_get_features(rvdev); rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS)); + if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) { + rpmsg_virtio_read_config(rvdev, + 0, + &rvdev->config, + sizeof(rvdev->config)); + } + #ifndef VIRTIO_SLAVE_ONLY if (role == RPMSG_MASTER) { /* @@ -600,11 +610,11 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, unsigned int idx; void *buffer; - vqbuf.len = RPMSG_BUFFER_SIZE; + vqbuf.len = rvdev->config.txbuf_size; for (idx = 0; idx < rvdev->rvq->vq_nentries; idx++) { /* Initialize TX virtqueue buffers for remote device */ buffer = rpmsg_virtio_shm_pool_get_buffer(shpool, - RPMSG_BUFFER_SIZE); + rvdev->config.txbuf_size); if (!buffer) { return RPMSG_ERR_NO_BUFF; @@ -615,7 +625,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, metal_io_block_set(shm_io, metal_io_virt_to_offset(shm_io, buffer), - 0x00, RPMSG_BUFFER_SIZE); + 0x00, rvdev->config.txbuf_size); status = virtqueue_add_buffer(rvdev->rvq, &vqbuf, 0, 1, buffer);