Skip to content

Commit 380eb70

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 8 bytes), otherwise the default size(512 bytes) will be used. Signed-off-by: Chao An <anchao@pinecone.net>
1 parent 411f624 commit 380eb70

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

lib/include/openamp/remoteproc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,23 @@ struct fw_rsc_vdev {
303303
struct fw_rsc_vdev_vring vring[0];
304304
} METAL_PACKED_END;
305305

306+
/**
307+
* struct fw_rsc_config - configuration space declaration
308+
* @txbuf_size: the tx buffer size
309+
* @rxbuf_size: the rx buffer size
310+
* @reserved: reserved (must be zero)
311+
*
312+
* This structure immediately follow fw_rsc_vdev to provide the config info.
313+
*/
314+
METAL_PACKED_BEGIN
315+
struct fw_rsc_config {
316+
/* The tx/rx individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */
317+
uint32_t txbuf_size;
318+
uint32_t rxbuf_size;
319+
uint32_t reserved[14]; /* Reserve for the future use */
320+
/* Put the customize config here */
321+
} METAL_PACKED_END;
322+
306323
/**
307324
* struct fw_rsc_vendor - remote processor vendor specific resource
308325
* @len: length of the resource

lib/include/openamp/rpmsg_virtio.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <metal/mutex.h>
1717
#include <openamp/rpmsg.h>
1818
#include <openamp/virtio.h>
19+
#include <openamp/remoteproc.h>
1920

2021
#if defined __cplusplus
2122
extern "C" {
@@ -28,6 +29,7 @@ extern "C" {
2829

2930
/* The feature bitmap for virtio rpmsg */
3031
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
32+
#define VIRTIO_RPMSG_F_BUFSZ 2 /* RP supports buffer size negotiation */
3133

3234
/**
3335
* struct rpmsg_virtio_shm_pool - shared memory pool used for rpmsg buffers
@@ -44,6 +46,7 @@ struct rpmsg_virtio_shm_pool {
4446
/**
4547
* struct rpmsg_virtio_device - representation of a rpmsg device based on virtio
4648
* @rdev: rpmsg device, first property in the struct
49+
* @config: rpmsg config information
4750
* @vdev: pointer to the virtio device
4851
* @rvq: pointer to receive virtqueue
4952
* @svq: pointer to send virtqueue
@@ -52,6 +55,7 @@ struct rpmsg_virtio_shm_pool {
5255
*/
5356
struct rpmsg_virtio_device {
5457
struct rpmsg_device rdev;
58+
struct fw_rsc_config config;
5559
struct virtio_device *vdev;
5660
struct virtqueue *rvq;
5761
struct virtqueue *svq;

lib/rpmsg/rpmsg_virtio.c

Lines changed: 15 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, len, idx);
152152
if (!data && rvdev->svq->vq_free_cnt) {
153153
data = rpmsg_virtio_shm_pool_get_buffer(rvdev->shpool,
154-
RPMSG_BUFFER_SIZE);
155-
*len = RPMSG_BUFFER_SIZE;
154+
rvdev->config.rxbuf_size);
155+
*len = rvdev->config.rxbuf_size;
156156
*idx = 0;
157157
}
158158
}
@@ -250,7 +250,7 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev)
250250
* If device role is Master then buffers are provided by us,
251251
* so just provide the macro.
252252
*/
253-
length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr);
253+
length = rvdev->config.rxbuf_size - sizeof(struct rpmsg_hdr);
254254
}
255255
#endif /*!VIRTIO_SLAVE_ONLY*/
256256

@@ -624,6 +624,8 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
624624
rvdev->vdev = vdev;
625625
rdev->ns_bind_cb = ns_bind_cb;
626626
vdev->priv = rvdev;
627+
rvdev->config.txbuf_size = RPMSG_BUFFER_SIZE;
628+
rvdev->config.rxbuf_size = RPMSG_BUFFER_SIZE;
627629
rdev->ops.send_offchannel_raw = rpmsg_virtio_send_offchannel_raw;
628630
rdev->ops.hold_rx_buffer = rpmsg_virtio_hold_rx_buffer;
629631
rdev->ops.release_rx_buffer = rpmsg_virtio_release_rx_buffer;
@@ -640,6 +642,13 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
640642
vdev->features = rpmsg_virtio_get_features(rvdev);
641643
rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS));
642644

645+
if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
646+
rpmsg_virtio_read_config(rvdev,
647+
0,
648+
&rvdev->config,
649+
sizeof(rvdev->config));
650+
}
651+
643652
#ifndef VIRTIO_SLAVE_ONLY
644653
if (role == RPMSG_MASTER) {
645654
/*
@@ -700,11 +709,11 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
700709
unsigned int idx;
701710
void *buffer;
702711

703-
vqbuf.len = RPMSG_BUFFER_SIZE;
712+
vqbuf.len = rvdev->config.txbuf_size;
704713
for (idx = 0; idx < rvdev->rvq->vq_nentries; idx++) {
705714
/* Initialize TX virtqueue buffers for remote device */
706715
buffer = rpmsg_virtio_shm_pool_get_buffer(shpool,
707-
RPMSG_BUFFER_SIZE);
716+
rvdev->config.txbuf_size);
708717

709718
if (!buffer) {
710719
return RPMSG_ERR_NO_BUFF;
@@ -715,7 +724,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
715724
metal_io_block_set(shm_io,
716725
metal_io_virt_to_offset(shm_io,
717726
buffer),
718-
0x00, RPMSG_BUFFER_SIZE);
727+
0x00, rvdev->config.txbuf_size);
719728
status =
720729
virtqueue_add_buffer(rvdev->rvq, &vqbuf, 0, 1,
721730
buffer);

0 commit comments

Comments
 (0)