Skip to content

Commit 1c5cd00

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 34bdd16 commit 1c5cd00

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
@@ -145,8 +145,8 @@ static void *rpmsg_virtio_get_tx_buffer(struct rpmsg_virtio_device *rvdev,
145145
data = virtqueue_get_buffer(rvdev->svq, len, idx);
146146
if (!data && rvdev->svq->vq_free_cnt) {
147147
data = rpmsg_virtio_shm_pool_get_buffer(rvdev->shpool,
148-
RPMSG_BUFFER_SIZE);
149-
*len = RPMSG_BUFFER_SIZE;
148+
rvdev->config.rxbuf_size);
149+
*len = rvdev->config.rxbuf_size;
150150
*idx = 0;
151151
}
152152
}
@@ -239,7 +239,7 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev)
239239
* If device role is Master then buffers are provided by us,
240240
* so just provide the macro.
241241
*/
242-
length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr);
242+
length = rvdev->config.rxbuf_size - sizeof(struct rpmsg_hdr);
243243
}
244244
#endif /*!VIRTIO_SLAVE_ONLY*/
245245

@@ -612,6 +612,8 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
612612
rvdev->vdev = vdev;
613613
rdev->ns_bind_cb = ns_bind_cb;
614614
vdev->priv = rvdev;
615+
rvdev->config.txbuf_size = RPMSG_BUFFER_SIZE;
616+
rvdev->config.rxbuf_size = RPMSG_BUFFER_SIZE;
615617
rdev->ops.send_offchannel_raw = rpmsg_virtio_send_offchannel_raw;
616618
rdev->ops.hold_rx_buffer = rpmsg_virtio_hold_rx_buffer;
617619
rdev->ops.release_rx_buffer = rpmsg_virtio_release_rx_buffer;
@@ -628,6 +630,13 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
628630
vdev->features = rpmsg_virtio_get_features(rvdev);
629631
rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS));
630632

633+
if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
634+
rpmsg_virtio_read_config(rvdev,
635+
0,
636+
&rvdev->config,
637+
sizeof(rvdev->config));
638+
}
639+
631640
#ifndef VIRTIO_SLAVE_ONLY
632641
if (role == RPMSG_MASTER) {
633642
/*
@@ -688,11 +697,11 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
688697
unsigned int idx;
689698
void *buffer;
690699

691-
vqbuf.len = RPMSG_BUFFER_SIZE;
700+
vqbuf.len = rvdev->config.txbuf_size;
692701
for (idx = 0; idx < rvdev->rvq->vq_nentries; idx++) {
693702
/* Initialize TX virtqueue buffers for remote device */
694703
buffer = rpmsg_virtio_shm_pool_get_buffer(shpool,
695-
RPMSG_BUFFER_SIZE);
704+
rvdev->config.txbuf_size);
696705

697706
if (!buffer) {
698707
return RPMSG_ERR_NO_BUFF;
@@ -703,7 +712,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
703712
metal_io_block_set(shm_io,
704713
metal_io_virt_to_offset(shm_io,
705714
buffer),
706-
0x00, RPMSG_BUFFER_SIZE);
715+
0x00, rvdev->config.txbuf_size);
707716
status =
708717
virtqueue_add_buffer(rvdev->rvq, &vqbuf, 0, 1,
709718
buffer);

0 commit comments

Comments
 (0)