Skip to content

Commit dd38a23

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: anchao <[email protected]>
1 parent 20292c5 commit dd38a23

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

lib/include/openamp/remoteproc.h

+17
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

+4
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

+16-6
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) {
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
}
151151
}
152152
#endif /*!VIRTIO_SLAVE_ONLY*/
@@ -238,7 +238,7 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev)
238238
* If device role is Master then buffers are provided by us,
239239
* so just provide the macro.
240240
*/
241-
length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr);
241+
length = rvdev->config.rxbuf_size - sizeof(struct rpmsg_hdr);
242242
}
243243
#endif /*!VIRTIO_SLAVE_ONLY*/
244244

@@ -529,7 +529,10 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
529529
rvdev->vdev = vdev;
530530
rdev->ns_bind_cb = ns_bind_cb;
531531
vdev->priv = rvdev;
532+
rvdev->config.txbuf_size = RPMSG_BUFFER_SIZE;
533+
rvdev->config.rxbuf_size = RPMSG_BUFFER_SIZE;
532534
rdev->ops.send_offchannel_raw = rpmsg_virtio_send_offchannel_raw;
535+
533536
role = rpmsg_virtio_get_role(rvdev);
534537

535538
#ifndef VIRTIO_MASTER_ONLY
@@ -541,6 +544,13 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
541544
vdev->features = rpmsg_virtio_get_features(rvdev);
542545
rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS));
543546

547+
if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
548+
rpmsg_virtio_read_config(rvdev,
549+
0,
550+
&rvdev->config,
551+
sizeof(rvdev->config));
552+
}
553+
544554
#ifndef VIRTIO_SLAVE_ONLY
545555
if (role == RPMSG_MASTER) {
546556
/*
@@ -601,11 +611,11 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
601611
unsigned int idx;
602612
void *buffer;
603613

604-
vqbuf.len = RPMSG_BUFFER_SIZE;
614+
vqbuf.len = rvdev->config.txbuf_size;
605615
for (idx = 0; idx < rvdev->rvq->vq_nentries; idx++) {
606616
/* Initialize TX virtqueue buffers for remote device */
607617
buffer = rpmsg_virtio_shm_pool_get_buffer(shpool,
608-
RPMSG_BUFFER_SIZE);
618+
rvdev->config.txbuf_size);
609619

610620
if (!buffer) {
611621
return RPMSG_ERR_NO_BUFF;
@@ -616,7 +626,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
616626
metal_io_block_set(shm_io,
617627
metal_io_virt_to_offset(shm_io,
618628
buffer),
619-
0x00, RPMSG_BUFFER_SIZE);
629+
0x00, rvdev->config.txbuf_size);
620630
status =
621631
virtqueue_add_buffer(rvdev->rvq, &vqbuf, 0, 1,
622632
buffer);

0 commit comments

Comments
 (0)