Skip to content

Commit 95d089c

Browse files
anchaoxiaoxiang781216
authored andcommitted
Negotiate individual buffer size dynamically
If slave support VIRTIO_RPMSG_F_BUFSZ(0x04) feature, master determine the buffer size from config space(first 4 bytes), otherwise the default size(512 bytes) will be used. Signed-off-by: anchao <anchao@pinecone.net>
1 parent 6019d74 commit 95d089c

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

lib/include/openamp/rpmsg_virtio.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ extern "C" {
2727
#endif
2828

2929
/* The feature bitmap for virtio rpmsg */
30-
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
30+
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
31+
#define VIRTIO_RPMSG_F_BUFSZ 2 /* RP supports get buffer size from config space */
3132

3233
struct rpmsg_virtio_shm_pool;
3334
/**
@@ -52,6 +53,7 @@ struct rpmsg_virtio_shm_pool {
5253
* @shbuf_io: pointer to the shared buffer I/O region
5354
* @shpool: pointer to the shared buffers pool
5455
* @endpoints: list of endpoints.
56+
* @shbuf_size: size of each rpmsg buffer
5557
*/
5658
struct rpmsg_virtio_device {
5759
struct rpmsg_device rdev;
@@ -60,6 +62,7 @@ struct rpmsg_virtio_device {
6062
struct virtqueue *svq;
6163
struct metal_io_region *shbuf_io;
6264
struct rpmsg_virtio_shm_pool *shpool;
65+
uint32_t shbuf_size;
6366
};
6467

6568
#define RPMSG_REMOTE VIRTIO_DEV_SLAVE
@@ -87,6 +90,13 @@ static inline uint32_t
8790
return rvdev->vdev->func->get_features(rvdev->vdev);
8891
}
8992

93+
static inline void
94+
rpmsg_virtio_read_config(struct rpmsg_virtio_device *rvdev,
95+
uint32_t offset, void *dst, int length)
96+
{
97+
rvdev->vdev->func->read_config(rvdev->vdev, offset, dst, length);
98+
}
99+
90100
static inline int
91101
rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev,
92102
int flags, unsigned int nvqs,

lib/rpmsg/rpmsg_virtio.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ static void *rpmsg_virtio_get_tx_buffer(struct rpmsg_virtio_device *rvdev,
151151
data = virtqueue_get_buffer(rvdev->svq, (uint32_t *)len, idx);
152152
if (data == NULL) {
153153
data = rpmsg_virtio_shm_pool_get_buffer(rvdev->shpool,
154-
RPMSG_BUFFER_SIZE);
155-
*len = RPMSG_BUFFER_SIZE;
154+
rvdev->shbuf_size);
155+
*len = rvdev->shbuf_size;
156156
}
157157
}
158158
#endif /*!VIRTIO_SLAVE_ONLY*/
@@ -258,7 +258,7 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev)
258258
* If device role is Remote then buffers are provided by us
259259
* (RPMSG Master), so just provide the macro.
260260
*/
261-
length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr);
261+
length = rvdev->shbuf_size - sizeof(struct rpmsg_hdr);
262262
}
263263
#endif /*!VIRTIO_SLAVE_ONLY*/
264264

@@ -545,6 +545,14 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
545545
rdev->ns_bind_cb = ns_bind_cb;
546546
vdev->priv = rvdev;
547547
rdev->ops.send_offchannel_raw = rpmsg_virtio_send_offchannel_raw;
548+
549+
if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
550+
rpmsg_virtio_read_config(rvdev, 0,
551+
&rvdev->shbuf_size,
552+
sizeof(rvdev->shbuf_size));
553+
} else
554+
rvdev->shbuf_size = RPMSG_BUFFER_SIZE;
555+
548556
role = rpmsg_virtio_get_role(rvdev);
549557

550558
#ifndef VIRTIO_SLAVE_ONLY
@@ -608,11 +616,11 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
608616
unsigned int idx;
609617
void *buffer;
610618

611-
vqbuf.len = RPMSG_BUFFER_SIZE;
619+
vqbuf.len = rvdev->shbuf_size;
612620
for (idx = 0; idx < rvdev->rvq->vq_nentries; idx++) {
613621
/* Initialize TX virtqueue buffers for remote device */
614622
buffer = rpmsg_virtio_shm_pool_get_buffer(shpool,
615-
RPMSG_BUFFER_SIZE);
623+
rvdev->shbuf_size);
616624

617625
if (!buffer) {
618626
return RPMSG_ERR_NO_BUFF;
@@ -623,7 +631,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
623631
metal_io_block_set(shm_io,
624632
metal_io_virt_to_offset(shm_io,
625633
buffer),
626-
0x00, RPMSG_BUFFER_SIZE);
634+
0x00, rvdev->shbuf_size);
627635
status =
628636
virtqueue_add_buffer(rvdev->rvq, &vqbuf, 0, 1,
629637
buffer);

0 commit comments

Comments
 (0)