Skip to content

Commit 9ecafcf

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 a12d03c commit 9ecafcf

3 files changed

Lines changed: 29 additions & 2 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+
* @h2r_buf_size: the size of the buffer used to send data from host to remote
309+
* @r2h_buf_size: the size of the buffer used to send data from remote to host
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 individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */
317+
uint32_t h2r_buf_size;
318+
uint32_t r2h_buf_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: 3 additions & 1 deletion
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
@@ -74,7 +76,7 @@ struct rpmsg_virtio_config {
7476
*/
7577
struct rpmsg_virtio_device {
7678
struct rpmsg_device rdev;
77-
struct rpmsg_virtio_config config;
79+
struct fw_rsc_config config;
7880
struct virtio_device *vdev;
7981
struct virtqueue *rvq;
8082
struct virtqueue *svq;

lib/rpmsg/rpmsg_virtio.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,8 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
651651
if (config == NULL) {
652652
return RPMSG_ERR_PARAM;
653653
}
654-
rvdev->config = *config;
654+
rvdev->config.h2r_buf_size = config->h2r_buf_size;
655+
rvdev->config.r2h_buf_size = config->r2h_buf_size;
655656
}
656657
#else /*!VIRTIO_SLAVE_ONLY*/
657658
/* Ignore passed config in the virtio-device-only configuration. */
@@ -668,6 +669,13 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
668669
vdev->features = rpmsg_virtio_get_features(rvdev);
669670
rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS));
670671

672+
if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
673+
rpmsg_virtio_read_config(rvdev,
674+
0,
675+
&rvdev->config,
676+
sizeof(rvdev->config));
677+
}
678+
671679
#ifndef VIRTIO_SLAVE_ONLY
672680
if (role == RPMSG_MASTER) {
673681
/*

0 commit comments

Comments
 (0)